| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #!/bin/sh
- #
- # Step-2 test runner for M2c (scalars + MC64 backend).
- # Usage: ./run_tests.sh (from the m2c directory, after ./build.sh)
- #
- # Positive tests: compile with M2c, run the newest .MCD under mcint,
- # compare the printed ExitCode value with the expectation.
- #
- MCINT="${MCINT:-../mc64/mcint}"
- pass=0
- fail=0
- expect_ok() {
- # $1 = test file (no dir) — parse only
- name="$1"
- out=$(./M2c "tests/$name" 2>&1)
- case "$out" in
- *"Parsed correctly"*)
- echo "ok $name accepted"
- pass=$((pass+1)) ;;
- *)
- echo "FAIL $name: expected accept, got: $out"
- fail=$((fail+1)) ;;
- esac
- }
- expect_fail() {
- # $1 = test file, $2 = message text expected in the .LST
- name="$1"
- want="$2"
- out=$(./M2c "tests/$name" 2>&1)
- case "$out" in
- *"Incorrect source"*) ;;
- *)
- echo "FAIL $name: expected rejection, got: $out"
- fail=$((fail+1)); return ;;
- esac
- lst="tests/$(basename "$name" .mod).LST"
- if grep -q "$want" "$lst" 2>/dev/null; then
- echo "ok $name rejected with [$want]"
- pass=$((pass+1))
- else
- echo "FAIL $name: [$want] not found in $lst"
- fail=$((fail+1))
- fi
- }
- expect_run() {
- # $1 = test file, $2 = expected printed ExitCode value
- name="$1"
- want="$2"
- mod=$(head -n 1 "tests/$name" | cut -d' ' -f2 | cut -d';' -f1)
- mcd="$mod.MCD"
- rm -f "$mcd"
- out=$(./M2c "tests/$name" 2>&1)
- case "$out" in
- *"Parsed correctly"*) ;;
- *)
- echo "FAIL $name: M2c rejected it: $out"
- fail=$((fail+1)); return ;;
- esac
- if [ ! -f "$mcd" ]; then
- echo "FAIL $name: no $mcd produced"
- fail=$((fail+1)); return
- fi
- got=$("$MCINT" "$mcd" 2>&1 | head -n 1 | tr -d '\r')
- if [ "$got" = "$want" ]; then
- echo "ok $name -> $got"
- pass=$((pass+1))
- else
- echo "FAIL $name: printed [$got], expected [$want]"
- fail=$((fail+1))
- fi
- }
- expect_run_none() {
- # $1 = test file — must compile and run with empty output
- name="$1"
- mod=$(head -n 1 "tests/$name" | cut -d' ' -f2 | cut -d';' -f1)
- mcd="$mod.MCD"
- rm -f "$mcd"
- out=$(./M2c "tests/$name" 2>&1)
- case "$out" in
- *"Parsed correctly"*) ;;
- *)
- echo "FAIL $name: M2c rejected it: $out"
- fail=$((fail+1)); return ;;
- esac
- if [ ! -f "$mcd" ]; then
- echo "FAIL $name: no $mcd produced"
- fail=$((fail+1)); return
- fi
- got=$("$MCINT" "$mcd" 2>&1 | head -n 1)
- if [ -z "$got" ]; then
- echo "ok $name runs silent"
- pass=$((pass+1))
- else
- echo "FAIL $name: unexpected output [$got]"
- fail=$((fail+1))
- fi
- }
- echo "=== Phase-0 tests (still green) ==="
- expect_ok ok_minimal.mod
- expect_ok ok_nobegin.mod
- expect_fail bad_mismatch.mod "module name mismatch"
- expect_fail bad_syntax.mod "expected"
- echo "=== Step-2 run tests (M2c -> mcint) ==="
- expect_run_none t_min.mod
- expect_run t_arith.mod 7
- expect_run t_const.mod 15
- expect_run t_bool.mod 42
- expect_run t_if.mod 20
- expect_run t_case.mod 103
- expect_run t_while.mod 55
- expect_run t_repeat.mod 55
- expect_run t_loop.mod 7
- expect_run t_for.mod 85
- expect_run t_real.mod 31
- expect_run t_char.mod 97
- expect_run t_enum.mod 1
- expect_run t_full.mod 74
- expect_run t_set.mod 15
- echo "=== Step-2 rejection tests ==="
- expect_fail t_bad_asn.mod "incompatible assignment"
- expect_fail t_bad_array.mod "not supported in this phase"
- expect_fail t_bad_with.mod "not supported in this phase"
- expect_fail t_bad_exit.mod "not supported in this phase"
- expect_fail t_bad_const.mod "not supported in this phase"
- expect_fail t_bad_deref.mod "not supported in this phase"
- echo "=== $pass passed, $fail failed ==="
- test "$fail" = 0
|