aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/test-ocn-alignment.sh
diff options
context:
space:
mode:
Diffstat (limited to 'test/test-ocn-alignment.sh')
-rwxr-xr-xtest/test-ocn-alignment.sh155
1 files changed, 155 insertions, 0 deletions
diff --git a/test/test-ocn-alignment.sh b/test/test-ocn-alignment.sh
new file mode 100755
index 0000000..f00a8ec
--- /dev/null
+++ b/test/test-ocn-alignment.sh
@@ -0,0 +1,155 @@
+#!/usr/bin/env sh
+# test-ocn-alignment.sh
+#
+# The languages of a document share their object numbering, and spine warns
+# when they stop doing so. This checks that the warning appears where it
+# should and, just as importantly, nowhere else.
+#
+# The sample set is the fixture, and it is a good one because it contains
+# both answers:
+#
+# live-manual ten languages, two of which diverge.
+# ja has two fewer numbered objects than en. A missing
+# translation of a short paragraph; everything below it
+# is renumbered.
+# pl has the same count, but the object at ocn 313 is a
+# paragraph in en and a heading in pl. A heading given as
+# running text, or running text given as a heading.
+# everything else single language, or aligned. Silent.
+#
+# A check that only ever fires is as useless as one that never does, so the
+# silence over the other documents is asserted too.
+#
+# It also asserts that --strict turns the warning into a non-zero exit, and
+# that without --strict the run still succeeds: a document with a diverging
+# translation is still a document.
+#
+# Usage:
+# SpinePOD=../../markup/sisudoc-spine-samples/markup/pod-samples/pod \
+# ./test/test-ocn-alignment.sh ./bin/spine-ldc
+#
+# Exit codes:
+# 0 the check reports what it should, and nothing else
+# 1 it does not (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
+
+OUT_DIR="$SCRIPT_DIR/current-ocn-alignment"
+rm -rf "$OUT_DIR"
+mkdir -p "$OUT_DIR"
+
+echo "spine binary: $SPINE_BIN"
+echo "samples: $SAMPLES_DIR"
+
+FAILURES=0
+fail() { echo " FAIL: $*"; FAILURES=$((FAILURES + 1)); }
+
+# the whole sample set, abstraction only: the check does not need outputs
+echo "Abstracting the sample set ..."
+set +e
+$SPINE_BIN --show-abstraction --skip-output \
+ --output="$OUT_DIR" "$SAMPLES_DIR"/* \
+ > "$OUT_DIR/run.out" 2> "$OUT_DIR/run.err"
+RUN_RC=$?
+set -e
+
+# without --strict a diverging document is still built
+if [ "$RUN_RC" -ne 0 ]; then
+ fail "the run exited $RUN_RC without --strict; a warning must not fail a run"
+ head -5 "$OUT_DIR/run.err"
+fi
+
+# what it said
+if ! grep -q "^WARNING ocn alignment: live-manual$" "$OUT_DIR/run.err"; then
+ fail "no ocn alignment warning for live-manual"
+fi
+if ! grep -q "^ \[ja\] differs from \[en\]$" "$OUT_DIR/run.err"; then
+ fail "ja not reported as differing from en"
+fi
+if ! grep -q "numbered objects: en 1019, ja 1017 (-2)" "$OUT_DIR/run.err"; then
+ fail "ja's object count difference not reported as -2"
+fi
+if ! grep -q "^ \[pl\] differs from \[en\]$" "$OUT_DIR/run.err"; then
+ fail "pl not reported as differing from en"
+fi
+if ! grep -q "ocn 313: para in en, heading:2 in pl" "$OUT_DIR/run.err"; then
+ fail "pl's substituted heading at ocn 313 not reported"
+fi
+
+# and what it did not say: exactly one document warned about, exactly two
+# languages of it
+n_docs=$(grep -c "^WARNING ocn alignment: " "$OUT_DIR/run.err" || true)
+if [ "$n_docs" != "1" ]; then
+ fail "$n_docs documents warned about, expected 1"
+ grep "^WARNING ocn alignment: " "$OUT_DIR/run.err" | sed 's/^/ /'
+fi
+n_langs=$(grep -c "^ \[.*\] differs from " "$OUT_DIR/run.err" || true)
+if [ "$n_langs" != "2" ]; then
+ fail "$n_langs languages reported, expected 2 (ja and pl)"
+ grep "^ \[.*\] differs from " "$OUT_DIR/run.err" | sed 's/^/ /'
+fi
+
+# --strict makes the same run fail
+set +e
+$SPINE_BIN --show-abstraction --skip-output --strict \
+ --output="$OUT_DIR/strict" "$SAMPLES_DIR"/live-manual \
+ > "$OUT_DIR/strict.out" 2> "$OUT_DIR/strict.err"
+STRICT_RC=$?
+set -e
+if [ "$STRICT_RC" -eq 0 ]; then
+ fail "--strict exited 0 on a document whose languages diverge"
+fi
+
+# and does not fail a document whose languages agree, or one that has only
+# the one language
+set +e
+$SPINE_BIN --show-abstraction --skip-output --strict \
+ --output="$OUT_DIR/strict-ok" "$SAMPLES_DIR"/the_wealth_of_networks.yochai_benkler \
+ > "$OUT_DIR/strict-ok.out" 2> "$OUT_DIR/strict-ok.err"
+STRICT_OK_RC=$?
+set -e
+if [ "$STRICT_OK_RC" -ne 0 ]; then
+ fail "--strict exited $STRICT_OK_RC on a single language document"
+ head -5 "$OUT_DIR/strict-ok.err"
+fi
+
+rm -rf "$OUT_DIR"
+
+if [ "$FAILURES" -eq 0 ]; then
+ echo "PASS: ja and pl reported on live-manual, silent elsewhere, --strict fails"
+ exit 0
+else
+ echo "FAIL: $FAILURES check(s)"
+ exit 1
+fi