Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: add tests for several ...



details:   https://anonhg.NetBSD.org/src/rev/7e277b01e6cd
branches:  trunk
changeset: 985458:7e277b01e6cd
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Aug 26 19:23:25 2021 +0000

description:
tests/lint: add tests for several messages

diffstat:

 tests/usr.bin/xlint/lint1/accept.sh   |   7 +++--
 tests/usr.bin/xlint/lint1/msg_011.c   |  38 ++++++++++++++++++++++++++++++++--
 tests/usr.bin/xlint/lint1/msg_011.exp |  11 +++++++++-
 tests/usr.bin/xlint/lint1/msg_012.c   |  11 +++++++--
 tests/usr.bin/xlint/lint1/msg_012.exp |   2 +-
 tests/usr.bin/xlint/lint1/msg_013.c   |  13 +++++++++--
 tests/usr.bin/xlint/lint1/msg_013.exp |   2 +-
 tests/usr.bin/xlint/lint1/msg_014.c   |   7 +++++-
 tests/usr.bin/xlint/lint1/msg_014.exp |   3 +-
 tests/usr.bin/xlint/lint1/msg_015.c   |   8 ++++--
 tests/usr.bin/xlint/lint1/msg_015.exp |   2 +-
 tests/usr.bin/xlint/lint1/msg_016.c   |  15 +++++++++++--
 tests/usr.bin/xlint/lint1/msg_016.exp |   3 +-
 tests/usr.bin/xlint/lint1/msg_017.c   |  17 ++++++++++++--
 tests/usr.bin/xlint/lint1/msg_017.exp |   4 ++-
 tests/usr.bin/xlint/lint1/msg_018.c   |   8 ++++++-
 tests/usr.bin/xlint/lint1/msg_018.exp |   4 ++-
 tests/usr.bin/xlint/lint1/msg_044.c   |  14 ++++++++++--
 tests/usr.bin/xlint/lint1/msg_044.exp |   4 ++-
 tests/usr.bin/xlint/lint1/msg_066.c   |   3 +-
 tests/usr.bin/xlint/lint1/msg_066.exp |   4 +-
 tests/usr.bin/xlint/lint1/msg_149.c   |  11 +++++++--
 tests/usr.bin/xlint/lint1/msg_149.exp |   2 +-
 tests/usr.bin/xlint/lint1/msg_176.c   |   3 +-
 tests/usr.bin/xlint/lint1/msg_189.c   |   3 +-
 tests/usr.bin/xlint/lint1/msg_189.exp |   2 +-
 tests/usr.bin/xlint/lint1/msg_201.c   |  11 +++++++--
 tests/usr.bin/xlint/lint1/msg_201.exp |   2 +-
 28 files changed, 165 insertions(+), 49 deletions(-)

diffs (truncated from 410 to 300 lines):

diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/accept.sh
--- a/tests/usr.bin/xlint/lint1/accept.sh       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/accept.sh       Thu Aug 26 19:23:25 2021 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: accept.sh,v 1.7 2021/08/16 06:24:37 rillig Exp $
+# $NetBSD: accept.sh,v 1.8 2021/08/26 19:23:25 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -75,7 +75,9 @@
                fi
 
                case "$base" in (msg_*)
-                       if [ ! -f "$expfile" ]; then
+                       if grep 'This message is not used\.' "$cfile" >/dev/null; then
+                               : 'Skip further checks.'
+                       elif [ ! -f "$expfile" ]; then
                                echo "$base should produce warnings"
                        elif grep '^TODO: "Add example code' "$base.c" >/dev/null; then
                                : 'ok, this test is not yet written'
@@ -90,7 +92,6 @@
                                fi
                        fi
                esac
