Module Name:    src
Committed By:   rillig
Date:           Sun Feb 28 12:40:00 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: msg_003.c msg_108.c msg_124.c msg_126.c
            msg_156.c msg_210.c msg_247.c msg_275.c msg_308.c
        src/usr.bin/xlint/lint1: check-msgs.lua

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/usr.bin/xlint/lint1/msg_003.c \
    src/tests/usr.bin/xlint/lint1/msg_126.c \
    src/tests/usr.bin/xlint/lint1/msg_275.c
cvs rdiff -u -r1.4 -r1.5 src/tests/usr.bin/xlint/lint1/msg_108.c \
    src/tests/usr.bin/xlint/lint1/msg_156.c \
    src/tests/usr.bin/xlint/lint1/msg_210.c \
    src/tests/usr.bin/xlint/lint1/msg_308.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/xlint/lint1/msg_124.c
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/xlint/lint1/msg_247.c
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/xlint/lint1/check-msgs.lua

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/msg_003.c
diff -u src/tests/usr.bin/xlint/lint1/msg_003.c:1.3 src/tests/usr.bin/xlint/lint1/msg_003.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_003.c:1.3	Sun Jan 31 11:12:07 2021
+++ src/tests/usr.bin/xlint/lint1/msg_003.c	Sun Feb 28 12:40:00 2021
@@ -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
Index: src/tests/usr.bin/xlint/lint1/msg_126.c
diff -u src/tests/usr.bin/xlint/lint1/msg_126.c:1.3 src/tests/usr.bin/xlint/lint1/msg_126.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_126.c:1.3	Sun Jan 31 11:12:07 2021
+++ src/tests/usr.bin/xlint/lint1/msg_126.c	Sun Feb 28 12:40:00 2021
@@ -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 */
Index: src/tests/usr.bin/xlint/lint1/msg_275.c
diff -u src/tests/usr.bin/xlint/lint1/msg_275.c:1.3 src/tests/usr.bin/xlint/lint1/msg_275.c:1.4
--- src/tests/usr.bin/xlint/lint1/msg_275.c:1.3	Sun Feb 28 01:36:46 2021
+++ src/tests/usr.bin/xlint/lint1/msg_275.c	Sun Feb 28 12:40:00 2021
@@ -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 */
 

Index: src/tests/usr.bin/xlint/lint1/msg_108.c
diff -u src/tests/usr.bin/xlint/lint1/msg_108.c:1.4 src/tests/usr.bin/xlint/lint1/msg_108.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_108.c:1.4	Sun Jan 31 11:12:07 2021
+++ src/tests/usr.bin/xlint/lint1/msg_108.c	Sun Feb 28 12:40:00 2021
@@ -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
Index: src/tests/usr.bin/xlint/lint1/msg_156.c
diff -u src/tests/usr.bin/xlint/lint1/msg_156.c:1.4 src/tests/usr.bin/xlint/lint1/msg_156.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_156.c:1.4	Sat Feb 27 13:43:36 2021
+++ src/tests/usr.bin/xlint/lint1/msg_156.c	Sun Feb 28 12:40:00 2021
@@ -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,
Index: src/tests/usr.bin/xlint/lint1/msg_210.c
diff -u src/tests/usr.bin/xlint/lint1/msg_210.c:1.4 src/tests/usr.bin/xlint/lint1/msg_210.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_210.c:1.4	Mon Feb 22 15:09:50 2021
+++ src/tests/usr.bin/xlint/lint1/msg_210.c	Sun Feb 28 12:40:00 2021
@@ -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
Index: src/tests/usr.bin/xlint/lint1/msg_308.c
diff -u src/tests/usr.bin/xlint/lint1/msg_308.c:1.4 src/tests/usr.bin/xlint/lint1/msg_308.c:1.5
--- src/tests/usr.bin/xlint/lint1/msg_308.c:1.4	Sun Jan 31 11:12:07 2021
+++ src/tests/usr.bin/xlint/lint1/msg_308.c	Sun Feb 28 12:40:00 2021
@@ -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;

Index: src/tests/usr.bin/xlint/lint1/msg_124.c
diff -u src/tests/usr.bin/xlint/lint1/msg_124.c:1.7 src/tests/usr.bin/xlint/lint1/msg_124.c:1.8
--- src/tests/usr.bin/xlint/lint1/msg_124.c:1.7	Mon Feb 15 07:18:20 2021
+++ src/tests/usr.bin/xlint/lint1/msg_124.c	Sun Feb 28 12:40:00 2021
@@ -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 */
 

Index: src/tests/usr.bin/xlint/lint1/msg_247.c
diff -u src/tests/usr.bin/xlint/lint1/msg_247.c:1.2 src/tests/usr.bin/xlint/lint1/msg_247.c:1.3
--- src/tests/usr.bin/xlint/lint1/msg_247.c:1.2	Sun Feb 21 09:07:58 2021
+++ src/tests/usr.bin/xlint/lint1/msg_247.c	Sun Feb 28 12:40:00 2021
@@ -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."

Index: src/usr.bin/xlint/lint1/check-msgs.lua
diff -u src/usr.bin/xlint/lint1/check-msgs.lua:1.7 src/usr.bin/xlint/lint1/check-msgs.lua:1.8
--- src/usr.bin/xlint/lint1/check-msgs.lua:1.7	Fri Feb 19 23:22:19 2021
+++ src/usr.bin/xlint/lint1/check-msgs.lua	Sun Feb 28 12:40:00 2021
@@ -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 @@ local function collect_errors(fname, msg
   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 @@ local function check_file(fname, msgs)
   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 @@ local function main(arg)
   for _, fname in ipairs(arg) do
     ok = check_file(fname, msgs) and ok
   end
+  ok = check_test_files(msgs) and ok
   return ok
 end
 

Reply via email to