1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
#!/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
|