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 the lexi...



details:   https://anonhg.NetBSD.org/src/rev/3ae4cc8f2652
branches:  trunk
changeset: 379956:3ae4cc8f2652
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Jun 29 07:17:43 2021 +0000

description:
tests/lint: add tests for the lexical analysis

diffstat:

 tests/usr.bin/xlint/lint1/lex_char.c   |  26 ++++++++++++++++++++++----
 tests/usr.bin/xlint/lint1/lex_char.exp |   2 +-
 tests/usr.bin/xlint/lint1/msg_076.c    |   5 ++---
 tests/usr.bin/xlint/lint1/msg_076.exp  |   2 +-
 tests/usr.bin/xlint/lint1/msg_077.c    |  26 ++++++++++++++++++++++----
 tests/usr.bin/xlint/lint1/msg_077.exp  |   2 +-
 tests/usr.bin/xlint/lint1/msg_080.c    |   8 +++++---
 tests/usr.bin/xlint/lint1/msg_080.exp  |   4 +++-
 tests/usr.bin/xlint/lint1/msg_082.c    |   4 ++--
 tests/usr.bin/xlint/lint1/msg_250.c    |   6 +++---
 tests/usr.bin/xlint/lint1/msg_250.exp  |   3 ++-
 tests/usr.bin/xlint/lint1/msg_251.c    |   9 ++++++---
 tests/usr.bin/xlint/lint1/msg_251.exp  |   3 ++-
 tests/usr.bin/xlint/lint1/msg_253.c    |   7 ++++---
 tests/usr.bin/xlint/lint1/msg_253.exp  |   3 ++-
 tests/usr.bin/xlint/lint1/msg_254.c    |  20 ++++++++++++++++----
 tests/usr.bin/xlint/lint1/msg_254.exp  |   6 +++++-
 tests/usr.bin/xlint/lint1/msg_262.c    |   9 +++++----
 tests/usr.bin/xlint/lint1/msg_262.exp  |   2 +-
 tests/usr.bin/xlint/lint1/msg_263.c    |   9 +++++----
 tests/usr.bin/xlint/lint1/msg_263.exp  |   2 +-
 21 files changed, 111 insertions(+), 47 deletions(-)

diffs (293 lines):

diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/lex_char.c
--- a/tests/usr.bin/xlint/lint1/lex_char.c      Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_char.c      Tue Jun 29 07:17:43 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lex_char.c,v 1.2 2021/06/20 18:23:07 rillig Exp $      */
+/*     $NetBSD: lex_char.c,v 1.3 2021/06/29 07:17:43 rillig Exp $      */
 # 3 "lex_char.c"
 
 /*
@@ -34,9 +34,27 @@ test(void)
        /* octal */
        sink('\177');
 
-       /* newline */
+       /* expect+1: empty character constant */
+       sink('');
+
+       /* U+0007 alarm/bell */
+       sink('\a');
+
+       /* U+0008 backspace */
+       sink('\b');
+
+       /* U+0009 horizontal tabulation */
+       sink('\t');
+
+       /* U+000A line feed */
        sink('\n');
 
-       /* expect+1: empty character constant */
-       sink('');
+       /* U+000B vertical tabulation */
+       sink('\v');
+
+       /* U+000C form feed */
+       sink('\f');
+
+       /* U+000D carriage return */
+       sink('\r');
 }
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/lex_char.exp
--- a/tests/usr.bin/xlint/lint1/lex_char.exp    Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_char.exp    Tue Jun 29 07:17:43 2021 +0000
@@ -2,4 +2,4 @@ lex_char.c(16): error: empty character c
 lex_char.c(25): warning: multi-character character constant [294]
 lex_char.c(25): warning: conversion of 'int' to 'char' is out of range, arg #1 [295]
 lex_char.c(29): warning: dubious escape \e [79]
