#!/usr/bin/env sh # test-run-order.sh # # A document's abstraction must not depend on what else is in the run. # # It did. The set of heading anchor names spine has seen is seeded with the # names it keeps for its own generated sections (toc, endnotes, glossary, # bibliography, bookindex, blurb, _the_title), and the seeding was written # only in scope(exit) and at the tail of docAbstraction(): both run *after* a # document, so they seeded the next one. The first document of a run began # with the set empty and was the one document not held to the reserved names, # and a heading of its own claiming "endnotes" kept the name of the generated # section rather than being renamed out of its way. # # So the same document abstracted alone and abstracted after another differed, # and an artefact written in a collection run could not be verified on its # own: --ocda-verify re-parses one document, where it is necessarily first, # and reported a correct artefact as one whose markup no longer makes it. # # The check: abstract two documents in one run, abstract each of them alone, # and require the .ssp to be identical either way. The second document is the # one that matters (it is seeded in the pair and not when alone), so the pair # is ordered with the affected document last. # # $SpineRunOrderDocs overrides the pair, space separated, unqualified # directory names within $SpinePOD. The default pair is chosen so that the # test would fail before the fix: the_autonomous_contract has a "1~endnotes" # heading, which is what the seeding renames. # # Usage: # SpinePOD=../../markup/sisudoc-spine-samples/markup/pod-samples/pod \ # ./test/test-run-order.sh ./bin/spine-ldc # # Exit codes: # 0 a document abstracts the same alone as in company # 1 it does not (the differing files are printed) # 2 set-up problem (no $SpinePOD, no binary, no samples) set -e SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" SPINE_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" if [ -z "$SpinePOD" ]; then echo "ERROR: \$SpinePOD is not set." >&2 echo " e.g. SpinePOD=../../markup/sisudoc-spine-samples/markup/pod-samples/pod" >&2 exit 2 fi SAMPLES_RAW="$SPINE_DIR/$SpinePOD" if [ -d "$SAMPLES_RAW" ]; then SAMPLES_DIR="$(cd "$SAMPLES_RAW" && pwd)" else SAMPLES_DIR="$SAMPLES_RAW" fi if [ ! -d "$SAMPLES_DIR" ]; then echo "ERROR: sample documents not found at $SAMPLES_DIR" >&2 exit 2 fi 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 DOCS="${SpineRunOrderDocs:-gpl2.fsf the_autonomous_contract.ralph_amissah}" for d in $DOCS; do if [ ! -d "$SAMPLES_DIR/$d" ]; then echo "ERROR: sample document not found: $SAMPLES_DIR/$d" >&2 echo " set \$SpineRunOrderDocs to a pair that is present" >&2 exit 2 fi done OUT_DIR="$SCRIPT_DIR/current-run-order" rm -rf "$OUT_DIR" mkdir -p "$OUT_DIR" echo "spine binary: $SPINE_BIN" echo "samples: $SAMPLES_DIR" echo "documents: $DOCS" FAILURES=0 fail() { echo " FAIL: $*"; FAILURES=$((FAILURES + 1)); } # the pair, in one run _pair_args="" for d in $DOCS; do _pair_args="$_pair_args $SAMPLES_DIR/$d" done # shellcheck disable=SC2086 $SPINE_BIN --show-abstraction --skip-output \ --output="$OUT_DIR/together" $_pair_args > "$OUT_DIR/together.out" 2>&1 # and each of them on its own for d in $DOCS; do $SPINE_BIN --show-abstraction --skip-output \ --output="$OUT_DIR/alone-$d" "$SAMPLES_DIR/$d" \ > "$OUT_DIR/alone-$d.out" 2>&1 done # every .ssp the pair run produced has to have a twin, identical, in the run # that produced it alone _compared=0 for f in $(find "$OUT_DIR/together" -name "*.ssp" | sort); do _rel="${f#"$OUT_DIR/together/"}" _alone="" for d in $DOCS; do if [ -f "$OUT_DIR/alone-$d/$_rel" ]; then _alone="$OUT_DIR/alone-$d/$_rel"; fi done if [ -z "$_alone" ]; then fail "$_rel was produced in the pair run and by neither document alone" continue fi _compared=$((_compared + 1)) if ! cmp -s "$f" "$_alone"; then fail "$_rel differs between the pair run and the run of its own document" diff --unified=2 "$_alone" "$f" | head -20 | sed 's/^/ /' fi done if [ "$_compared" -eq 0 ]; then echo "ERROR: no .ssp files were produced to compare" >&2 rm -rf "$OUT_DIR" exit 2 fi rm -rf "$OUT_DIR" if [ "$FAILURES" -eq 0 ]; then echo "PASS: $_compared .ssp identical whether the document ran alone or in company" exit 0 else echo "FAIL: $FAILURES check(s)" exit 1 fi