about summary refs log tree commit diff stats
path: root/modal/tests/run.sh
blob: 8902829ca69bf7b53d302c8ab57e60a6a900f9da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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"