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: ensure that tests on a messa...



details:   https://anonhg.NetBSD.org/src/rev/db6f7e77f5c6
branches:  trunk
changeset: 1027706:db6f7e77f5c6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Dec 16 21:14:58 2021 +0000

description:
tests/lint: ensure that tests on a message mention this message

diffstat:

 tests/usr.bin/xlint/lint1/msg_230_uchar.c |   4 ++--
 usr.bin/xlint/lint1/check-msgs.lua        |  21 +++++++++++++++------
 2 files changed, 17 insertions(+), 8 deletions(-)

diffs (58 lines):

diff -r 1c5d8f5057da -r db6f7e77f5c6 tests/usr.bin/xlint/lint1/msg_230_uchar.c
--- a/tests/usr.bin/xlint/lint1/msg_230_uchar.c Thu Dec 16 20:23:40 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/msg_230_uchar.c Thu Dec 16 21:14:58 2021 +0000
@@ -1,7 +1,7 @@
-/*     $NetBSD: msg_230_uchar.c,v 1.5 2021/12/16 20:23:40 rillig Exp $ */
+/*     $NetBSD: msg_230_uchar.c,v 1.6 2021/12/16 21:14:59 rillig Exp $ */
 # 3 "msg_230_uchar.c"
 
-// Test for message: nonportable character comparison, op %s [230]
+// Test for message: nonportable character comparison '%s %d' [230]
 
 /* lint1-flags: -S -g -p -w */
 /* lint1-only-if: uchar */
diff -r 1c5d8f5057da -r db6f7e77f5c6 usr.bin/xlint/lint1/check-msgs.lua
--- a/usr.bin/xlint/lint1/check-msgs.lua        Thu Dec 16 20:23:40 2021 +0000
+++ b/usr.bin/xlint/lint1/check-msgs.lua        Thu Dec 16 21:14:58 2021 +0000
@@ -1,5 +1,5 @@
 #! /usr/bin/lua
--- $NetBSD: check-msgs.lua,v 1.12 2021/09/04 12:30:46 rillig Exp $
+-- $NetBSD: check-msgs.lua,v 1.13 2021/12/16 21:14:58 rillig Exp $
 
 --[[
 
@@ -98,6 +98,8 @@
 end
 
 
+-- Ensure that each test file for a particular message mentions the full text
+-- of that message and the message ID.
 local function check_test_files(msgs)
 
   local msgids = {}
@@ -107,13 +109,20 @@
   table.sort(msgids)
 
   local testdir = "../../../tests/usr.bin/xlint/lint1"
-  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
-      print_error("%s must contain: %s", filename, msg)
+  local cmd = ("cd '%s' && printf '%%s\\n' msg_[0-9][0-9][0-9]*.c"):format(testdir)
+  local filenames = assert(io.popen(cmd))
+  for filename in filenames:lines() do
+    local msgid = tonumber(filename:match("^msg_(%d%d%d)"))
+    if msgs[msgid] then
+      local unescaped_msg = msgs[msgid]:gsub("\\(.)", "%1")
+      local expected_text = ("%s [%d]"):format(unescaped_msg, msgid)
+      local fullname = ("%s/%s"):format(testdir, filename)
+      if not file_contains(fullname, expected_text) then
+        print_error("%s must contain: %s", fullname, expected_text)
+      end
     end
   end
+  filenames:close()
 end
 
 local function main(arg)



Home | Main Index | Thread Index | Old Index