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. |
| 17 | set -u |
| 18 | |
| 19 | HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 20 | CRATE="$(cd "$HERE/../.." && pwd)" |
| 21 | # shellcheck source=gate_lib.sh |
| 22 | . "$HERE/gate_lib.sh" |
| 23 | |
| 24 | V="${1:?usage: selftest.sh <typst-vendor> <scratch>}" |
| 25 | PARENT="${2:?usage: selftest.sh <typst-vendor> <scratch>}" |
| 26 | TYPST="${SKEW_TYPST:-/home/jason/bin/typst}" |
| 27 | mkdir -p "$PARENT" || exit 2 |
| 28 | S="$(mktemp -d "$PARENT/o1.XXXXXX")" || exit 2 |
| 29 | trap 'rm -rf "${S:?}"' EXIT |
| 30 | GATE_SCRATCH="$S" |
| 31 | |
| 32 | bad=0 |
| 33 | ok() { echo "selftest: ok $1"; } |
| 34 | fail() { echo "selftest: FAIL $1"; bad=$((bad + 1)); } |
| 35 | expect() { # 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 | } |
| 38 | lack() { # 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 ────────────────────────────────────────────────── |
| 43 | mkproj() { # 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' |
| 48 | import sys |
| 49 | from PIL import Image |
| 50 | Image.new('RGB', (8, 8), (200, 40, 40)).save(sys.argv[1]) |
| 51 | PY |
| 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() |
| 68 | Third page. |
| 69 | TYP |
| 70 | if [ -n "${2:-}" ]; then |
| 71 | printf '#pagebreak()\n%s\n' "$2" >> "$p/main.typ" |
| 72 | fi |
| 73 | } |
| 74 | mkproj "$S/proj" |
| 75 | mkproj "$S/skewed" 'Compiler minor #sys.version.at(1).' |
| 76 | mkdir -p "$S/broken" |
| 77 | printf '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. |
| 82 | pkgfile() { # pkgfile <relative path> <text> |
| 83 | mkdir -p "$(dirname "$S/tpk/$1")" |
| 84 | printf '%s\n' "$2" > "$S/tpk/$1" |
| 85 | } |
| 86 | pkgfile preview/zzpkg/0.1.0/typst.toml $'[package]\nname = "zzpkg"\nversion = "0.1.0"\nentrypoint = "lib.typ"' |
| 87 | pkgfile 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()]' |
| 88 | pkgfile preview/zzpkg/0.1.0/helper.typ '#let help() = [helper]' |
| 89 | pkgfile preview/zzdep/0.3.0/typst.toml $'[package]\nname = "zzdep"\nversion = "0.3.0"\nentrypoint = "lib.typ"' |
| 90 | pkgfile preview/zzdep/0.3.0/lib.typ '#let dep() = [dependency]' |
| 91 | pkgfile preview/zzpack/0.2.0/typst.toml $'[package]\nname = "zzpack"\nversion = "0.2.0"\nentrypoint = "src/lib.typ"' |
| 92 | pkgfile preview/zzpack/0.2.0/src/lib.typ '#let pk() = [packed]' |
| 93 | pkgfile preview/zzpack/0.2.0/LICENSE 'Synthetic.' |
| 94 | mkdir -p "$S/pk/preview/zzpkg" "$S/pk/preview/zzdep" "$S/pk/preview/zzpack" |
| 95 | cp -r "$S/tpk/preview/zzpkg/0.1.0" "$S/pk/preview/zzpkg/0.1.0" |
| 96 | mkpack() { # 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' |
| 98 | import os, re, sys |
| 99 | src, ns, name, ver, out = sys.argv[1:] |
| 100 | files = [] |
| 101 | for 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) |
| 106 | files.sort() |
| 107 | entry = re.search(r'^\s*entrypoint\s*=\s*"(.*)"', open(os.path.join(src, 'typst.toml')).read(), re.M).group(1) |
| 108 | head = 'DAIMOND TYPST PACK 1\nnamespace %s\nname %s\nversion %s\nentrypoint %s\n' % (ns, name, ver, entry) |
| 109 | body = b'' |
| 110 | for 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 |
| 114 | os.makedirs(os.path.dirname(out), exist_ok=True) |
| 115 | open(out, 'wb').write(head.encode() + b'\n' + body) |
| 116 | PY |
| 117 | } |
| 118 | mkpack preview zzdep 0.3.0 "$S/pk" |
| 119 | mkpack preview zzpack 0.2.0 "$S/pk" |
| 120 | mkproj "$S/pkgproj" |
| 121 | cat >> "$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() |
| 126 | Quoted, not imported: `#import "@preview/zzghost:1.0.0"` and the string below. |
| 127 | #let s = "@preview/zzghost2:1.0.0" |
| 128 | TYP |
| 129 | |
| 130 | # ── 1. gather ─────────────────────────────────────────────────────────────── |
| 131 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/proj" main.typ --exclude skip 2>&1)" |
| 132 | echo "$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" |
| 135 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/proj" main.typ 2>&1)" |
| 136 | echo "$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" |
| 138 | mkdir -p "$S/pkg" |
| 139 | printf '#import "@preview/zzz:0.0.1": f\n' > "$S/pkg/main.typ" |
| 140 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkg" main.typ 2>&1)" |
| 141 | echo "$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. |
| 146 | mkdir -p "$S/links/a" |
| 147 | printf '#set page(width: 100pt)\n' > "$S/links/main.typ" |
| 148 | printf 'x\n' > "$S/links/a/x.txt" |
| 149 | ln -s a "$S/links/b" |
| 150 | ln -s . "$S/links/up" |
| 151 | ln -s nowhere "$S/links/dead" |
| 152 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/links" main.typ 2>&1)" |
| 153 | echo "$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" |
| 156 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --exclude skip --packages "$S/pk" 2>&1)" |
| 157 | echo "$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" |
| 160 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --exclude skip 2>&1)" |
| 161 | echo "$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" |
| 163 | cp -r "$S/pk" "$S/pk_nodep" && rm -rf "${S:?}/pk_nodep/preview/zzdep" |
| 164 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --exclude skip --packages "$S/pk_nodep" 2>&1)" |
| 165 | echo "$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" |
| 167 | cp -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" |
| 168 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --exclude skip --packages "$S/pk_bad" 2>&1)" |
| 169 | expect "gather: a truncated pack is refused with a closed code" "$g" "gather: error bad-package" |
| 170 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/pkgproj" main.typ --packages "$S/nowhere" 2>&1)" |
| 171 | expect "gather: a package directory that does not exist is refused" "$g" "gather: error no-packages" |
| 172 | g="$(gate_cap node "$CRATE/tools/bench/lib/gather.mjs" "$S/proj" nothing.typ 2>&1)" |
| 173 | expect "gather: a missing main is refused with a closed code" "$g" "gather: error no-main" |
| 174 | |
| 175 | # ── 2. g_checks ───────────────────────────────────────────────────────────── |
| 176 | mkpdf() { # 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 | } |
| 190 | P1="Alpha one two three" |
| 191 | P2="Beta four five six" |
| 192 | P2x="Beta four 5 six" |
| 193 | mkpdf A "$P1" "$P2" "$P2" |
| 194 | mkpdf B "$P1" "$P1" "$P2" |
| 195 | mkpdf C "$P1" "$P2x" "$P2" |
| 196 | mkpdf D "$P1" "Beta four five seven" "$P2" |
| 197 | mkpdf E "$P1" "Gamma four five six" "$P2" |
| 198 | G="$HERE/g_checks.py" |
| 199 | r="$(python3 "$G" compare "$S/A.pdf" "$S/A.pdf")" |
| 200 | expect "g_checks: a PDF agrees with itself" "$r" "g3 verdict same" |
| 201 | expect "g_checks: no page differs" "$r" "g3 differ 0 pages none" |
| 202 | r="$(python3 "$G" compare "$S/A.pdf" "$S/B.pdf")" |
| 203 | expect "g_checks: the pair that differs on page 2 goes red, on page 2" "$r" "g3 differ 1 pages 2" |
| 204 | expect "g_checks: and the verdict is differs" "$r" "g3 verdict differs" |
| 205 | r="$(python3 "$G" compare "$S/A.pdf" "$S/C.pdf")" |
| 206 | expect "g_checks: a middle-token change moves no hash" "$r" "g3 differ 0 pages none" |
| 207 | expect "g_checks: but the verdict is differs" "$r" "g3 verdict differs" |
| 208 | lack "g_checks: and the similarity is below 1" "$r" "g3 min-similarity 1.000" |
| 209 | r="$(python3 "$G" compare "$S/A.pdf" "$S/D.pdf")" |
| 210 | expect "g_checks: a change of the last token alone is a hash difference" "$r" "g3 differ 1 pages 2" |
| 211 | r="$(python3 "$G" compare "$S/A.pdf" "$S/E.pdf")" |
| 212 | expect "g_checks: so is a change of the first token alone" "$r" "g3 differ 1 pages 2" |
| 213 | r="$(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" |
| 215 | l2="$(printf '%s\n' "$r" | sed -n 2p | awk '{ print $4 }')" |
| 216 | l3="$(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. |
| 221 | sed 's/a, b = pa\[i\], pb\[i\]/a, b = pa[i], pb[min(i + 1, n - 1)]/' "$G" > "$S/g_checks_plant.py" |
| 222 | if cmp -s "$G" "$S/g_checks_plant.py"; then |
| 223 | fail "plant: the sed did not change g_checks.py (its compare line moved)" |
| 224 | else |
| 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 |
| 231 | fi |
| 232 | |
| 233 | # ── 3. skew.sh ────────────────────────────────────────────────────────────── |
| 234 | export SKEW_OUT="$S/out" |
| 235 | export SKEW_EXCLUDE="skip" |
| 236 | r="$("$HERE/skew.sh" "$S/proj" main.typ assets/fonts "$V" 2>&1)" |
| 237 | echo "$r" | sed 's/^/ /' |
| 238 | n="$(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)" |
| 240 | expect "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" |
| 241 | expect "skew: typst.ts compiled" "$r" "skew: typstts compile ok" |
| 242 | expect "skew: row a typst exit 0" "$r" "skew: row a typst exit 0" |
| 243 | expect "skew: row b typst exit 0" "$r" "skew: row b typst exit 0" |
| 244 | expect "skew: row b has 3 pages on both" "$r" "skew: row b pages typstts 3 typst 3" |
| 245 | expect "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 | |
| 248 | r="$("$HERE/skew.sh" "$S/skewed" main.typ assets/fonts "$V" 2>&1)" |
| 249 | echo "$r" | sed 's/^/ /' |
| 250 | expect "skew: the page that prints the compiler version goes red in row a" "$r" "skew: row a differ 1 pages 4" |
| 251 | expect "skew: and in row b" "$r" "skew: row b differ 1 pages 4" |
| 252 | expect "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. |
| 255 | r="$(TYPST_PACKAGE_PATH="$S/tpk" SKEW_PACKAGES="$S/pk" "$HERE/skew.sh" "$S/pkgproj" main.typ assets/fonts "$V" 2>&1)" |
| 256 | echo "$r" | sed 's/^/ /' |
| 257 | n="$(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)" |
| 259 | expect "skew: 3 packages found, none missing" "$r" "skew: typstts gathered sources 4 assets 1 fonts 1 packages 3 missing 0" |
| 260 | expect "skew: the directory package is named" "$r" "skew: typstts package preview zzpkg 0.1.0 supplied" |
| 261 | expect "skew: a pack is named" "$r" "skew: typstts package preview zzpack 0.2.0 supplied" |
| 262 | expect "skew: and so is the dependency found by the closure" "$r" "skew: typstts package preview zzdep 0.3.0 supplied" |
| 263 | expect "skew: typst.ts compiled the project that imports them" "$r" "skew: typstts compile ok" |
| 264 | expect "skew: 4 pages on both, row b" "$r" "skew: row b pages typstts 4 typst 4" |
| 265 | expect "skew: and the pages agree, row b" "$r" "skew: row b verdict same" |
| 266 | r="$(TYPST_PACKAGE_PATH="$S/tpk" SKEW_PACKAGES="$S/pk_nodep" "$HERE/skew.sh" "$S/pkgproj" main.typ assets/fonts "$V" 2>&1)" |
| 267 | expect "skew: a package that is not supplied is named missing" "$r" "skew: typstts package preview zzdep 0.3.0 missing" |
| 268 | expect "skew: and typst.ts fails" "$r" "skew: typstts compile failed" |
| 269 | expect "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. |
| 273 | PACKS="$V/../../assets/typst/packs" |
| 274 | CACHE="${XDG_CACHE_HOME:-$HOME/.cache}/typst/packages/preview" |
| 275 | if [ -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) |
| 292 | TYP |
| 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" |
| 297 | else |
| 298 | echo "selftest: skip real packs (Daimond's packs or Typst's cache of the same versions are absent)" |
| 299 | fi |
| 300 | |
| 301 | # The supplied font and the image reached typst.ts: the PDF says so, which text alone would not. |
| 302 | gate_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 |
| 304 | pdffonts "$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" |
| 306 | n="$(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. |
| 310 | mkdir -p "$S/home/.local/share/fonts" |
| 311 | cp "$CRATE/fonts/LibertinusMono-Regular.otf" "$S/home/.local/share/fonts/" |
| 312 | printf '#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 |
| 314 | pdffonts "$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" |
| 316 | HOME="$S/home" gate_typst "$TYPST" compile "$S/iso.typ" "$S/iso_hidden.pdf" > /dev/null 2>&1 |
| 317 | pdffonts "$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. |
| 321 | raw="$(cd "$S/broken" && gate_typst "$TYPST" compile --root . main.typ "$S/broken.pdf" 2>&1)" |
| 322 | printf '%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" |
| 324 | r="$("$HERE/skew.sh" "$S/broken" main.typ assets/fonts "$V" 2>&1)" |
| 325 | echo "$r" | sed 's/^/ /' |
| 326 | lack "skew: nothing of a broken project's text is printed" "$r" ZZLEAKMARKERZZ |
| 327 | expect "skew: a typst failure is a closed word" "$r" "skew: row a verdict incomparable" |
| 328 | expect "skew: and a typst.ts failure too" "$r" "skew: typstts compile failed" |
| 329 | n="$(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 | |
| 332 | echo "selftest: $bad failure(s)" |
| 333 | [ "$bad" -eq 0 ] |