Source-Changes-HG archive

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

[src/trunk]: src tests/lint: make 'expect+-' comments stricter



details:   https://anonhg.NetBSD.org/src/rev/3f975a58cf64
branches:  trunk
changeset: 366831:3f975a58cf64
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Jun 17 18:54:53 2022 +0000

description:
tests/lint: make 'expect+-' comments stricter

Previously, the expectations from these comments were already satisfied
if the expectation occurred somewhere in the actual message from lint.
This meant that the prefix 'error:' or 'warning:' could be omitted from
the 'expect' comment.  These omissions were hard to see in a manual
review.  Now any omissions must be visually marked with '...'.

The test msg_342 now reports its messages properly as being in the file
msg_342.c, rather than msg_341.c.  This had been a copy-and-paste
mistake.

diffstat:

 tests/usr.bin/xlint/check-expect.lua                   |   66 ++++++-
 tests/usr.bin/xlint/lint1/c11_generic_expression.c     |   12 +-
 tests/usr.bin/xlint/lint1/d_c99_init.c                 |   12 +-
 tests/usr.bin/xlint/lint1/d_init_array_using_string.c  |    6 +-
 tests/usr.bin/xlint/lint1/decl.c                       |   18 +-
 tests/usr.bin/xlint/lint1/decl_direct_abstract.c       |   22 +-
 tests/usr.bin/xlint/lint1/decl_enum_c90.c              |    4 +-
 tests/usr.bin/xlint/lint1/decl_struct_member.c         |    4 +-
 tests/usr.bin/xlint/lint1/expr_binary.c                |   78 +++---
 tests/usr.bin/xlint/lint1/expr_binary_trad.c           |   30 +-
 tests/usr.bin/xlint/lint1/expr_precedence.c            |    4 +-
 tests/usr.bin/xlint/lint1/feat_stacktrace.c            |    4 +-
 tests/usr.bin/xlint/lint1/gcc_attribute.c              |    6 +-
 tests/usr.bin/xlint/lint1/gcc_attribute_aligned.c      |    4 +-
 tests/usr.bin/xlint/lint1/gcc_attribute_enum.c         |    4 +-
 tests/usr.bin/xlint/lint1/gcc_init_compound_literal.c  |    4 +-
 tests/usr.bin/xlint/lint1/gcc_stmt_asm.c               |    4 +-
 tests/usr.bin/xlint/lint1/gcc_typeof_after_statement.c |    4 +-
 tests/usr.bin/xlint/lint1/init_c90.c                   |    4 +-
 tests/usr.bin/xlint/lint1/lex_char.c                   |   12 +-
 tests/usr.bin/xlint/lint1/lex_integer.c                |   68 +++---
 tests/usr.bin/xlint/lint1/lex_integer_binary.c         |    4 +-
 tests/usr.bin/xlint/lint1/lex_integer_ilp32.c          |   10 +-
 tests/usr.bin/xlint/lint1/lex_string.c                 |    6 +-
 tests/usr.bin/xlint/lint1/lex_wide_char.c              |   10 +-
 tests/usr.bin/xlint/lint1/lex_wide_string.c            |    6 +-
 tests/usr.bin/xlint/lint1/msg_005.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_031.c                    |    6 +-
 tests/usr.bin/xlint/lint1/msg_034.c                    |    6 +-
 tests/usr.bin/xlint/lint1/msg_041.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_048.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_066.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_069.c                    |    6 +-
 tests/usr.bin/xlint/lint1/msg_077.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_080.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_103.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_104.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_118.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_155.c                    |   26 +-
 tests/usr.bin/xlint/lint1/msg_184.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_189.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_193.c                    |  174 ++++++++--------
 tests/usr.bin/xlint/lint1/msg_211.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_232.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_249.c                    |    6 +-
 tests/usr.bin/xlint/lint1/msg_250.c                    |    6 +-
 tests/usr.bin/xlint/lint1/msg_251.c                    |    6 +-
 tests/usr.bin/xlint/lint1/msg_253.c                    |    6 +-
 tests/usr.bin/xlint/lint1/msg_254.c                    |   12 +-
 tests/usr.bin/xlint/lint1/msg_257.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_259.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_259_c90.c                |    4 +-
 tests/usr.bin/xlint/lint1/msg_259_ilp32.c              |    8 +-
 tests/usr.bin/xlint/lint1/msg_265.c                    |    6 +-
 tests/usr.bin/xlint/lint1/msg_283.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_289.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_312.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_333.c                    |    8 +-
 tests/usr.bin/xlint/lint1/msg_341.c                    |   14 +-
 tests/usr.bin/xlint/lint1/msg_342.c                    |   16 +-
 tests/usr.bin/xlint/lint1/msg_342.exp                  |   40 +-
 tests/usr.bin/xlint/lint1/msg_343.c                    |   10 +-
 tests/usr.bin/xlint/lint1/msg_344.c                    |    4 +-
 tests/usr.bin/xlint/lint1/msg_345.c                    |    4 +-
 tests/usr.bin/xlint/lint1/op_colon.c                   |   32 +-
 tests/usr.bin/xlint/lint1/parse_stmt_error.c           |    6 +-
 tests/usr.bin/xlint/lint1/parse_stmt_iter_error.c      |    8 +-
 tests/usr.bin/xlint/lint1/parse_type_name.c            |    8 +-
 tests/usr.bin/xlint/lint1/stmt_for.c                   |    4 +-
 tests/usr.bin/xlint/lint1/stmt_goto.c                  |    8 +-
 tests/usr.bin/xlint/lint1/stmt_if.c                    |    4 +-
 usr.bin/xlint/lint1/README.md                          |    6 +-
 72 files changed, 491 insertions(+), 431 deletions(-)

