diff options
Diffstat (limited to 'org/tests_for_document_abstraction_shell_scripts.org')
| -rw-r--r-- | org/tests_for_document_abstraction_shell_scripts.org | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/org/tests_for_document_abstraction_shell_scripts.org b/org/tests_for_document_abstraction_shell_scripts.org index f8563c7..b62f1da 100644 --- a/org/tests_for_document_abstraction_shell_scripts.org +++ b/org/tests_for_document_abstraction_shell_scripts.org @@ -438,3 +438,93 @@ else exit 1 fi #+END_SRC +* +** ssp document abstraction test/test-abstraction-ssp-roundtrip.sh + +#+HEADER: :tangle ../test/test-abstraction-ssp-roundtrip.sh +#+HEADER: :tangle-mode (identity #o755) +#+HEADER: :shebang "#!/usr/bin/env sh" +#+BEGIN_SRC shell +# test-abstraction-ssp-roundtrip.sh +# +# Reads each reference .ssp back into the abstraction and emits it again, +# and requires the result to be byte identical to the file it read. +# +# What that proves: the reader (sisudoc.ocda.abstraction.ssp_in) restores +# every field the writer emits. The check is made against the writer itself, +# since both go through template sspObjectRecord, so there is no second +# description of the format that could drift from the first. +# +# It needs no sample documents and no output directory: the committed +# reference set is the input. Run test-abstraction-ssp.sh first if you want +# to know that the reference set is itself current. +# +# Usage: +# ./test/test-abstraction-ssp-roundtrip.sh # uses result/bin/spine +# ./test/test-abstraction-ssp-roundtrip.sh ./bin/spine-ldc # specify binary +# +# Exit codes: +# 0 every reference .ssp round trips byte identically +# 1 one or more do not (the first differences are printed) +# 2 set-up problem (no binary, no reference set) + +set -e + +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +SPINE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" +REF_DIR="$SCRIPT_DIR/reference/abstraction" + +SPINE_BIN="${1:-}" +if [ -z "$SPINE_BIN" ]; then + if [ -x "$SPINE_DIR/result/bin/spine" ]; then SPINE_BIN="$SPINE_DIR/result/bin/spine" + elif [ -x "$SPINE_DIR/bin/spine-ldc" ]; then SPINE_BIN="$SPINE_DIR/bin/spine-ldc" + elif [ -x "$SPINE_DIR/bin/spine" ]; then SPINE_BIN="$SPINE_DIR/bin/spine" + else + echo "ERROR: spine binary not found. Specify path as argument." >&2 + exit 2 + fi +fi + +if [ ! -d "$REF_DIR" ] || [ -z "$(ls "$REF_DIR"/*.ssp 2>/dev/null)" ]; then + echo "ERROR: no reference files found at $REF_DIR" >&2 + echo "Run ./test/test-abstraction-ssp.sh --generate first." >&2 + exit 2 +fi + +TMP="$SCRIPT_DIR/current-roundtrip" +rm -rf "$TMP" +mkdir -p "$TMP" + +echo "spine binary: $SPINE_BIN" +echo "reference: $REF_DIR" +echo "Reading each .ssp back and emitting it again ..." + +COUNT=0 +FAILURES=0 +for ref in "$REF_DIR"/*.ssp; do + base=$(basename "$ref") + COUNT=$((COUNT + 1)) + if ! $SPINE_BIN --ssp-round-trip="$ref" > "$TMP/$base" 2> "$TMP/$base.err"; then + echo "ERROR: $base (spine exited non-zero)" + head -3 "$TMP/$base.err" + FAILURES=$((FAILURES + 1)) + continue + fi + if ! cmp -s "$ref" "$TMP/$base"; then + echo "DIFFERS: $base ($(diff "$ref" "$TMP/$base" | grep -c '^[<>]') lines)" + diff --unified=1 "$ref" "$TMP/$base" | head -12 + echo " ..." + FAILURES=$((FAILURES + 1)) + fi +done + +rm -rf "$TMP" + +if [ "$FAILURES" -eq 0 ]; then + echo "PASS: all $COUNT .ssp files read back and re-emit byte identically" + exit 0 +else + echo "FAIL: $FAILURES of $COUNT do not round trip" + exit 1 +fi +#+END_SRC |
