Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint2 tests/lint: align message checker for li...
details: https://anonhg.NetBSD.org/src/rev/c58c39288a5b
branches: trunk
changeset: 985837:c58c39288a5b
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Sep 10 21:05:08 2021 +0000
description:
tests/lint: align message checker for lint2 to the one from lint1
No functional change.
diffstat:
usr.bin/xlint/lint2/check-msgs.lua | 48 +++++++++++++++----------------------
1 files changed, 19 insertions(+), 29 deletions(-)
diffs (105 lines):
diff -r 0a54ee648d92 -r c58c39288a5b usr.bin/xlint/lint2/check-msgs.lua
--- a/usr.bin/xlint/lint2/check-msgs.lua Fri Sep 10 20:33:38 2021 +0000
+++ b/usr.bin/xlint/lint2/check-msgs.lua Fri Sep 10 21:05:08 2021 +0000
@@ -1,5 +1,5 @@
#! /usr/bin/lua
--- $NetBSD: check-msgs.lua,v 1.1 2021/02/28 18:17:08 rillig Exp $
+-- $NetBSD: check-msgs.lua,v 1.2 2021/09/10 21:05:08 rillig Exp $
--[[
@@ -12,7 +12,7 @@
local function load_messages(fname)
- local msgs = {}
+ local msgs = {} ---@type table<number>string
local f = assert(io.open(fname, "r"))
for line in f:lines() do
@@ -28,11 +28,19 @@
end
-local function check_message(fname, lineno, id, comment, msgs, errors)
+local had_errors = false
+---@param fmt string
+function print_error(fmt, ...)
+ print(fmt:format(...))
+ had_errors = true
+end
+
+
+local function check_message(fname, lineno, id, comment, msgs)
local msg = msgs[id]
if msg == nil then
- errors:add("%s:%d: id=%d not found", fname, lineno, id)
+ print_error("%s:%d: id=%d not found", fname, lineno, id)
return
end
@@ -50,17 +58,12 @@
return
end
- errors:add("%s:%d: id=%-3d msg=%-40s comment=%s",
+ print_error("%s:%d: id=%-3d msg=%-40s comment=%s",
fname, lineno, id, msg, comment)
end
-local function collect_errors(fname, msgs)
- local errors = {}
- errors.add = function(self, fmt, ...)
- table.insert(self, fmt:format(...))
- end
-
+local function check_file(fname, msgs)
local f = assert(io.open(fname, "r"))
local lineno = 0
local prev = ""
@@ -72,9 +75,9 @@
if func == "msg" then
local comment = prev:match("^%s+/%* (.+) %*/$")
if comment ~= nil then
- check_message(fname, lineno, id, comment, msgs, errors)
+ check_message(fname, lineno, id, comment, msgs)
else
- errors:add("%s:%d: missing comment for %d: /* %s */",
+ print_error("%s:%d: missing comment for %d: /* %s */",
fname, lineno, id, msgs[id])
end
end
@@ -83,28 +86,15 @@
end
f:close()
-
- return errors
-end
-
-
-local function check_file(fname, msgs)
- local errors = collect_errors(fname, msgs)
- for _, err in ipairs(errors) do
- print(err)
- end
- return #errors == 0
end
local function main(arg)
local msgs = load_messages("msg.c")
- local ok = true
for _, fname in ipairs(arg) do
- ok = check_file(fname, msgs) and ok
+ check_file(fname, msgs)
end
- return ok
end
-
-os.exit(main(arg))
+main(arg)
+os.exit(not had_errors)
Home |
Main Index |
Thread Index |
Old Index