Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/usr.bin/xlint/lint1 tests/lint: automate accepting cha...
details: https://anonhg.NetBSD.org/src/rev/2a97ec867835
branches: trunk
changeset: 377345:2a97ec867835
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jul 08 10:01:17 2023 +0000
description:
tests/lint: automate accepting changed test results
diffstat:
tests/usr.bin/xlint/lint1/accept.sh | 14 ++++++-
tests/usr.bin/xlint/lint1/check-expect.lua | 56 ++++++++++++++++++++++++++---
2 files changed, 62 insertions(+), 8 deletions(-)
diffs (143 lines):
diff -r 393da1f95b2c -r 2a97ec867835 tests/usr.bin/xlint/lint1/accept.sh
--- a/tests/usr.bin/xlint/lint1/accept.sh Sat Jul 08 09:35:35 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/accept.sh Sat Jul 08 10:01:17 2023 +0000
@@ -1,5 +1,5 @@
#! /bin/sh
-# $NetBSD: accept.sh,v 1.13 2023/07/08 08:02:45 rillig Exp $
+# $NetBSD: accept.sh,v 1.14 2023/07/08 10:01:17 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -37,6 +37,16 @@ set -eu
: "${archsubdir:=$(make -v ARCHSUBDIR)}"
. './t_integration.sh' # for configure_test_case
+update_flags=''
+while getopts 'u' opt; do
+ case $opt in
+ u) update_flags='-u';;
+ *) echo "usage: $0 [-u] pattern..." 1>&2
+ exit 1;;
+ esac
+done
+shift $((OPTIND - 1))
+
done_tests=''
for pattern in "$@"; do
# shellcheck disable=SC2231
@@ -115,4 +125,4 @@ for pattern in "$@"; do
done
# shellcheck disable=SC2086
-lua './check-expect.lua' $done_tests
+lua './check-expect.lua' $update_flags $done_tests
diff -r 393da1f95b2c -r 2a97ec867835 tests/usr.bin/xlint/lint1/check-expect.lua
--- a/tests/usr.bin/xlint/lint1/check-expect.lua Sat Jul 08 09:35:35 2023 +0000
+++ b/tests/usr.bin/xlint/lint1/check-expect.lua Sat Jul 08 10:01:17 2023 +0000
@@ -1,5 +1,5 @@
#! /usr/bin/lua
--- $NetBSD: check-expect.lua,v 1.5 2023/07/06 07:33:36 rillig Exp $
+-- $NetBSD: check-expect.lua,v 1.6 2023/07/08 10:01:17 rillig Exp $
--[[
@@ -49,6 +49,15 @@ local function load_lines(fname)
end
+local function save_lines(fname, lines)
+ local f = io.open(fname, "w")
+ for _, line in ipairs(lines) do
+ f:write(line .. "\n")
+ end
+ f:close()
+end
+
+
-- Load the 'expect:' comments from a C source file.
--
-- example return values:
@@ -136,9 +145,6 @@ local function load_exp(exp_fname)
end
----@param comment string
----@param pattern string
----@return boolean
local function matches(comment, pattern)
if comment == "" then return false end
@@ -182,13 +188,32 @@ test(function()
end)
-local function check_test(c_fname)
+-- Inserts the '/* expect */' lines to the .c file, so that the .c file matches
+-- the .exp file. Multiple 'expect' comments for a single line of code are not
+-- handled correctly, but it's still better than doing the same work manually.
+local function insert_missing(missing)
+ for fname, items in pairs(missing) do
+ table.sort(items, function(a, b) return a.lineno > b.lineno end)
+ local lines = load_lines(fname)
+ for _, item in ipairs(items) do
+ local lineno, message = item.lineno, item.message
+ local indent = (lines[lineno] or ""):match("^([ \t]*)")
+ local line = ("%s/* expect+1: %s */"):format(indent, message)
+ table.insert(lines, lineno, line)
+ end
+ save_lines(fname, lines)
+ end
+end
+
+
+local function check_test(c_fname, update)
local exp_fname = c_fname:gsub("%.c$", ".exp"):gsub(".+/", "")
local c_comment_locations, c_comments_by_location = load_c(c_fname)
if c_comment_locations == nil then return end
local exp_messages = load_exp(exp_fname) or {}
+ local missing = {}
for _, exp_message in ipairs(exp_messages) do
local c_comments = c_comments_by_location[exp_message.location] or {}
@@ -207,6 +232,16 @@ local function check_test(c_fname)
if not found then
print_error("error: %s: missing /* expect+1: %s */",
exp_message.location, expected_message)
+
+ if update then
+ local fname = exp_message.location:match("^([^(]+)")
+ local lineno = tonumber(exp_message.location:match("%((%d+)%)$"))
+ if not missing[fname] then missing[fname] = {} end
+ table.insert(missing[fname], {
+ lineno = lineno,
+ message = expected_message,
+ })
+ end
end
end
@@ -219,12 +254,21 @@ local function check_test(c_fname)
end
end
end
+
+ if missing then
+ insert_missing(missing)
+ end
end
local function main(args)
+ local update = args[1] == "-u"
+ if update then
+ table.remove(args, 1)
+ end
+
for _, name in ipairs(args) do
- check_test(name)
+ check_test(name, update)
end
end
Home |
Main Index |
Thread Index |
Old Index