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