diffs (truncated from 2735 to 300 lines):

diff -r a733062c28d7 -r 3f975a58cf64 tests/usr.bin/xlint/check-expect.lua
--- a/tests/usr.bin/xlint/check-expect.lua      Fri Jun 17 16:45:22 2022 +0000
+++ b/tests/usr.bin/xlint/check-expect.lua      Fri Jun 17 18:54:53 2022 +0000
@@ -1,5 +1,5 @@
 #!  /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.20 2022/06/17 16:10:10 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.21 2022/06/17 18:54:53 rillig Exp $
 
 --[[
 
@@ -12,6 +12,17 @@
 ]]
 
 
+local function test(func)
+  func()
+end
+
+local function assert_equals(got, expected)
+  if got ~= expected then
+    assert(false, string.format("got %q, expected %q", got, expected))
+  end
+end
+
+
 local had_errors = false
 ---@param fmt string
 function print_error(fmt, ...)
@@ -34,6 +45,7 @@
   return lines
 end
 
+
 -- Load the 'expect:' comments from a C source file.
 --
 -- example return values:
@@ -114,6 +126,52 @@
 end
 
 
+---@param comment string
+---@param pattern string
+---@return boolean
+local function matches(comment, pattern)
+  if comment == "" then return false end
+
+  local any_prefix = pattern:sub(1, 3) == "..."
+  if any_prefix then pattern = pattern:sub(4) end
+  local any_suffix = pattern:sub(-3) == "..."
+  if any_suffix then pattern = pattern:sub(1, -4) end
+
+  if any_prefix and any_suffix then
+    return comment:find(pattern, 1, true) ~= nil
+  elseif any_prefix then
+    return pattern ~= "" and comment:sub(-#pattern) == pattern
+  elseif any_suffix then
+    return comment:sub(1, #pattern) == pattern
+  else
+    return comment == pattern
+  end
+end
+
+test(function()
+  assert_equals(matches("a", "a"), true)
+  assert_equals(matches("a", "b"), false)
+  assert_equals(matches("a", "aaa"), false)
+
+  assert_equals(matches("abc", "a..."), true)
+  assert_equals(matches("abc", "c..."), false)
+
+  assert_equals(matches("abc", "...c"), true)
+  assert_equals(matches("abc", "...a"), false)
+
+  assert_equals(matches("abc123xyz", "...a..."), true)
+  assert_equals(matches("abc123xyz", "...b..."), true)
+  assert_equals(matches("abc123xyz", "...c..."), true)
+  assert_equals(matches("abc123xyz", "...1..."), true)
+  assert_equals(matches("abc123xyz", "...2..."), true)
+  assert_equals(matches("abc123xyz", "...3..."), true)
+  assert_equals(matches("abc123xyz", "...x..."), true)
+  assert_equals(matches("abc123xyz", "...y..."), true)
+  assert_equals(matches("abc123xyz", "...z..."), true)
+  assert_equals(matches("pattern", "...pattern..."), true)
+end)
+
+
 local function check_test(c_fname)
   local exp_fname = c_fname:gsub("%.c$", ".exp")
 
@@ -125,12 +183,12 @@
 
   for _, exp_message in ipairs(exp_messages) do
     local c_comments = c_comments_by_location[exp_message.location] or {}
-    local expected_comment =
+    local expected_message =
       exp_message.message:gsub("/%*", "**"):gsub("%*/", "**")
 
     local found = false
     for i, c_comment in ipairs(c_comments) do
-      if c_comment ~= "" and expected_comment:find(c_comment, 1, true) then
+      if c_comment ~= "" and matches(expected_message, c_comment) then
         c_comments[i] = ""
         found = true
         break
@@ -139,7 +197,7 @@
 
     if not found then
       print_error("error: %s: missing /* expect+1: %s */",
-        exp_message.location, expected_comment)
+        exp_message.location, expected_message)
     end
   end
 
diff -r a733062c28d7 -r 3f975a58cf64 tests/usr.bin/xlint/lint1/c11_generic_expression.c
--- a/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Fri Jun 17 16:45:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/c11_generic_expression.c        Fri Jun 17 18:54:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: c11_generic_expression.c,v 1.11 2022/01/15 14:22:03 rillig Exp $       */
+/*     $NetBSD: c11_generic_expression.c,v 1.12 2022/06/17 18:54:53 rillig Exp $       */
 # 3 "c11_generic_expression.c"
 
 /*
@@ -20,14 +20,14 @@
 const char *
 classify_type_without_default(double var)
 {
-       /* expect-2: argument 'var' unused */
+       /* expect-2: warning: argument 'var' unused in function 'classify_type_without_default' [231] */
 
        return _Generic(var,
            long double: "long double",
            long long: "long long",
            unsigned: "unsigned"
        );
-       /* expect-1: expects to return value [214] */
+       /* expect-1: warning: function 'classify_type_without_default' expects to return value [214] */
 }
 
 /*
@@ -36,7 +36,7 @@
 const char *
 classify_type_with_default(double var)
 {
-       /* expect-2: argument 'var' unused */
+       /* expect-2: warning: argument 'var' unused in function 'classify_type_with_default' [231] */
 
        return _Generic(var,
            long double: "long double",
@@ -52,7 +52,7 @@
 const char *
 classify_char(char c)
 {
-       /* expect-2: argument 'c' unused */
+       /* expect-2: warning: argument 'c' unused in function 'classify_char' [231] */
 
        return _Generic(c,
            char: "yes",
@@ -74,7 +74,7 @@
            char: "first",
            double: 2.0
        );
-       /* expect+1: without returning value [217] */
+       /* expect+1: warning: function comma_expression falls off bottom without returning value [217] */
 }
 
 /*
diff -r a733062c28d7 -r 3f975a58cf64 tests/usr.bin/xlint/lint1/d_c99_init.c
--- a/tests/usr.bin/xlint/lint1/d_c99_init.c    Fri Jun 17 16:45:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_init.c    Fri Jun 17 18:54:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_c99_init.c,v 1.40 2022/01/15 14:22:03 rillig Exp $   */
+/*     $NetBSD: d_c99_init.c,v 1.41 2022/06/17 18:54:53 rillig Exp $   */
 # 3 "d_c99_init.c"
 
 /*
@@ -222,11 +222,11 @@
        .pentagons[0].points[4].x = 1,
        .points[0][0][0] = { 0, 0 },
        .points[2][4][1] = {301, 302 },
-       /* expect+1: array subscript cannot be > 2: 3 */
+       /* expect+1: error: array subscript cannot be > 2: 3 [168] */
        .points[3][0][0] = {3001, 3002 },
-       /* expect+1: array subscript cannot be > 4: 5 */
+       /* expect+1: error: array subscript cannot be > 4: 5 [168] */
        .points[0][5][0] = {501, 502 },
-       /* expect+1: array subscript cannot be > 1: 2 */
+       /* expect+1: error: array subscript cannot be > 1: 2 [168] */
        .points[0][0][2] = {21, 22 },
 };
 
