interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / browse / tests / run.sh

47 lines · 2671 bytes Raw Blame History
1#!/bin/sh
2# browse/tests/run.sh: build the ForgeBrowse test programs with the pinned omc and run the
3# Markdown fixtures (tests/md/*.md -> expected tests/md/*.html). Cores: taskset -c ${CORES:-6} (the
4# caller's pool; ticket t_7c02d686).
5# Usage: tests/run.sh [util.om] (default: tests/stubutil.om)
6set -eu
7here=$(cd "$(dirname "$0")" && pwd)
8br=$(dirname "$here")
9omv=${OMV:-$HOME/work/flux/omega-mv}
10omc=$omv/seed/out/omc
11util=${1:-$here/stubutil.om}
12out=${OUT:-/tmp/forgebrowse}
13mkdir -p "$out"
14want=3ad9f10f64309e7acf8a725082b28e23a2a4aeb07e98322fb4dc0fcd8fc93194
15got=$(sha256sum "$omc" | cut -d' ' -f1)
16[ "$got" = "$want" ] || { echo "omc sha256 $got != pinned $want" >&2; exit 2; }
17run() { taskset -c "${CORES:-6}" nice -n 10 "$@"; }
18{ printf 'om2\n'; cat "$util" "$(dirname "$br")"/nodes/head.om "$br"/a_core.om "$br"/b_md.om "$here/mdmain.om"; } | run "$omc" > "$out/mdtest" || {
19 echo "compile mdtest failed" >&2; exit 1; }
20chmod +x "$out/mdtest"
21pass=0; fail=0
22for md in "$here"/md/*.md; do
23 exp=${md%.md}.html
24 got=$out/$(basename "${md%.md}").out
25 run "$out/mdtest" < "$md" > "$got" || { echo "FAIL (exit $?) $(basename "$md")"; fail=$((fail+1)); continue; }
26 if grep -qiE '<script|<style|style=|href="javascript:|src="javascript:' "$got"; then
27 fail=$((fail+1)); echo "FAIL (active content) $(basename "$md")"; continue; fi
28 if cmp -s "$got" "$exp"; then pass=$((pass+1)); echo "PASS $(basename "$md")"
29 else fail=$((fail+1)); echo "FAIL $(basename "$md")"; diff "$exp" "$got" | head -20; fi
30done
31# Bounded comment scans: 4 MiB of "<!--" openers with no "-->" (inline and at line starts) must
32# render well inside the timeout (one rescan per opener would be about 10^12 byte reads here) and
33# every opener must stay escaped text.
34n=262144
35big=$out/comment-big.md
36awk -v n=$n 'BEGIN { for (i = 0; i < n; i++) printf "a <!-- b\n<!-- c\n" }' > "$big"
37rc=0
38run timeout 60 "$out/mdtest" < "$big" > "$out/comment-big.out" || rc=$?
39k=$(grep -o '&lt;!--' "$out/comment-big.out" | wc -l)
40if [ "$rc" -ne 0 ]; then fail=$((fail+1)); echo "FAIL comment-big (exit $rc; 124 = timeout)"
41elif [ "$k" -ne $((2 * n)) ]; then fail=$((fail+1)); echo "FAIL comment-big: $k escaped openers, want $((2 * n))"
42else pass=$((pass+1)); echo "PASS comment-big (bounded scan)"; fi
43# The README safety policy on every fixture and its four mutant renderers (tests/hostile.sh).
44if sh "$here/hostile.sh" "$out/hostile" > "$out/hostile.log" 2>&1; then pass=$((pass+1)); echo "PASS hostile.sh ($(tail -1 "$out/hostile.log"))"
45else fail=$((fail+1)); echo "FAIL hostile.sh"; grep '^FAIL' "$out/hostile.log" | head -20; fi
46echo "md fixtures: $pass pass, $fail fail"
47[ "$fail" -eq 0 ]