diff options
| author | rillig <rillig@NetBSD.org> | 2023-07-08 10:01:17 +0000 |
|---|---|---|
| committer | rillig <rillig@NetBSD.org> | 2023-07-08 10:01:17 +0000 |
| commit | a9f17a43da0092b6d63ec84550b87ef67c7ecef3 (patch) | |
| tree | 9c23ebcfcf504a6c29fb9c79a66a9a88e27809de /tests/usr.bin | |
| parent | cfcdde557958fc701848686dd4db2d8611322218 (diff) | |
tests/lint: automate accepting changed test results
Diffstat (limited to 'tests/usr.bin')
| -rw-r--r-- | tests/usr.bin/xlint/lint1/accept.sh | 14 | ||||
| -rw-r--r-- | tests/usr.bin/xlint/lint1/check-expect.lua | 56 |
2 files changed, 62 insertions, 8 deletions
diff --git a/tests/usr.bin/xlint/lint1/accept.sh b/tests/usr.bin/xlint/lint1/accept.sh index 659e0dd8458..4a2a752a9fc 100644 --- a/tests/usr.bin/xlint/lint1/accept.sh +++ b/tests/usr.bin/xlint/lint1/accept.sh @@ -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 --git a/tests/usr.bin/xlint/lint1/check-expect.lua b/tests/usr.bin/xlint/lint1/check-expect.lua index 3ece1989542..3a9a7b3b68d 100644 --- a/tests/usr.bin/xlint/lint1/check-expect.lua +++ b/tests/usr.bin/xlint/lint1/check-expect.lua @@ -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 |