@@ -235,13 +235,13 @@
        int:0;
 } ends_with_unnamed_bit_field = {
        12345,
-       /* expect+1: too many struct/union initializers */
+       /* expect+1: error: too many struct/union initializers [172] */
        23456,
 };
 
 char prefixed_message[] = {
        'E', ':', ' ',
-       /* expect+1: illegal combination of integer (char) and pointer */
+       /* expect+1: warning: illegal combination of integer (char) and pointer (pointer to char) [183] */
        "message\n",
 };
 
diff -r a733062c28d7 -r 3f975a58cf64 tests/usr.bin/xlint/lint1/d_init_array_using_string.c
--- a/tests/usr.bin/xlint/lint1/d_init_array_using_string.c     Fri Jun 17 16:45:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/d_init_array_using_string.c     Fri Jun 17 18:54:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: d_init_array_using_string.c,v 1.10 2022/01/15 14:22:03 rillig Exp $    */
+/*     $NetBSD: d_init_array_using_string.c,v 1.11 2022/06/17 18:54:53 rillig Exp $    */
 # 3 "d_init_array_using_string.c"
 
 /*
@@ -72,9 +72,9 @@
        };
 
        struct cs_ws too_many_characters = {
-               /* expect+1: warning: string literal too long (11) for target array (10) */
+               /* expect+1: warning: string literal too long (11) for target array (10) [187] */
                "0123456789X",
