Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tools/gate/selftest.sh

18.9 KiB, 1 run, executable

created by r1870400018:66268, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1#!/usr/bin/env bash
2# Proves the O1 tools on synthetic projects, and proves each proof can fail.
3#
4# selftest.sh <typst-vendor> <scratch>
5#
6# <typst-vendor> is Daimond's `www/vendor/typst`; <scratch> is a directory this script makes a child of and
7# removes on exit. Everything here is synthetic: no path to a real project is taken or needed.
8#
9# It checks, in order:
10# 1. gather.mjs on a project of three .typ files, a csv, an image and a supplied font, with --exclude;
11# 2. g_checks.py: identical PDFs agree; a pair that differs on page 2 goes red on page 2; a middle-token
12# change moves the similarity but no hash; and a copy with the plant, page i compared with page i+1,
13# is blind to the pair that differs, so the check on it goes red;
14# 3. skew.sh end to end: a project that agrees reports `same` on the row that shares fonts; a project
15# whose page 4 prints the compiler's minor version reports `differs` on page 4 in both rows; a project
16# that does not compile prints a closed vocabulary and none of its own text.
17set -u
18
19HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
20CRATE="$(cd "$HERE/../.." && pwd)"
21# shellcheck source=gate_lib.sh
22. "$HERE/gate_lib.sh"
23
24V="${1:?usage: selftest.sh <typst-vendor> <scratch>}"
25PARENT="${2:?usage: selftest.sh <typst-vendor> <scratch>}"
26TYPST="${SKEW_TYPST:-/home/jason/bin/typst}"
27mkdir -p "$PARENT" || exit 2
28S="$(mktemp -d "$PARENT/o1.XXXXXX")" || exit 2
29trap 'rm -rf "${S:?}"' EXIT
30GATE_SCRATCH="$S"
31
32bad=0
33ok() { echo "selftest: ok $1"; }
34fail() { echo "selftest: FAIL $1"; bad=$((bad + 1)); }
35expect() { # expect <label> <text> <fixed line the text must contain>
36 if printf '%s\n' "$2" | grep -qxF -- "$3"; then ok "$1"; else fail "$1 (wanted: $3)"; fi
37}
38lack() { # lack <label> <text> <fixed string the text must not contain>
39 if printf '%s\n' "$2" | grep -qF -- "$3"; then fail "$1 (found: $3)"; else ok "$1"; fi
40}
41
42# ── the synthetic projects ──────────────────────────────────────────────────
43mkproj() { # mkproj <dir> [extra page text]
44 local p="$1"
45 mkdir -p "$p/chap" "$p/img" "$p/data" "$p/assets/fonts" "$p/skip"
46 cp "$CRATE/fonts/LibertinusMono-Regular.otf" "$p/assets/fonts/"
47 python3 - "$p/img/mark.png" <<'PY'
48import sys
49from PIL import Image
50Image.new('RGB', (8, 8), (200, 40, 40)).save(sys.argv[1])
51PY
52 printf 'a,1\nb,2\n' > "$p/data/rows.csv"
53 printf 'junk that --exclude must leave out\n' > "$p/skip/note.txt"
54 printf '#let one = [One: some words on the first page.]\n' > "$p/chap/one.typ"
55 printf '#let two = [Two: #csv("../data/rows.csv").map(r => r.join("-")).join(" ")]\n' > "$p/chap/two.typ"
56 cat > "$p/main.typ" <<'TYP'
57#set page(width: 200pt, height: 120pt, margin: 12pt)
58#set text(size: 10pt)
59#import "chap/one.typ": one
60#import "chap/two.typ": two
61= Synthetic
62#image("img/mark.png", width: 24pt)
63#text(font: "Libertinus Mono")[mono face]
64#one
65#pagebreak()
66#two
67#pagebreak()
68Third page.
69TYP
70 if [ -n "${2:-}" ]; then
71 printf '#pagebreak()\n%s\n' "$2" >> "$p/main.typ"
72 fi
73}
74mkproj "$S/proj"
75mkproj "$S/skewed" 'Compiler minor #sys.version.at(1).'
76mkdir -p "$S/broken"
77printf 'Text #ZZLEAKMARKERZZ more.\n' > "$S/broken/main.typ"
78
79# Synthetic packages. `tpk` is Typst's own layout, which typst 0.15.1 reads through TYPST_PACKAGE_PATH; `pk`
80# is what the typst.ts side is given: one package as a directory and two as Daimond's packs. zzpkg imports
81# zzdep, by a registry import and by a package-root path, so the closure and both re-pointings are used.
82pkgfile() { # pkgfile <relative path> <text>
83 mkdir -p "$(dirname "$S/tpk/$1")"
84 printf '%s\n' "$2" > "$S/tpk/$1"
85}
86pkgfile preview/zzpkg/0.1.0/typst.toml $'[package]\nname = "zzpkg"\nversion = "0.1.0"\nentrypoint = "lib.typ"'
87pkgfile preview/zzpkg/0.1.0/lib.typ $'#import "@preview/zzdep:0.3.0": dep\n#import "/helper.typ": help\n#let zz(x) = [zz(#x) #dep() #help()]'
88pkgfile preview/zzpkg/0.1.0/helper.typ '#let help() = [helper]'
89pkgfile preview/zzdep/0.3.0/typst.toml $'[package]\nname = "zzdep"\nversion = "0.3.0"\nentrypoint = "lib.typ"'
90pkgfile preview/zzdep/0.3.0/lib.typ '#let dep() = [dependency]'
91pkgfile preview/zzpack/0.2.0/typst.toml $'[package]\nname = "zzpack"\nversion = "0.2.0"\nentrypoint = "src/lib.typ"'
92pkgfile preview/zzpack/0.2.0/src/lib.typ '#let pk() = [packed]'
93pkgfile preview/zzpack/0.2.0/LICENSE 'Synthetic.'
94mkdir -p "$S/pk/preview/zzpkg" "$S/pk/preview/zzdep" "$S/pk/preview/zzpack"
95cp -r "$S/tpk/preview/zzpkg/0.1.0" "$S/pk/preview/zzpkg/0.1.0"
96mkpack() { # mkpack <ns> <name> <version> <out dir>: Daimond's refresh.sh format, from the tpk directory
97 python3 - "$S/tpk/$1/$2/$3" "$1" "$2" "$3" "$4/$1/$2/$3.pack" <<'PY'
98import os, re, sys
99src, ns, name, ver, out = sys.argv[1:]
100files = []
101for dp, _, fs in os.walk(src):
102 for f in fs:
103 rel = os.path.relpath(os.path.join(dp, f), src)
104 if f.endswith('.typ') or f == 'typst.toml' or f == 'LICENSE' or f.startswith('LICENSE.'):
105 files.append(rel)
106files.sort()
107entry = re.search(r'^\s*entrypoint\s*=\s*"(.*)"', open(os.path.join(src, 'typst.toml')).read(), re.M).group(1)
108head = 'DAIMOND TYPST PACK 1\nnamespace %s\nname %s\nversion %s\nentrypoint %s\n' % (ns, name, ver, entry)
109body = b''
110for f in files:
111 data = open(os.path.join(src, f), 'rb').read()
112 head += 'file %d %s\n' % (len(data), f)
113 body += data
114os.makedirs(os.path.dirname(out), exist_ok=True)
115open(out, 'wb').write(head.encode() + b'\n' + body)
116PY
117}
118mkpack preview zzdep 0.3.0 "$S/pk"
119mkpack preview zzpack 0.2.0 "$S/pk"
120mkproj "$S/pkgproj"
121cat >> "$S/pkgproj/main.typ" <<'TYP'
122#pagebreak()
123#import "@preview/zzpkg:0.1.0": zz
124#import "@preview/zzpack:0.2.0": pk
125#zz([a]) #pk()
126Quoted, not imported: `#import "@preview/zzghost:1.0.0"` and the string below.
127#let s = "@preview/zzghost2:1.0.0"
128TYP
129
130# ── 1. gather ───────────────────────────────────────────────────────────────
131g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/proj" main.typ --exclude skip 2>&1)"
132echo "$g" | grep -q '^gather: sources 4 assets 1 fonts 1 packages 0 missing 0 bytes [0-9]*$' \
133 && ok "gather: 3 .typ + csv as sources, the image as an asset, the font as a font, --exclude honoured" \
134 || fail "gather counts: $g"
135g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/proj" main.typ 2>&1)"
136echo "$g" | grep -q '^gather: sources 5 assets 1 fonts 1 packages 0 missing 0 bytes [0-9]*$' \
137 && ok "gather: without --exclude the skipped file is gathered" || fail "gather without exclude: $g"
138mkdir -p "$S/pkg"
139printf '#import "@preview/zzz:0.0.1": f\n' > "$S/pkg/main.typ"
140g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkg" main.typ 2>&1)"
141echo "$g" | grep -q '^gather: sources 1 assets 0 fonts 0 packages 1 missing 1 bytes [0-9]*$' \
142 && ok "gather: a package import with no package directory is a spec found and missing" \
143 || fail "gather packages: $g"
144# Links: a directory reached by two names is gathered under both, a link back up the tree is not followed
145# for ever, and a link that points nowhere is passed over.
146mkdir -p "$S/links/a"
147printf '#set page(width: 100pt)\n' > "$S/links/main.typ"
148printf 'x\n' > "$S/links/a/x.txt"
149ln -s a "$S/links/b"
150ln -s . "$S/links/up"
151ln -s nowhere "$S/links/dead"
152g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/links" main.typ 2>&1)"
153echo "$g" | grep -q '^gather: sources 3 assets 0 fonts 0 packages 0 missing 0 bytes [0-9]*$' \
154 && ok "gather: a directory under two names counts under both; a link back up and a dangling link do no harm" \
155 || fail "gather links: $g"
156g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --exclude skip --packages "$S/pk" 2>&1)"
157echo "$g" | grep -q '^gather: sources 4 assets 1 fonts 1 packages 3 missing 0 bytes [0-9]*$' \
158 && ok "gather: the closure finds 3 packages (a directory, two packs, one a dependency); a quoted import and a string are not imports" \
159 || fail "gather package closure: $g"
160g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --exclude skip 2>&1)"
161echo "$g" | grep -q '^gather: sources 4 assets 1 fonts 1 packages 2 missing 2 bytes [0-9]*$' \
162 && ok "gather: with no package directory the 2 imported specs are missing" || fail "gather no packages: $g"
163cp -r "$S/pk" "$S/pk_nodep" && rm -rf "${S:?}/pk_nodep/preview/zzdep"
164g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --exclude skip --packages "$S/pk_nodep" 2>&1)"
165echo "$g" | grep -q '^gather: sources 4 assets 1 fonts 1 packages 3 missing 1 bytes [0-9]*$' \
166 && ok "gather: a dependency that the directory lacks is missing, the rest supplied" || fail "gather missing dependency: $g"
167cp -r "$S/pk" "$S/pk_bad" && head -c 100 "$S/pk/preview/zzpack/0.2.0.pack" > "$S/pk_bad/preview/zzpack/0.2.0.pack"
168g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --exclude skip --packages "$S/pk_bad" 2>&1)"
169expect "gather: a truncated pack is refused with a closed code" "$g" "gather: error bad-package"
170g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --packages "$S/nowhere" 2>&1)"
171expect "gather: a package directory that does not exist is refused" "$g" "gather: error no-packages"
172g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/proj" nothing.typ 2>&1)"
173expect "gather: a missing main is refused with a closed code" "$g" "gather: error no-main"
174
175# ── 2. g_checks ─────────────────────────────────────────────────────────────
176mkpdf() { # mkpdf <name> <page text>... : one page per argument
177 local name="$1"
178 shift
179 {
180 printf '#set page(width: 200pt, height: 80pt, margin: 10pt)\n'
181 local first=1 t
182 for t in "$@"; do
183 [ $first -eq 1 ] || printf '#pagebreak()\n'
184 first=0
185 printf '%s\n' "$t"
186 done
187 } > "$S/$name.typ"
188 gate_typst "$TYPST" compile "$S/$name.typ" "$S/$name.pdf" > /dev/null 2>&1
189}
190P1="Alpha one two three"
191P2="Beta four five six"
192P2x="Beta four 5 six"
193mkpdf A "$P1" "$P2" "$P2"
194mkpdf B "$P1" "$P1" "$P2"
195mkpdf C "$P1" "$P2x" "$P2"
196mkpdf D "$P1" "Beta four five seven" "$P2"
197mkpdf E "$P1" "Gamma four five six" "$P2"
198G="$HERE/g_checks.py"
199r="$(python3 "$G" compare "$S/A.pdf" "$S/A.pdf")"
200expect "g_checks: a PDF agrees with itself" "$r" "g3 verdict same"
201expect "g_checks: no page differs" "$r" "g3 differ 0 pages none"
202r="$(python3 "$G" compare "$S/A.pdf" "$S/B.pdf")"
203expect "g_checks: the pair that differs on page 2 goes red, on page 2" "$r" "g3 differ 1 pages 2"
204expect "g_checks: and the verdict is differs" "$r" "g3 verdict differs"
205r="$(python3 "$G" compare "$S/A.pdf" "$S/C.pdf")"
206expect "g_checks: a middle-token change moves no hash" "$r" "g3 differ 0 pages none"
207expect "g_checks: but the verdict is differs" "$r" "g3 verdict differs"
208lack "g_checks: and the similarity is below 1" "$r" "g3 min-similarity 1.000"
209r="$(python3 "$G" compare "$S/A.pdf" "$S/D.pdf")"
210expect "g_checks: a change of the last token alone is a hash difference" "$r" "g3 differ 1 pages 2"
211r="$(python3 "$G" compare "$S/A.pdf" "$S/E.pdf")"
212expect "g_checks: so is a change of the first token alone" "$r" "g3 differ 1 pages 2"
213r="$(python3 "$G" pages "$S/A.pdf")"
214[ "$(printf '%s\n' "$r" | wc -l)" -eq 3 ] && ok "g_checks: pages lists 3 pages" || fail "g_checks pages: $r"
215l2="$(printf '%s\n' "$r" | sed -n 2p | awk '{ print $4 }')"
216l3="$(printf '%s\n' "$r" | sed -n 3p | awk '{ print $4 }')"
217[ -n "$l2" ] && [ "$l2" = "$l3" ] && ok "g_checks: equal pages hash alike" || fail "g_checks hashes: $l2 / $l3"
218
219# The plant: page i is compared with page i+1. The pair A and B was made so that page i of A is page i+1
220# of B, which that fault cannot see; the same check that is green on the real file must go red on the copy.
221sed 's/a, b = pa\[i\], pb\[i\]/a, b = pa[i], pb[min(i + 1, n - 1)]/' "$G" > "$S/g_checks_plant.py"
222if cmp -s "$G" "$S/g_checks_plant.py"; then
223 fail "plant: the sed did not change g_checks.py (its compare line moved)"
224else
225 r="$(python3 "$S/g_checks_plant.py" compare "$S/A.pdf" "$S/B.pdf")"
226 if printf '%s\n' "$r" | grep -qxF "g3 differ 1 pages 2"; then
227 fail "plant: g_checks with page i against page i+1 still found the difference"
228 else
229 ok "plant: page i against page i+1 reports no difference on the pair that differs, so the check is red"
230 fi
231fi
232
233# ── 3. skew.sh ──────────────────────────────────────────────────────────────
234export SKEW_OUT="$S/out"
235export SKEW_EXCLUDE="skip"
236r="$("$HERE/skew.sh" "$S/proj" main.typ assets/fonts "$V" 2>&1)"
237echo "$r" | sed 's/^/ /'
238n="$(printf '%s\n' "$r" | grep -vc '^skew: ')"
239[ "$n" -eq 0 ] && ok "skew: every line is a skew: line" || fail "skew: $n stray line(s)"
240expect "skew: the gather saw 4 sources, an asset and a font" "$r" "skew: typstts gathered sources 4 assets 1 fonts 1 packages 0 missing 0"
241expect "skew: typst.ts compiled" "$r" "skew: typstts compile ok"
242expect "skew: row a typst exit 0" "$r" "skew: row a typst exit 0"
243expect "skew: row b typst exit 0" "$r" "skew: row b typst exit 0"
244expect "skew: row b has 3 pages on both" "$r" "skew: row b pages typstts 3 typst 3"
245expect "skew: row b, the same font files, agrees" "$r" "skew: row b verdict same"
246[ -z "$(ls -A "$S/out")" ] && ok "skew: its scratch is gone on exit" || fail "skew: left $(ls -A "$S/out" | wc -l) entr(ies) behind"
247
248r="$("$HERE/skew.sh" "$S/skewed" main.typ assets/fonts "$V" 2>&1)"
249echo "$r" | sed 's/^/ /'
250expect "skew: the page that prints the compiler version goes red in row a" "$r" "skew: row a differ 1 pages 4"
251expect "skew: and in row b" "$r" "skew: row b differ 1 pages 4"
252expect "skew: and the verdict is differs" "$r" "skew: row b verdict differs"
253
254# Packages: supplied to typst.ts from `pk`, and resolved by typst 0.15.1 from its own layout of the same.
255r="$(TYPST_PACKAGE_PATH="$S/tpk" SKEW_PACKAGES="$S/pk" "$HERE/skew.sh" "$S/pkgproj" main.typ assets/fonts "$V" 2>&1)"
256echo "$r" | sed 's/^/ /'
257n="$(printf '%s\n' "$r" | grep -vc '^skew: ')"
258[ "$n" -eq 0 ] && ok "skew: every line is a skew: line, packages included" || fail "skew: $n stray line(s)"
259expect "skew: 3 packages found, none missing" "$r" "skew: typstts gathered sources 4 assets 1 fonts 1 packages 3 missing 0"
260expect "skew: the directory package is named" "$r" "skew: typstts package preview zzpkg 0.1.0 supplied"
261expect "skew: a pack is named" "$r" "skew: typstts package preview zzpack 0.2.0 supplied"
262expect "skew: and so is the dependency found by the closure" "$r" "skew: typstts package preview zzdep 0.3.0 supplied"
263expect "skew: typst.ts compiled the project that imports them" "$r" "skew: typstts compile ok"
264expect "skew: 4 pages on both, row b" "$r" "skew: row b pages typstts 4 typst 4"
265expect "skew: and the pages agree, row b" "$r" "skew: row b verdict same"
266r="$(TYPST_PACKAGE_PATH="$S/tpk" SKEW_PACKAGES="$S/pk_nodep" "$HERE/skew.sh" "$S/pkgproj" main.typ assets/fonts "$V" 2>&1)"
267expect "skew: a package that is not supplied is named missing" "$r" "skew: typstts package preview zzdep 0.3.0 missing"
268expect "skew: and typst.ts fails" "$r" "skew: typstts compile failed"
269expect "skew: and the row is incomparable, not different" "$r" "skew: row b verdict incomparable"
270
271# Daimond's own vendored packs, where this host has them and Typst's cache holds the same versions: a
272# synthetic project that draws with each of them compiles in typst.ts, so the port reads the real format.
273PACKS="$V/../../assets/typst/packs"
274CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/typst/packages/preview"
275if [ -d "$PACKS" ] && [ -d "$CACHE/cetz/0.3.4" ] && [ -d "$CACHE/fletcher/0.5.7" ] && [ -d "$CACHE/cetz-plot/0.1.1" ] && [ -d "$CACHE/oxifmt/0.2.1" ]; then
276 mkdir -p "$S/real"
277 cat > "$S/real/main.typ" <<'TYP'
278#set page(width: 220pt, height: 160pt, margin: 10pt)
279#import "@preview/cetz:0.3.4": canvas, draw
280#import "@preview/fletcher:0.5.7": diagram, node, edge
281#import "@preview/cetz-plot:0.1.1": plot
282#import "@preview/oxifmt:0.2.1": strfmt
283= Real packs
284#canvas({
285 import draw: *
286 circle((0, 0), radius: 1)
287})
288#pagebreak()
289#diagram(node((0,0), [A]), edge("->"), node((1,0), [B]))
290#pagebreak()
291#strfmt("{} and {}", 1, 2)
292TYP
293 r="$(SKEW_PACKAGES="$PACKS" "$HERE/skew.sh" "$S/real" main.typ assets/fonts "$V" 2>&1)"
294 expect "real packs: cetz, fletcher, cetz-plot, oxifmt and cetz 0.3.2 by closure, none missing" "$r" "skew: typstts gathered sources 1 assets 0 fonts 0 packages 5 missing 0"
295 expect "real packs: typst.ts compiled the project" "$r" "skew: typstts compile ok"
296 expect "real packs: and agrees with typst 0.15.1 on every page, row a" "$r" "skew: row a verdict same"
297else
298 echo "selftest: skip real packs (Daimond's packs or Typst's cache of the same versions are absent)"
299fi
300
301# The supplied font and the image reached typst.ts: the PDF says so, which text alone would not.
302gate_cap node "$HERE/skew_ts.mjs" --root "$S/proj" --main main.typ --vendor "$V" --out "$S/ts.pdf" \
303 --font-dir assets/fonts --exclude skip > /dev/null 2>&1
304pdffonts "$S/ts.pdf" 2>/dev/null | grep -q LibertinusMono \
305 && ok "typst.ts typeset in the supplied font (add_raw_font)" || fail "typst.ts did not embed the supplied font"
306n="$(pdfimages -list "$S/ts.pdf" 2>/dev/null | tail -n +3 | wc -l)"
307[ "$n" -eq 1 ] && ok "typst.ts placed the image (map_shadow)" || fail "typst.ts placed $n image(s), wanted 1"
308
309# Every typst 0.15.1 run hides the account's own fonts: a fake home holds a face typst does not carry.
310mkdir -p "$S/home/.local/share/fonts"
311cp "$CRATE/fonts/LibertinusMono-Regular.otf" "$S/home/.local/share/fonts/"
312printf '#set text(font: "Libertinus Mono")\nMono\n' > "$S/iso.typ"
313( unset XDG_DATA_HOME; HOME="$S/home" gate_cap "$TYPST" compile "$S/iso.typ" "$S/iso_open.pdf" ) > /dev/null 2>&1
314pdffonts "$S/iso_open.pdf" 2>/dev/null | grep -q LibertinusMono \
315 && ok "isolation premise: an open run finds the account's face" || fail "isolation premise: an open run did not find the face"
316HOME="$S/home" gate_typst "$TYPST" compile "$S/iso.typ" "$S/iso_hidden.pdf" > /dev/null 2>&1
317pdffonts "$S/iso_hidden.pdf" 2>/dev/null | grep -q LibertinusMono \
318 && fail "gate_typst let the account's face through" || ok "gate_typst hides the account's own fonts"
319
320# A project that does not compile: typst quotes its source in the error, and none of it may be printed.
321raw="$(cd "$S/broken" && gate_typst "$TYPST" compile --root . main.typ "$S/broken.pdf" 2>&1)"
322printf '%s\n' "$raw" | grep -qF ZZLEAKMARKERZZ && ok "leak premise: typst's own stderr quotes the project's text" \
323 || fail "leak premise: typst did not quote the marker, so the next check proves nothing"
324r="$("$HERE/skew.sh" "$S/broken" main.typ assets/fonts "$V" 2>&1)"
325echo "$r" | sed 's/^/ /'
326lack "skew: nothing of a broken project's text is printed" "$r" ZZLEAKMARKERZZ
327expect "skew: a typst failure is a closed word" "$r" "skew: row a verdict incomparable"
328expect "skew: and a typst.ts failure too" "$r" "skew: typstts compile failed"
329n="$(printf '%s\n' "$r" | grep -vc '^skew: ')"
330[ "$n" -eq 0 ] && ok "skew: a failing run prints only skew: lines" || fail "skew: $n stray line(s) on a failing run"
331
332echo "selftest: $bad failure(s)"
333[ "$bad" -eq 0 ]