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 integer ...



details:   https://anonhg.NetBSD.org/src/rev/f2503e080a60
branches:  trunk
changeset: 1023094:f2503e080a60
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Aug 23 17:47:34 2021 +0000

description:
tests/lint: add tests for integer comparisons

diffstat:

 tests/usr.bin/xlint/lint1/lex_string.c        |   7 +++-
 tests/usr.bin/xlint/lint1/lex_string.exp      |   1 +
 tests/usr.bin/xlint/lint1/lex_wide_string.c   |   7 +++-
 tests/usr.bin/xlint/lint1/lex_wide_string.exp |   1 +
 tests/usr.bin/xlint/lint1/msg_162.c           |  52 +++++++++++++++++++++++++-
 tests/usr.bin/xlint/lint1/msg_162.exp         |   9 ++++-
 tests/usr.bin/xlint/lint1/msg_230.c           |   9 ++++-
 tests/usr.bin/xlint/lint1/msg_230.exp         |   2 +
 8 files changed, 81 insertions(+), 7 deletions(-)

diffs (155 lines):

diff -r 24febc9d9ca0 -r f2503e080a60 tests/usr.bin/xlint/lint1/lex_string.c
--- a/tests/usr.bin/xlint/lint1/lex_string.c    Mon Aug 23 17:03:23 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_string.c    Mon Aug 23 17:47:34 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lex_string.c,v 1.2 2021/06/19 08:37:18 rillig Exp $    */
+/*     $NetBSD: lex_string.c,v 1.3 2021/08/23 17:47:34 rillig Exp $    */
 # 3 "lex_string.c"
 
 /*
@@ -25,4 +25,9 @@
 
        /* expect+1: dubious escape \y [79] */
        sink("\y");             /* unknown escape sequence */
+
+       sink("first" "second");
+
+       /* expect+1: error: cannot concatenate wide and regular string literals [292] */
+       sink("plain" L"wide");
 }
diff -r 24febc9d9ca0 -r f2503e080a60 tests/usr.bin/xlint/lint1/lex_string.exp
--- a/tests/usr.bin/xlint/lint1/lex_string.exp  Mon Aug 23 17:03:23 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_string.exp  Mon Aug 23 17:47:34 2021 +0000
@@ -1,2 +1,3 @@
 lex_string.c(24): error: no hex digits follow \x [74]
 lex_string.c(27): warning: dubious escape \y [79]
+lex_string.c(32): error: cannot concatenate wide and regular string literals [292]
diff -r 24febc9d9ca0 -r f2503e080a60 tests/usr.bin/xlint/lint1/lex_wide_string.c
--- a/tests/usr.bin/xlint/lint1/lex_wide_string.c       Mon Aug 23 17:03:23 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_wide_string.c       Mon Aug 23 17:47:34 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lex_wide_string.c,v 1.1 2021/06/19 08:30:08 rillig Exp $       */
+/*     $NetBSD: lex_wide_string.c,v 1.2 2021/08/23 17:47:34 rillig Exp $       */
 # 3 "lex_wide_string.c"
 
 /*
@@ -25,4 +25,9 @@
 
        /* expect+1: dubious escape \y [79] */
        sink(L"\y");
+
+       sink(L"first" L"second");
+
+       /* expect+1: error: cannot concatenate wide and regular string literals [292] */
+       sink(L"wide" "plain");
 }
diff -r 24febc9d9ca0 -r f2503e080a60 tests/usr.bin/xlint/lint1/lex_wide_string.exp
--- a/tests/usr.bin/xlint/lint1/lex_wide_string.exp     Mon Aug 23 17:03:23 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_wide_string.exp     Mon Aug 23 17:47:34 2021 +0000
@@ -1,2 +1,3 @@
 lex_wide_string.c(24): error: no hex digits follow \x [74]
 lex_wide_string.c(27): warning: dubious escape \y [79]
+lex_wide_string.c(32): error: cannot concatenate wide and regular string literals [292]
diff -r 24febc9d9ca0 -r f2503e080a60 tests/usr.bin/xlint/lint1/msg_162.c
--- a/tests/usr.bin/xlint/lint1/msg_162.c       Mon Aug 23 17:03:23 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_162.c       Mon Aug 23 17:47:34 2021 +0000
@@ -1,7 +1,53 @@
-/*     $NetBSD: msg_162.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_162.c,v 1.3 2021/08/23 17:47:34 rillig Exp $       */
 # 3 "msg_162.c"
 
 // Test for message: comparison of %s with %s, op %s [162]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-extra-flags: -hp */