-               /* expect+1: warning: string literal too long (11) for target array (10) */
+               /* expect+1: warning: string literal too long (11) for target array (10) [187] */
                L"0123456789X",
        };
 
diff -r a733062c28d7 -r 3f975a58cf64 tests/usr.bin/xlint/lint1/decl.c
--- a/tests/usr.bin/xlint/lint1/decl.c  Fri Jun 17 16:45:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl.c  Fri Jun 17 18:54:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: decl.c,v 1.16 2022/06/11 11:52:13 rillig Exp $ */
+/*     $NetBSD: decl.c,v 1.17 2022/06/17 18:54:53 rillig Exp $ */
 # 3 "decl.c"
 
 /*
@@ -39,7 +39,7 @@
 void
 declarator_with_prefix_qualifier(void)
 {
-       /* expect+1: syntax error 'const' [249] */
+       /* expect+1: error: syntax error 'const' [249] */
        char a = 1, const b = 2;
 
        a = 1;
@@ -50,7 +50,7 @@
 void
 declarator_with_postfix_qualifier(void)
 {
-       /* expect+1: syntax error 'const' [249] */
+       /* expect+1: error: syntax error 'const' [249] */
        char a = 1, b const = 2;
 
        a = 1;
@@ -64,11 +64,11 @@
 {
        char *pc = 0, c = 0, **ppc = 0;
 
-       /* expect+1: warning: converting 'pointer to char' to incompatible 'pointer to double' */
+       /* expect+1: warning: converting 'pointer to char' to incompatible 'pointer to double' for argument 1 [153] */
        sink(pc);
-       /* expect+1: warning: illegal combination of pointer (pointer to double) and integer (char) */
+       /* expect+1: warning: illegal combination of pointer (pointer to double) and integer (char), arg #1 [154] */
        sink(c);
-       /* expect+1: converting 'pointer to pointer to char' to incompatible 'pointer to double' */
+       /* expect+1: warning: converting 'pointer to pointer to char' to incompatible 'pointer to double' for argument 1 [153] */
        sink(ppc);
 }
 
@@ -76,7 +76,7 @@
 enum_error_handling(void)
 {
        enum {
-               /* expect+1: syntax error '"' [249] */
+               /* expect+1: error: syntax error '"' [249] */
                "error 1"
                :               /* still the same error */
                ,               /* back on track */
@@ -160,11 +160,11 @@
     sizeof(const typeof(unnamed_struct));
 
 /* expect+2: error: old style declaration; add 'int' [1] */
-/* expect+1: syntax error 'int' [249] */
+/* expect+1: error: syntax error 'int' [249] */
 thread int thread_int;
 __thread int thread_int;
 /* expect+2: error: old style declaration; add 'int' [1] */
-/* expect+1: syntax error 'int' [249] */
+/* expect+1: error: syntax error 'int' [249] */
 __thread__ int thread_int;
 
 /* expect+4: error: old style declaration; add 'int' [1] */
diff -r a733062c28d7 -r 3f975a58cf64 tests/usr.bin/xlint/lint1/decl_direct_abstract.c
--- a/tests/usr.bin/xlint/lint1/decl_direct_abstract.c  Fri Jun 17 16:45:22 2022 +0000
+++ b/tests/usr.bin/xlint/lint1/decl_direct_abstract.c  Fri Jun 17 18:54:53 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: decl_direct_abstract.c,v 1.6 2022/04/01 23:16:32 rillig Exp $  */
+/*     $NetBSD: decl_direct_abstract.c,v 1.7 2022/06/17 18:54:53 rillig Exp $  */
 # 3 "decl_direct_abstract.c"
 



Home | Main Index | Thread Index | Old Index