From 10e8a339b198b6e49e393c457cba7667a2a39ca5 Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 15:43:59 +0330 Subject: xref self-test: a real write in a compiler copy, reject unknown options; runerr.sh runs every folder it is given --- src/tools/xref_selftest.sh | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/tools') diff --git a/src/tools/xref_selftest.sh b/src/tools/xref_selftest.sh index 36425e4..e8a888b 100755 --- a/src/tools/xref_selftest.sh +++ b/src/tools/xref_selftest.sh @@ -1,11 +1,17 @@ #!/bin/bash -# self-test of src/tools/xref.sh --check: the checked-in baseline passes (exit 0), and a copy of it -# with one writer removed from one line fails (exit 1). works in a scratch directory; the tree, -# tests/xref.baseline and build/xref are not touched. +# self-test of src/tools/xref.sh --check: the checked-in baseline passes (exit 0); a copy of it +# with one writer removed from one line fails (exit 1); and a scratch copy of src/compiler with one +# new write to a global (namecount) fails and names that global. works in a scratch directory; the +# tree, src/compiler, tests/xref.baseline and build/xref are not touched. # usage: src/tools/xref_selftest.sh [SERVER] (default build/bin/zclsp) set -u cd "$(dirname "$0")/../.." -case "${1:-}" in -h|--help) echo "usage: src/tools/xref_selftest.sh [SERVER]"; exit 0;; esac +usage="usage: src/tools/xref_selftest.sh [SERVER] (default build/bin/zclsp)" +case "${1:-}" in + -h|--help) echo "$usage"; exit 0;; + -*) echo "xref_selftest: unknown option $1; $usage" >&2; exit 2;; +esac +[ $# -le 1 ] || { echo "xref_selftest: too many arguments; $usage" >&2; exit 2; } server=${1:-build/bin/zclsp} tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT fail=0 @@ -18,4 +24,12 @@ sed "${line}s/ [^ ]*\$//" tests/xref.baseline > "$tmp/baseline" bash src/tools/xref.sh --server "$server" --out "$tmp/out" --baseline "$tmp/baseline" --check > "$tmp/bad.log" 2>&1; r=$? if [ $r = 1 ] && grep -q 'is now written by' "$tmp/bad.log"; then echo "ok xref --check fails when the baseline misses a writer" else echo "FAIL xref --check with a writer removed from the baseline: exit $r (want 1)"; cat "$tmp/bad.log"; fail=1; fi +# a real new write in a copy of the compiler: a new function that assigns namecount +g=namecount +mkdir "$tmp/compiler"; cp src/compiler/* "$tmp/compiler/" +last=$(tr -d '\r' < "$tmp/compiler/parts" | tail -1) +printf '\nint xref_selftest_probe() { %s = %s + 1; return 0; }\n' "$g" "$g" >> "$tmp/compiler/$last" +bash src/tools/xref.sh --server "$server" --out "$tmp/out" --compiler-dir "$tmp/compiler" --check > "$tmp/src.log" 2>&1; r=$? +if [ $r = 1 ] && grep -q "^ $g is now written by xref_selftest_probe" "$tmp/src.log"; then echo "ok xref --check fails and names $g when a copy of the compiler writes it in a new function" +else echo "FAIL xref --check with a new write to $g in a copy of the compiler: exit $r (want 1 naming $g)"; cat "$tmp/src.log"; fail=1; fi exit $fail -- cgit v1.2.3