-
        done
 done
 
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_011.c
--- a/tests/usr.bin/xlint/lint1/msg_011.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_011.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,39 @@
-/*     $NetBSD: msg_011.c,v 1.4 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_011.c,v 1.5 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_011.c"
 
 // Test for message: bit-field initializer out of range [11]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+void
+example(void)
+{
+       struct {
+               signed int si: 3;
+               unsigned int ui: 3;
+       } s[] = {
+               /* expect+2: warning: bit-field initializer out of range [11] */
+               /* expect+1: warning: initialization of unsigned with negative constant [221] */
+               { -8, -8 },
+
+               /* expect+2: warning: bit-field initializer out of range [11] */
+               /* expect+1: warning: initialization of unsigned with negative constant [221] */
+               { -7, -7 },
+
+               /* expect+1: warning: initialization of unsigned with negative constant [221] */
+               { -4, -4 },
+
+               /* expect+1: warning: initialization of unsigned with negative constant [221] */
+               { -3, -3 },
+
+               { 3, 3 },
+
+               /* expect+1: warning: bit-field initializer out of range [11] */
+               { 4, 4 },
+
+               /* expect+1: warning: bit-field initializer out of range [11] */
+               { 7, 7 },
+
+               /* expect+2: warning: bit-field initializer does not fit [180] */
+               /* expect+1: warning: bit-field initializer does not fit [180] */
+               { 8, 8 },
+       };
+}
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_011.exp
--- a/tests/usr.bin/xlint/lint1/msg_011.exp     Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_011.exp     Thu Aug 26 19:23:25 2021 +0000
@@ -1,1 +1,10 @@
-msg_011.c(6): error: syntax error ':' [249]
+msg_011.c(15): warning: bit-field initializer out of range [11]
+msg_011.c(15): warning: initialization of unsigned with negative constant [221]
+msg_011.c(19): warning: bit-field initializer out of range [11]
+msg_011.c(19): warning: initialization of unsigned with negative constant [221]
+msg_011.c(22): warning: initialization of unsigned with negative constant [221]
+msg_011.c(25): warning: initialization of unsigned with negative constant [221]
+msg_011.c(30): warning: bit-field initializer out of range [11]
+msg_011.c(33): warning: bit-field initializer out of range [11]
+msg_011.c(37): warning: bit-field initializer does not fit [180]
+msg_011.c(37): warning: bit-field initializer does not fit [180]
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_012.c
--- a/tests/usr.bin/xlint/lint1/msg_012.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_012.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,12 @@
-/*     $NetBSD: msg_012.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_012.c,v 1.3 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_012.c"
 
 // Test for message: compiler takes size of function [12]
+/* This message is not used. */
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+unsigned long
+example(void)
+{
+       /* expect+1: error: cannot take size/alignment of function [144] */
+       return sizeof(example);
+}
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_012.exp
--- a/tests/usr.bin/xlint/lint1/msg_012.exp     Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_012.exp     Thu Aug 26 19:23:25 2021 +0000
@@ -1,1 +1,1 @@
-msg_012.c(6): error: syntax error ':' [249]
+msg_012.c(11): error: cannot take size/alignment of function [144]
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_013.c
--- a/tests/usr.bin/xlint/lint1/msg_013.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_013.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,14 @@
-/*     $NetBSD: msg_013.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_013.c,v 1.3 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_013.c"
 
 // Test for message: incomplete enum type: %s [13]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+enum tag;
+
+/* XXX: why '<unnamed>'? */
+/* expect+1: warning: incomplete enum type: <unnamed> [13] */
+void function(enum tag);
+
+enum tag {
+       CONSTANT
+};
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_013.exp
--- a/tests/usr.bin/xlint/lint1/msg_013.exp     Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_013.exp     Thu Aug 26 19:23:25 2021 +0000
@@ -1,1 +1,1 @@
-msg_013.c(6): error: syntax error ':' [249]
+msg_013.c(10): warning: incomplete enum type: <unnamed> [13]
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_014.c
--- a/tests/usr.bin/xlint/lint1/msg_014.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_014.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,12 @@
-/*     $NetBSD: msg_014.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_014.c,v 1.3 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_014.c"
 
 // Test for message: compiler takes alignment of function [14]
 
+typedef void function(void);
+
+/* expect+1: error: cannot take size/alignment of function [144] */
+unsigned long alignof_function = __alignof__(function);
+
 TODO: "Add example code that triggers the above message." /* expect: 249 */
 TODO: "Add example code that almost triggers the above message."
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_014.exp
--- a/tests/usr.bin/xlint/lint1/msg_014.exp     Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_014.exp     Thu Aug 26 19:23:25 2021 +0000
@@ -1,1 +1,2 @@
-msg_014.c(6): error: syntax error ':' [249]
+msg_014.c(9): error: cannot take size/alignment of function [144]
+msg_014.c(11): error: syntax error ':' [249]
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_015.c
--- a/tests/usr.bin/xlint/lint1/msg_015.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_015.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,9 @@
-/*     $NetBSD: msg_015.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_015.c,v 1.3 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_015.c"
 
 // Test for message: function returns illegal type [15]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+typedef int array[5];
+
+/* expect+1: error: function returns illegal type [15] */
+array invalid(void);
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_015.exp
--- a/tests/usr.bin/xlint/lint1/msg_015.exp     Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_015.exp     Thu Aug 26 19:23:25 2021 +0000
@@ -1,1 +1,1 @@
-msg_015.c(6): error: syntax error ':' [249]
+msg_015.c(9): error: function returns illegal type [15]
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_016.c
--- a/tests/usr.bin/xlint/lint1/msg_016.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_016.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,16 @@
-/*     $NetBSD: msg_016.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_016.c,v 1.3 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_016.c"
 
 // Test for message: array of function is illegal [16]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+typedef void function(void);
+
+/* expect+1: error: array of function is illegal [16] */
+function functions[] = {
+       /*
+        * XXX: The below warning should not assume that function is an
+        * integer type.
+        */
+       /* expect+1: warning: illegal combination of integer (int) and pointer (pointer to void) [183] */
+       (void *)0,
+};
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_016.exp
--- a/tests/usr.bin/xlint/lint1/msg_016.exp     Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_016.exp     Thu Aug 26 19:23:25 2021 +0000
@@ -1,1 +1,2 @@
-msg_016.c(6): error: syntax error ':' [249]
+msg_016.c(9): error: array of function is illegal [16]
+msg_016.c(15): warning: illegal combination of integer (int) and pointer (pointer to void) [183]
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_017.c
--- a/tests/usr.bin/xlint/lint1/msg_017.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_017.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,18 @@
-/*     $NetBSD: msg_017.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_017.c,v 1.3 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_017.c"
 
 // Test for message: null dimension [17]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* expect+1: warning: empty array declaration: empty_array_var [190] */
