#!/bin/sh
# Cryn test suite: compile and run each tests/*.cryn and compare with
# tests/expected/<name>.txt. Error tests in tests/errors must fail to compile.
# CRYN_ARGS: extra flags passed to the compiler (e.g. --release).
set -u
cd "$(dirname "$0")"
CRYN=../cryn
CRYN_ARGS=${CRYN_ARGS:-}
pass=0
fail=0
for src in *.cryn; do
name=$(basename "$src" .cryn)
exp="expected/$name.txt"
[ -f "$exp" ] || continue
if [ -f "input/$name.txt" ]; then
out=$($CRYN run "$src" $CRYN_ARGS < "input/$name.txt" 2>/dev/null)
else
out=$($CRYN run "$src" $CRYN_ARGS 2>/dev/null)
fi
if [ "$out" = "$(cat "$exp")" ]; then
pass=$((pass + 1))
else
fail=$((fail + 1))
echo "FAIL: $name"
echo " expected: $(tr '\n' '|' < "$exp")"
echo " got: $(printf '%s' "$out" | tr '\n' '|')"
fi
done
for src in errors/*.cryn; do
name=$(basename "$src" .cryn)
if $CRYN check "$src" >/dev/null 2>&1; then
fail=$((fail + 1))
echo "FAIL (should not compile): $name"
else
pass=$((pass + 1))
fi
done
echo "$pass passed, $fail failed"
[ "$fail" -eq 0 ]