aboutsummaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools')
-rwxr-xr-xsrc/tools/xref_selftest.sh21
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