aboutsummaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2026-09-07 22:59:06 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2026-09-09 17:47:54 -0400
commit3ebec9563c035de976a7d57974f94be2d8bef83e (patch)
tree22d973da98ae5f7367c17e4f4062ad380accdbbf /test
parentrun abstraction test re-generate reference .ssp (diff)
test: .ssp round trip script beside the other two
Reads each committed reference .ssp back into the abstraction, emits it again, and requires byte identity. Both directions go through template sspObjectRecord, the writer's own definition of a record, so what is being checked is the reader against the writer and not against a second description of the format. ./test/test-abstraction-ssp-roundtrip.sh ./bin/spine-ldc PASS: all 35 .ssp files read back and re-emit byte identically It needs no sample documents and no output directory; the reference set is the input. So the three tests now say three different things: test-abstraction-ssp.sh the abstraction has not changed test-abstraction-db.sh the two serialisations agree test-abstraction-ssp-roundtrip.sh the .ssp can be read back whole Added with -f, as test/ is covered by .gitignore's catch-all. (assisted by Claude-Code)
Diffstat (limited to 'test')
-rwxr-xr-xtest/test-abstraction-ssp-roundtrip.sh83
1 files changed, 83 insertions, 0 deletions
diff --git a/test/test-abstraction-ssp-roundtrip.sh b/test/test-abstraction-ssp-roundtrip.sh
new file mode 100755
index 0000000..edc45d7
--- /dev/null
+++ b/test/test-abstraction-ssp-roundtrip.sh
@@ -0,0 +1,83 @@
+#!/usr/bin/env sh
+# 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