+
+void
+left_unsigned(unsigned int ui)
+{
+       if (ui < -5.0) {
+       }
+
+       /* expect+1: warning: comparison of unsigned int with negative constant, op < [162] */
+       if (ui < -5) {
+       }
+
+       /* expect+1: warning: comparison of unsigned int with 0, op < [162] */
+       if (ui < 0) {
+       }
+
+       /* expect+1: warning: comparison of unsigned int with 0, op >= [162] */
+       if (ui >= 0) {
+       }
+
+       /* expect+1: warning: comparison of unsigned int with 0, op <= [162] */
+       if (ui <= 0) {
+       }
+}
+
+void
+right_unsigned(unsigned int ui)
+{
+
+       if (-5.0 > ui) {
+       }
+
+       /* expect+1: warning: comparison of negative constant with unsigned int, op > [162] */
+       if (-5 > ui) {
+       }
+
+       /* expect+1: warning: comparison of 0 with unsigned int, op > [162] */
+       if (0 > ui) {
+       }
+
+       /* expect+1: warning: comparison of 0 with unsigned int, op <= [162] */
+       if (0 <= ui) {
+       }
+
+       /* expect+1: warning: comparison of 0 with unsigned int, op >= [162] */
+       if (0 >= ui) {
+       }
+}
diff -r 24febc9d9ca0 -r f2503e080a60 tests/usr.bin/xlint/lint1/msg_162.exp
--- a/tests/usr.bin/xlint/lint1/msg_162.exp     Mon Aug 23 17:03:23 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_162.exp     Mon Aug 23 17:47:34 2021 +0000
@@ -1,1 +1,8 @@
-msg_162.c(6): error: syntax error ':' [249]
+msg_162.c(15): warning: comparison of unsigned int with negative constant, op < [162]
+msg_162.c(19): warning: comparison of unsigned int with 0, op < [162]
+msg_162.c(23): warning: comparison of unsigned int with 0, op >= [162]
+msg_162.c(27): warning: comparison of unsigned int with 0, op <= [162]
+msg_162.c(39): warning: comparison of negative constant with unsigned int, op > [162]
+msg_162.c(43): warning: comparison of 0 with unsigned int, op > [162]
+msg_162.c(47): warning: comparison of 0 with unsigned int, op <= [162]
+msg_162.c(51): warning: comparison of 0 with unsigned int, op >= [162]
diff -r 24febc9d9ca0 -r f2503e080a60 tests/usr.bin/xlint/lint1/msg_230.c
--- a/tests/usr.bin/xlint/lint1/msg_230.c       Mon Aug 23 17:03:23 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230.c       Mon Aug 23 17:47:34 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: msg_230.c,v 1.5 2021/08/21 11:50:57 rillig Exp $       */
+/*     $NetBSD: msg_230.c,v 1.6 2021/08/23 17:47:34 rillig Exp $       */
 # 3 "msg_230.c"
 
 // Test for message: nonportable character comparison, op %s [230]
@@ -31,4 +31,11 @@
                return;
        if (sc <= -1)
                return;
+
+       /* expect+1: warning: nonportable character comparison, op <= [230] */
+       if (-1 <= c)
+               return;
+       /* expect+1: warning: nonportable character comparison, op <= [230] */
+       if (256 <= c)
+               return;
 }
diff -r 24febc9d9ca0 -r f2503e080a60 tests/usr.bin/xlint/lint1/msg_230.exp
--- a/tests/usr.bin/xlint/lint1/msg_230.exp     Mon Aug 23 17:03:23 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230.exp     Mon Aug 23 17:47:34 2021 +0000
@@ -1,3 +1,5 @@
 msg_230.c(14): warning: comparison of unsigned char with 0, op < [162]
 msg_230.c(27): warning: nonportable character comparison, op <= [230]
 msg_230.c(30): warning: comparison of unsigned char with negative constant, op <= [162]
+msg_230.c(36): warning: nonportable character comparison, op <= [230]
+msg_230.c(39): warning: nonportable character comparison, op <= [230]



Home | Main Index | Thread Index | Old Index