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

This commit is contained in:
rillig 2021-12-16 21:14:58 +00:00
parent 38da6713f9
commit a8a62f37ee
2 changed files with 17 additions and 8 deletions

View File

@ -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 */

View File

@ -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 @@ local function file_contains(filename, text)
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 @@ local function check_test_files(msgs)
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)