34 lines
1.5 KiB
Bash
Executable File
34 lines
1.5 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
unset DISPLAY WAYLAND_DISPLAY XAUTHORITY DBUS_SESSION_BUS_ADDRESS
|
|
|
|
work=$(mktemp -d)
|
|
trap 'rm -rf "$work"' EXIT HUP INT TERM
|
|
|
|
"$1" check --root tests/spec --module-path std tests/spec/sort_test.zi
|
|
"$1" bundle --root tests/spec --module-path std \
|
|
--entry sort_test:SelfTest -o "$work/test.zx" tests/spec/sort_test.zi
|
|
test "$("$1" run "$work/test.zx")" = "42"
|
|
|
|
"$1" build --target=c --root tests/spec --module-path std \
|
|
-o "$work/c" tests/spec/sort_test.zi
|
|
printf '#include "sort_test.h"\nint main(void) { return SelfTest() == 42 ? 0 : 1; }\n' \
|
|
> "$work/c/run.c"
|
|
"${CC:-cc}" -std=c11 -I"$work/c" "$work"/c/*.c -o "$work/c/program"
|
|
"$work/c/program"
|
|
|
|
"$1" ir --root tests/spec --module-path std -o "$work/ir" tests/spec/sort_test.zi
|
|
"$1" bundle --root "$work/ir" --entry sort_test:SelfTest -o "$work/saved.zx" "$work/ir/sort_test.zir"
|
|
cmp "$work/test.zx" "$work/saved.zx"
|
|
test "$("$1" run "$work/saved.zx")" = "42"
|
|
for form in source saved; do
|
|
input=tests/spec/sort_test.zi; module_root=tests/spec
|
|
if test "$form" = saved; then input=$work/ir/sort_test.zir; module_root=$work/ir; fi
|
|
output=$work/$form-c
|
|
"$1" build --target=c --root "$module_root" --module-path std -o "$output" "$input"
|
|
printf '#include "sort_test.h"\nint main(void) { return SelfTest() == 42 ? 0 : 1; }\n' > "$output/run.c"
|
|
"${CC:-cc}" -std=c11 -I"$output" "$output"/*.c -o "$output/program"
|
|
"$output/program"
|
|
done
|
|
printf 'Sorting passed source and saved VM and C.\n'
|