-lex_char.c(41): error: empty character constant [73]
+lex_char.c(38): error: empty character constant [73]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_076.c
--- a/tests/usr.bin/xlint/lint1/msg_076.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_076.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,6 @@
-/*     $NetBSD: msg_076.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_076.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_076.c"
 
 // Test for message: character escape does not fit in character [76]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+char ch = '\777';              /* expect: [76] */
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_076.exp
--- a/tests/usr.bin/xlint/lint1/msg_076.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_076.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,1 @@
-msg_076.c(6): error: syntax error ':' [249]
+msg_076.c(6): warning: character escape does not fit in character [76]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_077.c
--- a/tests/usr.bin/xlint/lint1/msg_077.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_077.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,25 @@
-/*     $NetBSD: msg_077.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_077.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_077.c"
 
-// Test for message: bad octal digit %c [77]
+/* Test for message: bad octal digit %c [77] */
+
+/* lint1-flags: -tw */
+
+char single_digit = '\8';      /* expect: bad octal digit 8 [77] */
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/*
+ * Before lex.c 1.47 from 2021-06-29, lint intended to detect a "bad octal
+ * digit" following good octal digits, but the corresponding code had an
+ * unsatisfiable guard clause.
+ *
+ * The C Reference Manual 1978, 2.4.3 "Character constants" does not mention
+ * non-octal digits, therefore this code must have been due to a particular
+ * C compiler's interpretation.  It's even wrong according to the Reference
+ * Manual to interpret '\088' as anything else than a malformed character
+ * literal.
+ *
+ * That code has been removed since nobody runs lint in traditional C mode
+ * anyway.
+ * https://mail-index.netbsd.org/tech-toolchain/2021/03/16/msg003933.html
+ */
+char several_digits = '\08';
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_077.exp
--- a/tests/usr.bin/xlint/lint1/msg_077.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_077.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,1 @@
-msg_077.c(6): error: syntax error ':' [249]
+msg_077.c(8): warning: bad octal digit 8 [77]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_080.c
--- a/tests/usr.bin/xlint/lint1/msg_080.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_080.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,9 @@
-/*     $NetBSD: msg_080.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_080.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_080.c"
 
 // Test for message: dubious escape \%o [80]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* expect+3: dubious escape \342 [80] */ /* FIXME: Why 342? */
+/* expect+2: multi-character character constant [294] */
+/* expect+1: initializer does not fit */
+char backslash_delete = '\⌂';
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_080.exp
--- a/tests/usr.bin/xlint/lint1/msg_080.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_080.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,3 @@
-msg_080.c(6): error: syntax error ':' [249]
+msg_080.c(9): warning: dubious escape \342 [80]
+msg_080.c(9): warning: multi-character character constant [294]
+msg_080.c(9): warning: initializer does not fit [178]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_082.c
--- a/tests/usr.bin/xlint/lint1/msg_082.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_082.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: msg_082.c,v 1.3 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_082.c,v 1.4 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_082.c"
 
 /* Test for message: \x undefined in traditional C [82] */
 
 /* lint1-flags: -Stw */
 
-char str[] = "A he\x78 escape";                /* expect: 82 */
+char str[] = "A he\x78 escape";                /* expect: [82] */
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_250.c
--- a/tests/usr.bin/xlint/lint1/msg_250.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_250.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_250.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_250.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_250.c"
 
 // Test for message: unknown character \%o [250]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+@deprecated                    /* expect: unknown character \100 [250] */
+char *gets(void);              /* expect: syntax error 'char' [249] */
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_250.exp
--- a/tests/usr.bin/xlint/lint1/msg_250.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_250.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,2 @@
-msg_250.c(6): error: syntax error ':' [249]
+msg_250.c(6): error: unknown character \100 [250]
+msg_250.c(7): error: syntax error 'char' [249]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_251.c
--- a/tests/usr.bin/xlint/lint1/msg_251.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_251.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,10 @@
-/*     $NetBSD: msg_251.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_251.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_251.c"
 
 // Test for message: malformed integer constant [251]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* expect+1: malformed integer constant */
