aboutsummaryrefslogtreecommitdiff
path: root/tests/exitstatus.sh
diff options
context:
space:
mode:
Diffstat (limited to 'tests/exitstatus.sh')
-rw-r--r--tests/exitstatus.sh21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/exitstatus.sh b/tests/exitstatus.sh
new file mode 100644
index 0000000..d48ad1f
--- /dev/null
+++ b/tests/exitstatus.sh
@@ -0,0 +1,21 @@
+#!/bin/bash
+# exit status of zy: a program that fails to compile (syntax, type or analyzer
+# error, or too many errors) exits 1; a good program exits 0; a runtime trap
+# keeps its status (0 today). usage: tests/exitstatus.sh [VM]. prints one line
+# per case and exits 1 when any case is wrong.
+vm=${1:-build/bin/zy}
+T=$(mktemp -d); trap 'rm -rf "$T"' EXIT
+fail=0
+want() { # status description < program
+ cat > "$T/p.zc"; "$vm" < "$T/p.zc" > "$T/out" 2>&1; local r=$?
+ if [ "$r" = "$1" ]; then echo "ok $2 (exit $r)"; else echo "FAIL $2: exit $r, want $1: $(head -c 200 "$T/out")"; fail=1; fi
+}
+want 0 "a good program" <<< $'namespace;\ninclude rt;\nfn main() { rt.put_n(1); return 0; }'
+want 1 "a syntax error" <<< $'namespace;\ninclude rt;\nfn main() { int a = ; return 0; }'
+want 1 "a module access without include" <<< $'fn main() { rt.put_n(1); return 0; }'
+want 1 "an undefined name" <<< $'namespace;\ninclude rt;\nfn main() { rt.put_n(nosuch); return 0; }'
+want 1 "a type error" < tests/typeerrors/arg.zc
+want 1 "an analyzer error" < tests/errors/alias_field.zc
+want 1 "twenty errors" < <(printf 'namespace;\ninclude rt;\nfn main() {\n'; for i in $(seq 25); do echo " int a$i = ;"; done; echo ' return 0; }')
+want 0 "a runtime trap keeps its status" < tests/programs/bounds_heap.zc
+exit $fail