diff --git a/specs/execution-transcript/tools/check-corpus.sh b/specs/execution-transcript/tools/check-corpus.sh index 0997e39..fd8491d 100755 --- a/specs/execution-transcript/tools/check-corpus.sh +++ b/specs/execution-transcript/tools/check-corpus.sh @@ -43,9 +43,12 @@ for cx in flip drop attr; do fi done echo "TRN1_CORPUS_SELFTEST counterexamples=3 detected=3" -if ! diff -r "$vec" "$tmp/regen" >/dev/null; then +# Only the crumb tool's two exact file names are ignored (RFC-0001 drops +# .crumb / .crumb.local into directories); any other stray file still differs. +ignore="-x .crumb -x .crumb.local" +if ! diff -r $ignore "$vec" "$tmp/regen" >/dev/null; then echo "TRN1_CORPUS_STALE: vectors/ differs from make-corpus.sh output" >&2 - diff -rq "$vec" "$tmp/regen" >&2 || true + diff -rq $ignore "$vec" "$tmp/regen" >&2 || true exit 1 fi echo "TRN1_CORPUS_REGEN identical" diff --git a/specs/execution-transcript/tools/test-check-corpus.sh b/specs/execution-transcript/tools/test-check-corpus.sh new file mode 100755 index 0000000..bb62245 --- /dev/null +++ b/specs/execution-transcript/tools/test-check-corpus.sh @@ -0,0 +1,42 @@ +#!/bin/sh +# test-check-corpus.sh: prove check-corpus.sh ignores the crumb tool's files +# (.crumb, .crumb.local, exact names) and nothing else. +# Usage: test-check-corpus.sh [CC] Copies specs/execution-transcript to a temp dir. +set -eu +here=$(cd "$(dirname "$0")" && pwd) +CC=${1:-cc} +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +fails=0 + +fresh() { rm -rf "$tmp/et"; cp -R "$here/.." "$tmp/et"; rm -f "$tmp/et/vectors/.crumb" "$tmp/et/vectors/.crumb.local"; } +runcheck() { sh -c 'bash "$1/tools/check-corpus.sh" "$2"' x "$tmp/et" "$CC" >"$tmp/out" 2>&1; } +expect() { # name, want (0|nz), then runcheck result + if runcheck; then got=0; else got=nz; fi + if [ "$got" = "$2" ]; then echo "ok $1"; else echo "FAIL $1 (exit $got, wanted $2)"; tail -n 5 "$tmp/out"; fails=$((fails+1)); fi +} + +fresh +expect baseline 0 + +# (a) kills: removing the -x .crumb exclusion (check would exit 1 as STALE). +fresh; printf 'crumb\n' >"$tmp/et/vectors/.crumb" +expect crumb-ignored 0 +# (a2) kills: dropping only the .crumb.local exclusion. +fresh; printf 'local\n' >"$tmp/et/vectors/.crumb.local" +expect crumb-local-ignored 0 + +# (b) kills: widening the exclusion to a glob such as -x '.crumb*' or '*'. +fresh; printf 'x\n' >"$tmp/et/vectors/.crumbx" +expect near-name-still-fails nz +fresh; printf 'x\n' >"$tmp/et/vectors/stray.txt" +expect unknown-file-still-fails nz + +# (c) kills: neutering the vector comparison (e.g. ignoring everything). +fresh +f="$tmp/et/vectors/f001.trn" +b=$(od -An -N1 -tu1 "$f" | tr -d ' ') +printf "\\$(printf '%03o' $((b ^ 1)))" | dd of="$f" bs=1 seek=0 count=1 conv=notrunc 2>/dev/null +expect mutated-golden-still-fails nz + +[ "$fails" -eq 0 ] && echo "TEST_CHECK_CORPUS pass" || { echo "TEST_CHECK_CORPUS fail=$fails"; exit 1; }