diff options
| author | 2026-10-14 15:41:56 +0330 | |
|---|---|---|
| committer | 2026-10-14 15:41:56 +0330 | |
| commit | 1660c16f4f296dee8c1efc972d4671208ed05a8d (patch) | |
| tree | 02d2470d7996f074475ccd553d1cbf471527b684 /src/tools/xref_selftest.sh | |
| parent | agent/xref-report: unmerged work from previous session (diff) | |
xref: checked-in baseline, --check self-test hooked into the lsp section, todo
Diffstat (limited to 'src/tools/xref_selftest.sh')
| -rwxr-xr-x | src/tools/xref_selftest.sh | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/tools/xref_selftest.sh b/src/tools/xref_selftest.sh new file mode 100755 index 0000000..36425e4 --- /dev/null +++ b/src/tools/xref_selftest.sh @@ -0,0 +1,21 @@ +#!/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. +# 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 +server=${1:-build/bin/zclsp} +tmp=$(mktemp -d); trap 'rm -rf "$tmp"' EXIT +fail=0 +bash src/tools/xref.sh --server "$server" --out "$tmp/out" --check > "$tmp/ok.log" 2>&1; r=$? +if [ $r = 0 ]; then echo "ok xref --check passes against tests/xref.baseline" +else echo "FAIL xref --check against tests/xref.baseline: exit $r"; cat "$tmp/ok.log"; fail=1; fi +# drop the last writer of the first global that has one: --check must report it as a new writer +line=$(awk 'NF>=2{print NR; exit}' tests/xref.baseline) +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 +exit $fail |
