Module Name: src Committed By: rillig Date: Sat Jun 19 08:30:08 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/xlint/lint1: Makefile t_integration.sh Added Files: src/tests/usr.bin/xlint/lint1: lex_char.c lex_char.exp lex_floating.c lex_floating.exp lex_integer.c lex_integer.exp lex_string.c lex_string.exp lex_wide_char.c lex_wide_char.exp lex_wide_string.c lex_wide_string.exp Log Message: tests/lint: add test cases for lexical analysis To generate a diff of this commit: cvs rdiff -u -r1.1057 -r1.1058 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.59 -r1.60 src/tests/usr.bin/xlint/lint1/Makefile cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/xlint/lint1/lex_char.c \ src/tests/usr.bin/xlint/lint1/lex_char.exp \ src/tests/usr.bin/xlint/lint1/lex_floating.c \ src/tests/usr.bin/xlint/lint1/lex_floating.exp \ src/tests/usr.bin/xlint/lint1/lex_integer.c \ src/tests/usr.bin/xlint/lint1/lex_integer.exp \ src/tests/usr.bin/xlint/lint1/lex_string.c \ src/tests/usr.bin/xlint/lint1/lex_string.exp \ src/tests/usr.bin/xlint/lint1/lex_wide_char.c \ src/tests/usr.bin/xlint/lint1/lex_wide_char.exp \ src/tests/usr.bin/xlint/lint1/lex_wide_string.c \ src/tests/usr.bin/xlint/lint1/lex_wide_string.exp cvs rdiff -u -r1.52 -r1.53 src/tests/usr.bin/xlint/lint1/t_integration.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1057 src/distrib/sets/lists/tests/mi:1.1058 --- src/distrib/sets/lists/tests/mi:1.1057 Wed Jun 16 09:39:48 2021 +++ src/distrib/sets/lists/tests/mi Sat Jun 19 08:30:08 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1057 2021/06/16 09:39:48 rillig Exp $ +# $NetBSD: mi,v 1.1058 2021/06/19 08:30:08 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -6212,6 +6212,18 @@ ./usr/tests/usr.bin/xlint/lint1/gcc_init_compound_literal.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_char.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_char.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_floating.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_floating.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_integer.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_integer.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_string.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_string.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_wide_char.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_wide_char.exp tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_wide_string.c tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/xlint/lint1/lex_wide_string.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_000.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_000.exp tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/xlint/lint1/msg_001.c tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/xlint/lint1/Makefile diff -u src/tests/usr.bin/xlint/lint1/Makefile:1.59 src/tests/usr.bin/xlint/lint1/Makefile:1.60 --- src/tests/usr.bin/xlint/lint1/Makefile:1.59 Tue May 25 19:22:18 2021 +++ src/tests/usr.bin/xlint/lint1/Makefile Sat Jun 19 08:30:08 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.59 2021/05/25 19:22:18 rillig Exp $ +# $NetBSD: Makefile,v 1.60 2021/06/19 08:30:08 rillig Exp $ NOMAN= # defined MAX_MESSAGE= 344 # see lint1/err.c @@ -116,6 +116,18 @@ FILES+= gcc_init_compound_literal.c FILES+= gcc_init_compound_literal.exp FILES+= gcc_typeof_after_statement.c FILES+= gcc_typeof_after_statement.exp +FILES+= lex_char.c +FILES+= lex_char.exp +FILES+= lex_floating.c +FILES+= lex_floating.exp +FILES+= lex_integer.c +FILES+= lex_integer.exp +FILES+= lex_string.c +FILES+= lex_string.exp +FILES+= lex_wide_char.c +FILES+= lex_wide_char.exp +FILES+= lex_wide_string.c +FILES+= lex_wide_string.exp FILES+= ${:U0 ${:U:${:Urange=${MAX_MESSAGE}}}:C,^.$,0&,:C,^..$,0&,:@i@msg_${i}.c msg_${i}.exp@:Nmsg_176.exp} FILES+= op_colon.c FILES+= op_colon.exp Index: src/tests/usr.bin/xlint/lint1/t_integration.sh diff -u src/tests/usr.bin/xlint/lint1/t_integration.sh:1.52 src/tests/usr.bin/xlint/lint1/t_integration.sh:1.53 --- src/tests/usr.bin/xlint/lint1/t_integration.sh:1.52 Wed Jun 16 10:21:51 2021 +++ src/tests/usr.bin/xlint/lint1/t_integration.sh Sat Jun 19 08:30:08 2021 @@ -1,4 +1,4 @@ -# $NetBSD: t_integration.sh,v 1.52 2021/06/16 10:21:51 rillig Exp $ +# $NetBSD: t_integration.sh,v 1.53 2021/06/19 08:30:08 rillig Exp $ # # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc. # All rights reserved. @@ -174,6 +174,12 @@ test_case gcc_attribute_aligned test_case gcc_bit_field_types test_case gcc_init_compound_literal test_case gcc_typeof_after_statement +test_case lex_char +test_case lex_floating +test_case lex_integer +test_case lex_string +test_case lex_wide_char +test_case lex_wide_string test_case op_colon all_messages_body() Added files: Index: src/tests/usr.bin/xlint/lint1/lex_char.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_char.c:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_char.c Sat Jun 19 08:30:08 2021 @@ -0,0 +1,43 @@ +/* $NetBSD: lex_char.c,v 1.1 2021/06/19 08:30:08 rillig Exp $ */ +# 3 "lex_char.c" + +/* + * Tests for lexical analysis of character constants. + * + * C99 6.4.4.4 "Character constants" + */ + +void sink(char); + +void +test(void) +{ + /* expect+1: empty character constant */ + sink(''); + + sink('a'); + + sink('\0'); + + /* UTF-8 */ + /* expect+2: multi-character character constant */ + /* expect+1: conversion of 'int' to 'char' is out of range */ + sink('ä'); + /* rescue the parser: ' */ + + /* GCC extension */ + /* expect+1: dubious escape \e */ + sink('\e'); + + /* since C99 */ + sink('\x12'); + + /* octal */ + sink('\177'); + + /* newline */ + sink('\n'); + + /* expect+1: empty character constant */ + sink(''); +} Index: src/tests/usr.bin/xlint/lint1/lex_char.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_char.exp:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_char.exp Sat Jun 19 08:30:08 2021 @@ -0,0 +1,5 @@ +lex_char.c(16): error: empty character constant [73] +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(30): warning: dubious escape \e [79] +lex_char.c(42): error: empty character constant [73] Index: src/tests/usr.bin/xlint/lint1/lex_floating.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_floating.c:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_floating.c Sat Jun 19 08:30:08 2021 @@ -0,0 +1,35 @@ +/* $NetBSD: lex_floating.c,v 1.1 2021/06/19 08:30:08 rillig Exp $ */ +# 3 "lex_floating.c" + +/* + * Tests for lexical analysis of floating constants. + * + * C99 6.4.4.2 "Floating constants" + */ + +void sinkf(float); +void sinkd(double); +void sinkl(long double); + +void +test_float(void) +{ + sinkf(0.0F); + sinkf(0.0f); + sinkf(-0.0F); + sinkf(-0.0f); +} + +void +test_double(void) +{ + // https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4396272 + sinkd(2.2250738585072012e-308); + sinkd(1.23x); /* expect: syntax error 'x' */ +} + +void +test_long_double(void) +{ + sinkl(2.2250738585072012e-308L); +} Index: src/tests/usr.bin/xlint/lint1/lex_floating.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_floating.exp:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_floating.exp Sat Jun 19 08:30:08 2021 @@ -0,0 +1 @@ +lex_floating.c(28): error: syntax error 'x' [249] Index: src/tests/usr.bin/xlint/lint1/lex_integer.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_integer.c:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_integer.c Sat Jun 19 08:30:08 2021 @@ -0,0 +1,43 @@ +/* $NetBSD: lex_integer.c,v 1.1 2021/06/19 08:30:08 rillig Exp $ */ +# 3 "lex_integer.c" + +/* + * Tests for lexical analysis of integer constants. + * + * C99 6.4.4.1 "Integer constants" + */ + +void sinki(int); +void sinku(unsigned int); + +/* All platforms supported by lint have 32-bit int in two's complement. */ +void +test_signed_int(void) +{ + sinki(0); + + sinki(-1); + + sinki(2147483647); + + /* expect+2: converted from 'long' to 'int' due to prototype */ + /* expect+1: conversion of 'long' to 'int' is out of range */ + sinki(2147483648); + + sinki(-2147483647); + + /* expect+1: converted from 'long' to 'int' due to prototype */ + sinki(-2147483648); +} + +void +test_unsigned_int(void) +{ + sinku(0); + + sinku(4294967295U); + + /* expect+2: from 'unsigned long' to 'unsigned int' due to prototype */ + /* expect+1: conversion of 'unsigned long' to 'unsigned int' is out of range */ + sinku(4294967296U); +} Index: src/tests/usr.bin/xlint/lint1/lex_integer.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_integer.exp:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_integer.exp Sat Jun 19 08:30:08 2021 @@ -0,0 +1,5 @@ +lex_integer.c(25): warning: argument #1 is converted from 'long' to 'int' due to prototype [259] +lex_integer.c(25): warning: conversion of 'long' to 'int' is out of range, arg #1 [295] +lex_integer.c(30): warning: argument #1 is converted from 'long' to 'int' due to prototype [259] +lex_integer.c(42): warning: argument #1 is converted from 'unsigned long' to 'unsigned int' due to prototype [259] +lex_integer.c(42): warning: conversion of 'unsigned long' to 'unsigned int' is out of range, arg #1 [295] Index: src/tests/usr.bin/xlint/lint1/lex_string.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_string.c:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_string.c Sat Jun 19 08:30:08 2021 @@ -0,0 +1,35 @@ +/* $NetBSD: lex_string.c,v 1.1 2021/06/19 08:30:08 rillig Exp $ */ +# 3 "lex_string.c" + +/* + * Test lexical analysis of string constants. + * + * C99 6.4.5 "String literals" + */ + +void sink(const char *); + +void +test(void) +{ + sink(""); + + sink("hello, world\n"); + + sink("\0"); + + /* expect+5: unknown character \134 */ + /* expect+4: syntax error '0' */ + /* expect+3: unknown character \134 */ + /* expect+2: unknown character \134 */ + /* expect+1: unknown character \134 */ + sink("\0\0\0\0"); + + /* expect+1: unknown character \134 */ + sink("\x"); /* unfinished */ + + /* expect+1: unknown character \134 */ + sink("\y"); /* unknown escape sequence */ +} + +/* expect+1: cannot recover from previous errors */ Index: src/tests/usr.bin/xlint/lint1/lex_string.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_string.exp:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_string.exp Sat Jun 19 08:30:08 2021 @@ -0,0 +1,8 @@ +lex_string.c(26): error: unknown character \134 [250] +lex_string.c(26): error: syntax error '0' [249] +lex_string.c(26): error: unknown character \134 [250] +lex_string.c(26): error: unknown character \134 [250] +lex_string.c(26): error: unknown character \134 [250] +lex_string.c(29): error: unknown character \134 [250] +lex_string.c(32): error: unknown character \134 [250] +lex_string.c(36): error: cannot recover from previous errors [224] Index: src/tests/usr.bin/xlint/lint1/lex_wide_char.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_wide_char.c:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_wide_char.c Sat Jun 19 08:30:08 2021 @@ -0,0 +1,42 @@ +/* $NetBSD: lex_wide_char.c,v 1.1 2021/06/19 08:30:08 rillig Exp $ */ +# 3 "lex_wide_char.c" + +/* + * Tests for lexical analysis of character constants. + * + * C99 6.4.4.4 "Character constants" + */ + +void sink(int); + +void +test(void) +{ + /* TODO: expect+1: empty character constant */ + sink(L''); + + sink(L'a'); + + sink(L'\0'); + + /* UTF-8 */ + /* expect+1: too many characters in character constant */ + sink(L'ä'); + /* rescue the parser: ' */ + + /* GCC extension */ + /* expect+1: dubious escape \e */ + sink(L'\e'); + + /* since C99 */ + sink(L'\x12'); + + /* octal */ + sink(L'\177'); + + /* newline */ + sink(L'\n'); + + /* TODO: expect+1: empty character constant */ + sink(L''); +} Index: src/tests/usr.bin/xlint/lint1/lex_wide_char.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_wide_char.exp:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_wide_char.exp Sat Jun 19 08:30:08 2021 @@ -0,0 +1,2 @@ +lex_wide_char.c(24): error: too many characters in character constant [71] +lex_wide_char.c(29): warning: dubious escape \e [79] Index: src/tests/usr.bin/xlint/lint1/lex_wide_string.c diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_wide_string.c:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_wide_string.c Sat Jun 19 08:30:08 2021 @@ -0,0 +1,28 @@ +/* $NetBSD: lex_wide_string.c,v 1.1 2021/06/19 08:30:08 rillig Exp $ */ +# 3 "lex_wide_string.c" + +/* + * Test lexical analysis of wide string constants. + * + * C99 6.4.5 "String literals" + */ + +void sink(const int *); + +void +test(void) +{ + sink(L""); + + sink(L"hello, world\n"); + + sink(L"\0"); + + sink(L"\0\0\0\0"); + + /* expect+1: no hex digits follow \x [74] */ + sink(L"\x"); + + /* expect+1: dubious escape \y [79] */ + sink(L"\y"); +} Index: src/tests/usr.bin/xlint/lint1/lex_wide_string.exp diff -u /dev/null src/tests/usr.bin/xlint/lint1/lex_wide_string.exp:1.1 --- /dev/null Sat Jun 19 08:30:08 2021 +++ src/tests/usr.bin/xlint/lint1/lex_wide_string.exp Sat Jun 19 08:30:08 2021 @@ -0,0 +1,2 @@ +lex_wide_string.c(24): error: no hex digits follow \x [74] +lex_wide_string.c(27): warning: dubious escape \y [79]