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 more tests for enu...



details:   https://anonhg.NetBSD.org/src/rev/d32997a95bf3
branches:  trunk
changeset: 1019116:d32997a95bf3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 27 13:43:36 2021 +0000

description:
tests/lint: add more tests for enum mismatch

diffstat:

 tests/usr.bin/xlint/lint1/msg_130.c   |  31 ++++++++++++++++++++++++++-----
 tests/usr.bin/xlint/lint1/msg_130.exp |   4 +++-
 tests/usr.bin/xlint/lint1/msg_156.c   |  17 ++++++++++-------
 tests/usr.bin/xlint/lint1/msg_156.exp |   3 ++-
 4 files changed, 41 insertions(+), 14 deletions(-)

diffs (101 lines):

diff -r bb69788e4c16 -r d32997a95bf3 tests/usr.bin/xlint/lint1/msg_130.c
--- a/tests/usr.bin/xlint/lint1/msg_130.c       Sat Feb 27 13:02:42 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_130.c       Sat Feb 27 13:43:36 2021 +0000
@@ -1,18 +1,39 @@
-/*     $NetBSD: msg_130.c,v 1.3 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_130.c,v 1.4 2021/02/27 13:43:36 rillig Exp $       */
 # 3 "msg_130.c"
 
 // Test for message: enum type mismatch, op %s [130]
 
 enum color {
-       RED, GREEN, BLUE
+       RED     = 1 << 0,
+       GREEN   = 1 << 1,
+       BLUE    = 1 << 2
+};
+
+enum size {
+       SMALL,
+       MEDIUM,
+       LARGE
 };
 
 enum daytime {
        NIGHT, MORNING, NOON, EVENING
 };
 
-int
-example(_Bool cond)
+void sink(_Bool);
+
+void
+example(_Bool cond, enum color c, enum size s)
 {
-       return cond ? GREEN : MORNING;  /* expect: 130 */
+       sink(cond ? GREEN : MORNING);   /* expect: 130 */
+
+       sink(c != s);                   /* expect: 130 */
+       sink(c == s);                   /* expect: 130 */
+       sink((c & MEDIUM) != 0);        /* might be useful to warn about */
+       sink((c | MEDIUM) != 0);        /* might be useful to warn about */
+
+       c |= MEDIUM;                    /* might be useful to warn about */
+       c &= MEDIUM;                    /* might be useful to warn about */
+
+       /* The cast to unsigned is required by GCC at WARNS=6. */
+       c &= ~(unsigned)MEDIUM;         /* might be useful to warn about */
 }
diff -r bb69788e4c16 -r d32997a95bf3 tests/usr.bin/xlint/lint1/msg_130.exp
--- a/tests/usr.bin/xlint/lint1/msg_130.exp     Sat Feb 27 13:02:42 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_130.exp     Sat Feb 27 13:43:36 2021 +0000
@@ -1,1 +1,3 @@
-msg_130.c(17): warning: enum type mismatch, op : [130]
+msg_130.c(27): warning: enum type mismatch, op : [130]
+msg_130.c(29): warning: enum type mismatch, op != [130]
+msg_130.c(30): warning: enum type mismatch, op == [130]
diff -r bb69788e4c16 -r d32997a95bf3 tests/usr.bin/xlint/lint1/msg_156.c
--- a/tests/usr.bin/xlint/lint1/msg_156.c       Sat Feb 27 13:02:42 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_156.c       Sat Feb 27 13:43:36 2021 +0000
@@ -1,12 +1,12 @@
-/*     $NetBSD: msg_156.c,v 1.3 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_156.c,v 1.4 2021/02/27 13:43:36 rillig Exp $       */
 # 3 "msg_156.c"
 
 // Test for message: enum type mismatch, arg #%d [156]
 
 enum color {
-       RED,
-       GREEN,
-       BLUE
+       RED     = 1 << 0,
+       GREEN   = 1 << 1,
+       BLUE    = 1 << 2
 };
 
 enum size {
@@ -15,11 +15,14 @@
        LARGE
 };
 
-void
-print_color(enum color);
+void print_color(enum color);
 
 void
-example(void)
+example(enum color c, enum size s)
 {
+       print_color(GREEN);
+       print_color(c);
+
        print_color(MEDIUM);            /* expect: 156 */
+       print_color(s);                 /* expect: 156 */
 }
diff -r bb69788e4c16 -r d32997a95bf3 tests/usr.bin/xlint/lint1/msg_156.exp
--- a/tests/usr.bin/xlint/lint1/msg_156.exp     Sat Feb 27 13:02:42 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_156.exp     Sat Feb 27 13:43:36 2021 +0000
@@ -1,1 +1,2 @@
-msg_156.c(24): warning: enum type mismatch, arg #1 (enum color != enum size) [156]
+msg_156.c(26): warning: enum type mismatch, arg #1 (enum color != enum size) [156]
+msg_156.c(27): warning: enum type mismatch, arg #1 (enum color != enum size) [156]



Home | Main Index | Thread Index | Old Index