. "$BST_LIB" require lua lua/present out=$(lua "$BST_DATA/selftest_lua.lua" 2>&1); rc=$? # Present-but-trapped is NOT a skip. A library that cannot begin executing on this # arm (the hwjs-cc#26 "orphan at clear" shape that stops libgcrypt's mpicalc) shows # up as a signal death with no output at all, so separate it from an ordinary # assertion failure and say which it was -- an opaque "rc=132" reads as a lua bug. rseen=$(printf '%s\n' "$out" | grep -c '^R[0-9]') trapped=0 [ "$rc" -ge 128 ] && [ "$rseen" -eq 0 ] && trapped=1 case "$out" in *ALL-LUA-OK*) all=1 ;; *) all=0 ;; esac if [ "$rc" -eq 0 ] && [ "$all" -eq 1 ]; then bst_ok lua/all-ok elif [ "$trapped" -eq 1 ]; then bst_notok lua/all-ok "lua trapped before running any case (rc=$rc, no output) - the interpreter did not start" else bst_notok lua/all-ok "rc=$rc $(_bst_1line "$out")"; fi if [ "$trapped" -eq 1 ]; then # Nothing executed, so the per-case assertions cannot run. Record them against # the trap rather than emitting a wall of opaque failures. for c in version maxint intdiv sort closure format gsub find \ err-msg err-nested err-table err-typeerr err-thru-c err-traceback err-loop \ co-yield co-return co-status co-error co-yield-across \ meta-add meta-index io-roundtrip varargs goto gc-reclaims load dump; do bst_notok "lua/$c" "lua trapped before running any case (rc=$rc)" done else # ---- language core ------------------------------------------------------ check_eq lua/version "Lua 5.4" "$(printf '%s\n' "$out" | sed -n 's/^R1-version //p')" check_eq lua/maxint 9223372036854775807 "$(printf '%s\n' "$out" | awk '/^R1-maxint/{print $2}')" check_eq lua/intdiv 3 "$(printf '%s\n' "$out" | awk '/^R1-intdiv/{print $2}')" check_eq lua/mathtype "integer/float" "$(printf '%s\n' "$out" | awk '/^R1-mathtype/{print $2}')" check_eq lua/sort "1" "$(printf '%s\n' "$out" | awk '/^R2-sorted1 /{print $2}')" check_eq lua/closure 3 "$(printf '%s\n' "$out" | awk '/^R2-closure/{print $2}')" check_eq lua/format "x/42/3.14" "$(printf '%s\n' "$out" | awk '/^R3-format/{print $2}')" check_eq lua/gsub "hell0 w0rld" "$(printf '%s\n' "$out" | sed -n 's/^R3-gsub //p')" check_eq lua/find "3:4" "$(printf '%s\n' "$out" | awk '/^R3-find/{print $2}')" # ---- pcall/error: the setjmp/longjmp surface this port was picked to probe. # A broken longjmp rarely crashes; it returns to the wrong frame. So these # assert the CAUGHT VALUE and the interpreter's continued correctness, not just # that something was caught. check_eq lua/err-msg "boom" "$(printf '%s\n' "$out" | sed -n 's/^R4-msg //p')" check_eq lua/err-nested 1 "$(printf '%s\n' "$out" | awk '/^R4-nested/{print $2}')" check_eq lua/err-table 1 "$(printf '%s\n' "$out" | awk '/^R4-tableid/{print $2}')" check_eq lua/err-typeerr 1 "$(printf '%s\n' "$out" | awk '/^R4-typeerr/{print $2}')" check_eq lua/err-thru-c 1 "$(printf '%s\n' "$out" | awk '/^R4-thruC/{print $2}')" check_eq lua/err-traceback 1 "$(printf '%s\n' "$out" | awk '/^R4-tb/{print $2}')" check_eq lua/err-loop 2000 "$(printf '%s\n' "$out" | awk '/^R4-loop/{print $2}')" # ---- coroutines, including an error unwinding out of one ----------------- check_eq lua/co-yield 11 "$(printf '%s\n' "$out" | awk '/^R5-yield /{print $2}')" check_eq lua/co-return 10 "$(printf '%s\n' "$out" | awk '/^R5-return/{print $2}')" check_eq lua/co-status "dead" "$(printf '%s\n' "$out" | awk '/^R5-status/{print $2}')" check_eq lua/co-error 1 "$(printf '%s\n' "$out" | awk '/^R5-coerr/{print $2}')" check_eq lua/co-yield-across "mid/false" "$(printf '%s\n' "$out" | awk '/^R5-yieldacross/{print $2}')" # ---- the rest of the language ------------------------------------------- check_eq lua/meta-add "V(7)" "$(printf '%s\n' "$out" | awk '/^R6-add/{print $2}')" check_eq lua/meta-index "hi" "$(printf '%s\n' "$out" | awk '/^R6-index/{print $2}')" check_eq lua/io-roundtrip "line1|6" "$(printf '%s\n' "$out" | awk '/^R7-io/{print $2}')" check_eq lua/varargs 15 "$(printf '%s\n' "$out" | awk '/^R8-varargs/{print $2}')" check_eq lua/goto 25 "$(printf '%s\n' "$out" | awk '/^R8-goto/{print $2}')" check_eq lua/gc-reclaims 1 "$(printf '%s\n' "$out" | awk '/^R9-gc/{print $2}')" check_eq lua/load 42 "$(printf '%s\n' "$out" | awk '/^R10-load /{print $2}')" check_eq lua/dump 123 "$(printf '%s\n' "$out" | awk '/^R10-dump/{print $2}')" fi # ---- the CLI itself, driven directly rather than through the payload ------- check_out lua/cli-version "Lua 5.4" lua -v check_out lua/cli-e "4" lua -e 'print(2+2)' # An uncaught error must reach the process exit status AND be reported. Not # check_out: that requires exit 0, and failing here is the whole point. check_rc lua/cli-errrc 1 lua -e 'error("cli-boom")' clierr=$(lua -e 'error("cli-boom")' 2>&1) case "$clierr" in *cli-boom*) bst_ok lua/cli-errmsg ;; *) bst_notok lua/cli-errmsg "uncaught error not reported: $(_bst_1line "$clierr")" ;; esac # ---- luac: the bytecode compiler is the package's second binary ------------ if command -v luac >/dev/null 2>&1; then tmp=${TMPDIR:-/tmp}/bst-lua.$$ printf 'print(6*7)\n' > "$tmp.lua" if luac -o "$tmp.luac" "$tmp.lua" 2>/dev/null; then bst_ok lua/luac-compile check_out lua/luac-run "42" lua "$tmp.luac" else bst_notok lua/luac-compile "luac failed to compile a trivial chunk" bst_notok lua/luac-run "no bytecode to run" fi rm -f "$tmp.lua" "$tmp.luac" else bst_skip lua/luac-compile "luac not installed" bst_skip lua/luac-run "luac not installed" fi