ability to run code and check output in tests

This commit is contained in:
2024-12-28 13:19:15 -08:00
parent 95f90c8698
commit a6e68ac2a2
62 changed files with 459 additions and 31 deletions

View File

@@ -1,11 +1,31 @@
#!/bin/sh
SAMPLES=$(find playground/samples -name "*.newt")
for i in tests/black/*.newt $SAMPLES aoc2024/*.newt; do
./build/exec/newt $i
total=0
failed=0
for fn in tests/*.newt ; do
total=$((total + 1))
echo Test $fn
bn=$(basename $fn)
./build/exec/newt $fn -o out.js > tmp/${bn}.compile
if [ $? != "0" ]; then
echo FAIL $i
exit -1
echo Compile failed for $fn
failed=$((failed + 1))
continue
fi
# if there is a golden file, run the code and compare output
if [ -f ${fn}.golden ]; then
bun run out.js > tmp/${bn}.out
if [ $? != "0" ]; then
echo Run failed for $fn
failed=$((failed + 1))
continue
fi
if ! diff -q tmp/${bn}.out ${fn}.golden; then
echo "Output mismatch for $fn"
failed=$((failed + 1))
fi
fi
echo $?
done
echo "Total tests: $total"
echo "Failed tests: $failed"