ssh git@grit.deadkey.org man

mailmanpat/jenny · 2026-09-06 09:36:46 +08002026-9-6 +8git clone …

FILES / test / compare-golden.sh

NameLast CommitTimestampSize
..
fixtures ad9c389 h test: replace the cloned-blog CI job with a committed fixture 26-08-24 11:38 -
lib 41cf051 h fix(index): restore the original break-marker placement and dimming 26-08-24 22:33 -
compare-golden.sh ad9c389 h test: replace the cloned-blog CI job with a committed fixture 26-08-24 11:38 1 KB
regressions.sh b70d686 h Take the parser's escape-by-default contract 26-09-05 10:21 123 KB
run.sh a346b6b h test: add bash test harness, fixtures and link checker 26-08-20 09:30 392 B
smoke.sh a346b6b h test: add bash test harness, fixtures and link checker 26-08-20 09:30 2 KB
units.sh b70d686 h Take the parser's escape-by-default contract 26-09-05 10:21 20 KB
#!/usr/bin/env bash
# Byte-for-byte comparison of a rebuild against a snapshotted golden build.
#
# Used to prove a refactor changed no output: snapshot a build, refactor, then
# rebuild and diff. Not part of test/run.sh, because the snapshot is a local
# artifact rather than something worth committing.
#
# cp -r blog/.dist /tmp/golden # before
# ...refactor...
# test/compare-golden.sh /tmp/golden blog
#
# usage: compare-golden.sh <golden-dist> <blog-src> [jenny]
set -uo pipefail
golden=${1:?usage: compare-golden.sh <golden-dist> <blog-src> [jenny]}
src=${2:?usage: compare-golden.sh <golden-dist> <blog-src> [jenny]}
jenny=${3:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/bin/jenny}
share=$(cd "$(dirname "$jenny")/../share/jenny" && pwd)
work=$(mktemp -d -t jenny-compare.XXXXXX)
trap 'rm -rf "$work"' EXIT
cp -r "$src" "$work/blog"
rm -rf "$work/blog/.dist" "$work/blog/.bloglock"
if ! ( cd "$work/blog" && JENNY_SHARE_DIR="$share" "$jenny" >"$work/build.log" 2>"$work/build.err" ); then
echo "REBUILD FAILED"
cat "$work/build.err"
exit 1
fi
if [ -s "$work/build.err" ]; then
echo "REBUILD WROTE TO STDERR:"
cat "$work/build.err"
exit 1
fi
# lastBuildDate legitimately differs between runs; normalise it away.
normalise() {
find "$1" -type f \( -name '*.html' -o -name '*.xml' \) -print0 \
| sort -z \
| while IFS= read -r -d '' f; do
printf '=== %s\n' "${f#"$1"/}"
sed -E 's#<lastBuildDate>[^<]*</lastBuildDate>#<lastBuildDate>NORMALISED</lastBuildDate>#' "$f"
done
}
normalise "$golden" > "$work/a.txt"
normalise "$work/blog/.dist" > "$work/b.txt"
if diff -q "$work/a.txt" "$work/b.txt" >/dev/null; then
files=$(find "$golden" -type f \( -name '*.html' -o -name '*.xml' \) | wc -l | tr -d ' ')
echo "IDENTICAL ($files rendered files match byte for byte)"
exit 0
fi
echo "OUTPUT DIFFERS:"
diff -u "$work/a.txt" "$work/b.txt" | head -60
exit 1