107 lines
4.2 KiB
Bash
Executable File
107 lines
4.2 KiB
Bash
Executable File
#!/bin/bash
|
|
# CHECK-q170 -- the import-order guard still answers its question.
|
|
#
|
|
# Legs
|
|
# selftest every fixture cell green (16 today), and the count pinned
|
|
# worktree every tracked *.py on disk binds its imports first, rc 0
|
|
# head the same reading at HEAD, rc 0
|
|
# red a synthetic tree carrying the three shapes Q170 repaired
|
|
# (module-level read, def called too early, both in one file)
|
|
# reads rc 1 and names each one -- the green control is not the
|
|
# only thing this guard can print
|
|
# runs the three files the repair touched still execute: rc 0 each
|
|
# wiring tools/verify.py names the leg and runs it at WORKTREE
|
|
#
|
|
# rc 0 every leg as expected | 1 a graded fault | 2 could not grade.
|
|
# Run from anywhere; paths resolve from $0, the repo from this file's place.
|
|
set -u
|
|
|
|
HERE="$(cd "$(dirname "$(readlink -f "$0")")" && pwd)"
|
|
REPO="$(cd "$HERE/../.." && pwd)"
|
|
TOOL="$HERE/q170_import_order_check.py"
|
|
CELLS="16 cells, 16 passed, 0 failed"
|
|
legs=0
|
|
faults=0
|
|
|
|
ok() { legs=$((legs + 1)); printf 'ok %-9s %s\n' "$1" "$2"; }
|
|
bad() { legs=$((legs + 1)); faults=$((faults + 1)); printf 'FAULT %-9s %s\n' "$1" "$2"; }
|
|
skip(){ legs=$((legs + 1)); printf 'skip %-9s %s\n' "$1" "$2"; }
|
|
|
|
[ -f "$TOOL" ] || { echo "cannot grade -- no tool: $TOOL"; exit 2; }
|
|
command -v python3 >/dev/null || { echo "cannot grade -- no python3"; exit 2; }
|
|
|
|
# selftest -- the fixture corpus, and the pin on its size
|
|
out="$(python3 "$TOOL" --selftest 2>&1)"; rc=$?
|
|
if [ $rc -eq 0 ] && printf '%s' "$out" | grep -qF "$CELLS"; then
|
|
ok selftest "$CELLS, rc 0"
|
|
else
|
|
bad selftest "rc $rc, want 0 and '$CELLS'; last: $(printf '%s' "$out" | tail -n 1)"
|
|
fi
|
|
|
|
# worktree -- the tree about to be committed
|
|
out="$(python3 "$TOOL" --repo "$REPO" 2>&1)"; rc=$?
|
|
line="$(printf '%s' "$out" | tail -n 1)"
|
|
if [ $rc -eq 0 ] && printf '%s' "$line" | grep -q ', 0 fault(s)$'; then
|
|
ok worktree "$line"
|
|
else
|
|
bad worktree "rc $rc: $line"
|
|
fi
|
|
|
|
# head -- the commit
|
|
out="$(python3 "$TOOL" --repo "$REPO" --rev HEAD 2>&1)"; rc=$?
|
|
line="$(printf '%s' "$out" | tail -n 1)"
|
|
if [ $rc -eq 0 ] && printf '%s' "$line" | grep -q ', 0 fault(s)$'; then
|
|
ok head "$line"
|
|
else
|
|
bad head "rc $rc: $line"
|
|
fi
|
|
|
|
# red -- the guard can still print red, on the three shapes it was opened for
|
|
red="$(mktemp -d "${TMPDIR:-/tmp}/q170-red.XXXXXX")"
|
|
mkdir -p "$red/wizard-work/beam"
|
|
printf 'import sys\n\n\ndef main():\n return Path(".")\n\n\nif __name__ == "__main__":\n sys.exit(main())\nfrom pathlib import Path\n' \
|
|
> "$red/wizard-work/beam/early_call.py"
|
|
printf 'REPO = Path(__file__).resolve()\nfrom pathlib import Path\n' \
|
|
> "$red/wizard-work/beam/module_level.py"
|
|
printf 'import os\nfrom pathlib import Path\n\nprint(Path(os.sep))\n' \
|
|
> "$red/wizard-work/beam/clean.py"
|
|
git -C "$red" init -q . 2>/dev/null
|
|
git -C "$red" add -A 2>/dev/null
|
|
out="$(python3 "$TOOL" --repo "$red" 2>&1)"; rc=$?
|
|
n="$(printf '%s\n' "$out" | grep -c '^FAULT ')"
|
|
if [ $rc -eq 1 ] && [ "$n" -ge 2 ] \
|
|
&& printf '%s' "$out" | grep -q 'early_call.py' \
|
|
&& printf '%s' "$out" | grep -q 'module_level.py' \
|
|
&& ! printf '%s' "$out" | grep -q 'clean.py'; then
|
|
ok red "rc 1, $n fault(s), both shapes named, the clean file silent"
|
|
else
|
|
bad red "rc $rc, want 1 with both shapes named and clean.py silent"
|
|
fi
|
|
rm -rf "$red"
|
|
|
|
# runs -- the property the guard exists for: these files EXECUTE
|
|
runs_ok=1
|
|
for f in wizard-work/beam/verify_wordcount_test.py \
|
|
wizard-work/spark/verify_wordcount_test.py \
|
|
wizard-work/ledger/verify_dates.py; do
|
|
if ! python3 "$REPO/$f" >/dev/null 2>&1; then
|
|
runs_ok=0
|
|
bad runs "python3 $f did not exit 0"
|
|
break
|
|
fi
|
|
done
|
|
[ $runs_ok -eq 1 ] && ok runs "the three repaired files exit 0"
|
|
|
|
# wiring -- the gate names the leg and runs it at the worktree
|
|
if grep -q '"import-order"' "$REPO/tools/verify.py" \
|
|
&& grep -q 'q170_import_order_check.py' "$REPO/tools/verify.py" \
|
|
&& grep -q '"--rev", "WORKTREE", "--quiet"' "$REPO/tools/verify.py"; then
|
|
ok wiring "tools/verify.py: leg import-order -> q170 at WORKTREE"
|
|
else
|
|
bad wiring "tools/verify.py no longer names the import-order leg at WORKTREE"
|
|
fi
|
|
|
|
echo "CHECK-q170: $legs leg(s), $faults fault(s)"
|
|
[ $faults -eq 0 ] || exit 1
|
|
exit 0
|