Files
2026-09-11 17:41:23 -04:00

59 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# End-to-end test: assemble -> link -> emulate, and check program output.
# Usage: tests/e2e.sh
set -euo pipefail
cd "$(dirname "$0")/.."
BIN="build/linux/x86_64/debug"
OUT="build/e2e"
mkdir -p "$OUT"
echo "== building =="
xmake -y >/dev/null
WASM="$BIN/wiasm"
WLINK="$BIN/wlinker"
WCPU="$BIN/weirdcpu"
for t in "$WASM" "$WLINK" "$WCPU"; do
[ -x "$t" ] || { echo "missing binary: $t"; exit 1; }
done
fail=0
check() { # name expected actual
if [ "$2" = "$3" ]; then
echo "PASS $1"
else
echo "FAIL $1"
echo " expected: $(printf '%q' "$2")"
echo " actual: $(printf '%q' "$3")"
fail=1
fi
}
echo
echo "== single object: hello =="
"$WASM" -o "$OUT/hello.wo" examples/hello.asm
"$WLINK" -o "$OUT/hello.wimg" --map "$OUT/hello.map" "$OUT/hello.wo"
check "hello" "Hello, World!" "$("$WCPU" "$OUT/hello.wimg")"
echo
echo "== cross object: putc + main =="
"$WASM" -o "$OUT/putc.wo" examples/putc.asm
"$WASM" -o "$OUT/main.wo" examples/main.asm
"$WLINK" -o "$OUT/main.wimg" -e start --map "$OUT/main.map" "$OUT/putc.wo" "$OUT/main.wo"
check "cross-object" "Hello, 6502!" "$("$WCPU" "$OUT/main.wimg")"
echo
echo "== arithmetic loop: count =="
"$WASM" -o "$OUT/count.wo" examples/count.asm
"$WLINK" -o "$OUT/count.wimg" "$OUT/count.wo"
check "count" "0123456789" "$("$WCPU" "$OUT/count.wimg")"
echo
if [ "$fail" -ne 0 ]; then
echo "e2e: FAILED"
exit 1
fi
echo "e2e: OK"