+int lll = 123LLL;
+
+/* expect+1: malformed integer constant */
+unsigned int uu = 123UU;
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_251.exp
--- a/tests/usr.bin/xlint/lint1/msg_251.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_251.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,2 @@
-msg_251.c(6): error: syntax error ':' [249]
+msg_251.c(7): warning: malformed integer constant [251]
+msg_251.c(10): warning: malformed integer constant [251]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_253.c
--- a/tests/usr.bin/xlint/lint1/msg_253.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_253.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,8 @@
-/*     $NetBSD: msg_253.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_253.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_253.c"
 
 // Test for message: unterminated character constant [253]
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* expect+3: [253] */
+/* expect+2: syntax error '' */
+'
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_253.exp
--- a/tests/usr.bin/xlint/lint1/msg_253.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_253.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,2 @@
-msg_253.c(6): error: syntax error ':' [249]
+msg_253.c(9): error: unterminated character constant [253]
+msg_253.c(9): error: syntax error '' [249]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_254.c
--- a/tests/usr.bin/xlint/lint1/msg_254.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_254.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,19 @@
-/*     $NetBSD: msg_254.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_254.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_254.c"
 
-// Test for message: newline in string or char constant [254]
+/* Test for message: newline in string or char constant [254] */
+
+/* lint1-flags: -tw */
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/*
+ * The sequence backslash-newline is a GCC extension.
+ * C99 does not allow it.
+ */
+
+/* expect+6: newline in string or char constant [254] */
+/* expect+5: unterminated string constant [258] */
+/* expect+4: syntax error '"' [249] */
+/* expect+4: newline in string or char constant [254] */
+/* expect+3: unterminated string constant [258] */
+"line1
+line2"
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_254.exp
--- a/tests/usr.bin/xlint/lint1/msg_254.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_254.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,5 @@
-msg_254.c(6): error: syntax error ':' [249]
+msg_254.c(19): error: newline in string or char constant [254]
+msg_254.c(19): error: unterminated string constant [258]
+msg_254.c(19): error: syntax error '"' [249]
+msg_254.c(20): error: newline in string or char constant [254]
+msg_254.c(20): error: unterminated string constant [258]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_262.c
--- a/tests/usr.bin/xlint/lint1/msg_262.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_262.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,8 @@
-/*     $NetBSD: msg_262.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_262.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_262.c"
 
-// Test for message: \" inside character constants undefined in traditional C [262]
+/* Test for message: \" inside character constants undefined in traditional C [262] */
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-flags: -tw */
+
+char msg = '\"';               /* expect: [262] */
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_262.exp
--- a/tests/usr.bin/xlint/lint1/msg_262.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_262.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,1 @@
-msg_262.c(6): error: syntax error ':' [249]
+msg_262.c(8): warning: \" inside character constants undefined in traditional C [262]
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_263.c
--- a/tests/usr.bin/xlint/lint1/msg_263.c       Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_263.c       Tue Jun 29 07:17:43 2021 +0000
@@ -1,7 +1,8 @@
-/*     $NetBSD: msg_263.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_263.c,v 1.3 2021/06/29 07:17:43 rillig Exp $       */
 # 3 "msg_263.c"
 
-// Test for message: \? undefined in traditional C [263]
+/* Test for message: \? undefined in traditional C [263] */
 
-TODO: "Add example code that triggers the above message." /* expect: 249 */
-TODO: "Add example code that almost triggers the above message."
+/* lint1-flags: -tw */
+
+char ch = '\?';                        /* expect: [263] */
diff -r e395798af056 -r 3ae4cc8f2652 tests/usr.bin/xlint/lint1/msg_263.exp
--- a/tests/usr.bin/xlint/lint1/msg_263.exp     Tue Jun 29 06:28:07 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_263.exp     Tue Jun 29 07:17:43 2021 +0000
@@ -1,1 +1,1 @@
-msg_263.c(6): error: syntax error ':' [249]
+msg_263.c(8): warning: \? undefined in traditional C [263]


Home | Main Index | Thread Index | Old Index