Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src tests/lint: add test cases for lexical analysis



details:   https://anonhg.NetBSD.org/src/rev/e7b35782d7bc
branches:  trunk
changeset: 379776:e7b35782d7bc
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 19 08:30:08 2021 +0000

description:
tests/lint: add test cases for lexical analysis

diffstat:

 distrib/sets/lists/tests/mi                   |  14 ++++++++-
 tests/usr.bin/xlint/lint1/Makefile            |  14 ++++++++-
 tests/usr.bin/xlint/lint1/lex_char.c          |  43 +++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/lex_char.exp        |   5 +++
 tests/usr.bin/xlint/lint1/lex_floating.c      |  35 +++++++++++++++++++++
 tests/usr.bin/xlint/lint1/lex_floating.exp    |   1 +
 tests/usr.bin/xlint/lint1/lex_integer.c       |  43 +++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/lex_integer.exp     |   5 +++
 tests/usr.bin/xlint/lint1/lex_string.c        |  35 +++++++++++++++++++++
 tests/usr.bin/xlint/lint1/lex_string.exp      |   8 +++++
 tests/usr.bin/xlint/lint1/lex_wide_char.c     |  42 ++++++++++++++++++++++++++
 tests/usr.bin/xlint/lint1/lex_wide_char.exp   |   2 +
 tests/usr.bin/xlint/lint1/lex_wide_string.c   |  28 +++++++++++++++++
 tests/usr.bin/xlint/lint1/lex_wide_string.exp |   2 +
 tests/usr.bin/xlint/lint1/t_integration.sh    |   8 ++++-
 15 files changed, 282 insertions(+), 3 deletions(-)

diffs (truncated from 375 to 300 lines):

diff -r a3a370a85dc2 -r e7b35782d7bc distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi       Sat Jun 19 06:19:35 2021 +0000
+++ b/distrib/sets/lists/tests/mi       Sat Jun 19 08:30:08 2021 +0000
@@ -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
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/Makefile
--- a/tests/usr.bin/xlint/lint1/Makefile        Sat Jun 19 06:19:35 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/Makefile        Sat Jun 19 08:30:08 2021 +0000
@@ -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
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_char.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_char.c      Sat Jun 19 08:30:08 2021 +0000
@@ -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('');
+}
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_char.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_char.exp    Sat Jun 19 08:30:08 2021 +0000
@@ -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]
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_floating.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_floating.c  Sat Jun 19 08:30:08 2021 +0000
@@ -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);
+}
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_floating.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_floating.exp        Sat Jun 19 08:30:08 2021 +0000
@@ -0,0 +1,1 @@
+lex_floating.c(28): error: syntax error 'x' [249]
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_integer.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer.c   Sat Jun 19 08:30:08 2021 +0000
@@ -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);
+}
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_integer.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_integer.exp Sat Jun 19 08:30:08 2021 +0000
@@ -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]
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_string.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_string.c    Sat Jun 19 08:30:08 2021 +0000
@@ -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 */
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_string.exp
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_string.exp  Sat Jun 19 08:30:08 2021 +0000
@@ -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]
diff -r a3a370a85dc2 -r e7b35782d7bc tests/usr.bin/xlint/lint1/lex_wide_char.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/usr.bin/xlint/lint1/lex_wide_char.c Sat Jun 19 08:30:08 2021 +0000
@@ -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');
+



Home | Main Index | Thread Index | Old Index