diff options
Diffstat (limited to 'modal/tests/run.sh')
-rwxr-xr-x | modal/tests/run.sh | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/modal/tests/run.sh b/modal/tests/run.sh new file mode 100755 index 0000000..8902829 --- /dev/null +++ b/modal/tests/run.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)" +BUILD_DIR="$ROOT_DIR/build" +OCAML_DIR="$ROOT_DIR/ocaml" +CASES_DIR="$ROOT_DIR/tests/cases" + +mkdir -p "$BUILD_DIR" + +echo "[1/3] Build C interpreter" +cc -O2 -o "$BUILD_DIR/modal_c" "$ROOT_DIR/modal.c" + +echo "[2/3] Build OCaml interpreter" +(cd "$OCAML_DIR" && opam exec -- dune build @install) + +echo "[3/3] Run test cases" +fail=0 +for case in "$CASES_DIR"/*.modal; do + [ -e "$case" ] || continue + rel="${case#$ROOT_DIR/}" + printf " - %s... " "$rel" + + # Skip non-parity features between OCaml AST engine and C stream engine + if grep -q "(<>\)" "$case" || grep -q "(><\)" "$case"; then + echo "SKIP" + continue + fi + + ocaml_out=$(cd "$OCAML_DIR" && opam exec -- dune exec modal -- -q "$case" 2>/dev/null | tr -d '\n' | sed -e 's/^((/(/' -e 's/))$/)/') + c_out=$("$BUILD_DIR/modal_c" "$case" 2>&1 1>/dev/null | sed -n 's/^\.\. \(.*\)$/\1/p' | tr -d '\n') + + if [ "$ocaml_out" = "$c_out" ]; then + echo "OK" + else + echo "FAIL" + echo " OCaml: $ocaml_out" + echo " C : $c_out" + fail=$((fail+1)) + fi +done + +if [ "$fail" -ne 0 ]; then + echo "Tests failed: $fail" + exit 1 +fi + +echo "All tests passed" + |