Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 tests/lint: keep messages in test files ...



details:   https://anonhg.NetBSD.org/src/rev/f79bc00ffa21
branches:  trunk
changeset: 959900:f79bc00ffa21
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Feb 28 12:40:00 2021 +0000

description:
tests/lint: keep messages in test files in sync with actual messages

Each of the tests named msg_*.c repeats the template of the message, to
make the test somewhat self-contained when viewed in isolation.

This creates a redundancy, and keeping track of this manually is next to
impossible.  I tried it and failed in 9 cases, even though it has just
been 2 months since I myself created the initial files and I knew all
the time that this redundancy exists.

Be fool-proof for the future by checking this automatically.

diffstat:

 tests/usr.bin/xlint/lint1/msg_003.c |   4 ++--
 tests/usr.bin/xlint/lint1/msg_108.c |   4 ++--
 tests/usr.bin/xlint/lint1/msg_124.c |   4 ++--
 tests/usr.bin/xlint/lint1/msg_126.c |   4 ++--
 tests/usr.bin/xlint/lint1/msg_156.c |   4 ++--
 tests/usr.bin/xlint/lint1/msg_210.c |   4 ++--
 tests/usr.bin/xlint/lint1/msg_247.c |   4 ++--
 tests/usr.bin/xlint/lint1/msg_275.c |   4 ++--
 tests/usr.bin/xlint/lint1/msg_308.c |   4 ++--
 usr.bin/xlint/lint1/check-msgs.lua  |  37 ++++++++++++++++++++++++++++++++++++-
 10 files changed, 54 insertions(+), 19 deletions(-)

diffs (183 lines):

diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_003.c
--- a/tests/usr.bin/xlint/lint1/msg_003.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_003.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_003.c,v 1.3 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_003.c,v 1.4 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_003.c"
 
-// Test for message: %s declared in argument declaration list [3]
+// Test for message: '%s' declared in argument declaration list [3]
 
 /*ARGSUSED*/
 void
diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_108.c
--- a/tests/usr.bin/xlint/lint1/msg_108.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_108.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_108.c,v 1.4 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_108.c,v 1.5 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_108.c"
 
-// Test for message: operand of '%s' has incompatible type (%s != %s) [108]
+// Test for message: operand of '%s' has invalid type (%s) [108]
 
 /*
  * Before tree.c 1.137 from 2021-01-19, taking the complement of a struct
diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_124.c
--- a/tests/usr.bin/xlint/lint1/msg_124.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_124.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_124.c,v 1.7 2021/02/15 07:18:20 rillig Exp $       */
+/*     $NetBSD: msg_124.c,v 1.8 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_124.c"
 
-// Test for message: illegal pointer combination, op %s [124]
+// Test for message: illegal pointer combination (%s) and (%s), op %s [124]
 
 /* lint1-extra-flags: -s */
 
diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_126.c
--- a/tests/usr.bin/xlint/lint1/msg_126.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_126.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_126.c,v 1.3 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_126.c,v 1.4 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_126.c"
 
-// Test for message: incompatible types in conditional [126]
+// Test for message: incompatible types '%s' and '%s' in conditional [126]
 
 int
 max(int cond, void *ptr, double dbl)   /* expect: 231, 231, 231 */
diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_156.c
--- a/tests/usr.bin/xlint/lint1/msg_156.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_156.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_156.c,v 1.4 2021/02/27 13:43:36 rillig Exp $       */
+/*     $NetBSD: msg_156.c,v 1.5 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_156.c"
 
-// Test for message: enum type mismatch, arg #%d [156]
+// Test for message: enum type mismatch, arg #%d (%s != %s) [156]
 
 enum color {
        RED     = 1 << 0,
diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_210.c
--- a/tests/usr.bin/xlint/lint1/msg_210.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_210.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_210.c,v 1.4 2021/02/22 15:09:50 rillig Exp $       */
+/*     $NetBSD: msg_210.c,v 1.5 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_210.c"
 
-// Test for message: enum type mismatch in initialization [210]
+// Test for message: enum type mismatch between '%s' and '%s' in initialization [210]
 
 enum A {
        A1
diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_247.c
--- a/tests/usr.bin/xlint/lint1/msg_247.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_247.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_247.c,v 1.2 2021/02/21 09:07:58 rillig Exp $       */
+/*     $NetBSD: msg_247.c,v 1.3 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_247.c"
 
-// Test for message: pointer casts may be troublesome [247]
+// Test for message: pointer cast from '%s' to '%s' may be troublesome [247]
 
 TODO: "Add example code that triggers the above message." /* expect: 249 */
 TODO: "Add example code that almost triggers the above message."
diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_275.c
--- a/tests/usr.bin/xlint/lint1/msg_275.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_275.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_275.c,v 1.3 2021/02/28 01:36:46 rillig Exp $       */
+/*     $NetBSD: msg_275.c,v 1.4 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_275.c"
 
-// Test for message: cast discards 'const' from pointer target type [275]
+// Test for message: cast discards 'const' from type '%s' [275]
 
 /* lint1-extra-flags: -h */
 
diff -r 170b9979d214 -r f79bc00ffa21 tests/usr.bin/xlint/lint1/msg_308.c
--- a/tests/usr.bin/xlint/lint1/msg_308.c       Sun Feb 28 09:04:28 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_308.c       Sun Feb 28 12:40:00 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_308.c,v 1.4 2021/01/31 11:12:07 rillig Exp $       */
+/*     $NetBSD: msg_308.c,v 1.5 2021/02/28 12:40:00 rillig Exp $       */
 # 3 "msg_308.c"
 
-// Test for message: Invalid type for _Complex [308]
+// Test for message: invalid type for _Complex [308]
 
 float _Complex float_complex;
 double _Complex double_complex;
diff -r 170b9979d214 -r f79bc00ffa21 usr.bin/xlint/lint1/check-msgs.lua
--- a/usr.bin/xlint/lint1/check-msgs.lua        Sun Feb 28 09:04:28 2021 +0000
+++ b/usr.bin/xlint/lint1/check-msgs.lua        Sun Feb 28 12:40:00 2021 +0000
@@ -1,5 +1,5 @@
 #! /usr/bin/lua
--- $NetBSD: check-msgs.lua,v 1.7 2021/02/19 23:22:19 rillig Exp $
+-- $NetBSD: check-msgs.lua,v 1.8 2021/02/28 12:40:00 rillig Exp $
 
 --[[
 
@@ -74,6 +74,7 @@
   errors.add = function(self, fmt, ...)
     table.insert(self, fmt:format(...))
   end
+
   local f = assert(io.open(fname, "r"))
   local lineno = 0
   local prev = ""
@@ -110,6 +111,39 @@
   return #errors == 0
 end
 
+local function file_contains(filename, text)
+  local f = assert(io.open(filename, "r"))
+  for line in f:lines() do
+    if line:find(text, 1, true) then
+      f:close()
+      return true
+    end
+  end
+  f:close()
+  return false
+end
+
+local function check_test_files(msgs)
+
+  local msgids = {}
+  for msgid, _ in pairs(msgs) do
+    table.insert(msgids, msgid)
+  end
+  table.sort(msgids)
+
+  local testdir = "../../../tests/usr.bin/xlint/lint1"
+  local ok = true
+  for _, msgid in ipairs(msgids) do
+    local msg = msgs[msgid]:gsub("\\(.)", "%1")
+    local filename = ("%s/msg_%03d.c"):format(testdir, msgid)
+    if not file_contains(filename, msg) then
+      ok = false
+      print(("%s must contain: %s"):format(filename, msg))
+    end
+  end
+
+  return ok
+end
 
 local function main(arg)
   local msgs = load_messages("err.c")
@@ -117,6 +151,7 @@
   for _, fname in ipairs(arg) do
     ok = check_file(fname, msgs) and ok
   end
+  ok = check_test_files(msgs) and ok
   return ok
 end
 



Home | Main Index | Thread Index | Old Index