+int empty_array_var[0];
+
+typedef int empty_array_type[0];
+/* expect+1: warning: empty array declaration: typedef_var [190] */
+empty_array_type typedef_var;
+
+struct s {
+       int empty_array_member[0];
+       /* expect+1: error: null dimension [17] */
+       int empty_multi_array_member[0][0];
+       int other_member;
+};
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_017.exp
--- a/tests/usr.bin/xlint/lint1/msg_017.exp     Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_017.exp     Thu Aug 26 19:23:25 2021 +0000
@@ -1,1 +1,3 @@
-msg_017.c(6): error: syntax error ':' [249]
+msg_017.c(16): error: null dimension [17]
+msg_017.c(7): warning: empty array declaration: empty_array_var [190]
+msg_017.c(11): warning: empty array declaration: typedef_var [190]
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_018.c
--- a/tests/usr.bin/xlint/lint1/msg_018.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_018.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,13 @@
-/*     $NetBSD: msg_018.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_018.c,v 1.3 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_018.c"
 
 // Test for message: illegal use of 'void' [18]
 
+/* expect+1: error: void type for 'x' [19] */
+void x;
+
+/* expect+1: error: cannot take size/alignment of void [146] */
+unsigned long sizeof_void = sizeof(void);
+
 TODO: "Add example code that triggers the above message." /* expect: 249 */
 TODO: "Add example code that almost triggers the above message."
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_018.exp
--- a/tests/usr.bin/xlint/lint1/msg_018.exp     Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_018.exp     Thu Aug 26 19:23:25 2021 +0000
@@ -1,1 +1,3 @@
-msg_018.c(6): error: syntax error ':' [249]
+msg_018.c(7): error: void type for 'x' [19]
+msg_018.c(10): error: cannot take size/alignment of void [146]
+msg_018.c(12): error: syntax error ':' [249]
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_044.c
--- a/tests/usr.bin/xlint/lint1/msg_044.c       Thu Aug 26 17:08:34 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_044.c       Thu Aug 26 19:23:25 2021 +0000
@@ -1,7 +1,15 @@
-/*     $NetBSD: msg_044.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_044.c,v 1.3 2021/08/26 19:23:25 rillig Exp $       */
 # 3 "msg_044.c"
 
 // Test for message: declaration introduces new type in ANSI C: %s %s [44]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* expect+1: warning: struct tag never defined [233] */
+struct tag;
+
+void declaration(struct tag *);
+
+void definition(void) {
+       /* expect+2: warning: declaration introduces new type in ANSI C: struct tag [44] */
+       /* expect+1: warning: struct tag never defined [233] */
+       struct tag;
+}
diff -r ce3a70dd097d -r 7e277b01e6cd tests/usr.bin/xlint/lint1/msg_044.exp



Home | Main Index | Thread Index | Old Index