run_tests.sh 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #!/bin/sh
  2. # Regression for M2comp step 2 (Coco/R + SymTab semantic analysis).
  3. # Usage: ./run_tests.sh (from the m2comp directory)
  4. pass=0; fail=0
  5. expect_ok() {
  6. if ./M2comp "$1" 2>&1 | grep -q "Parsed correctly"; then
  7. pass=$((pass+1)); echo "PASS(ok): $1"
  8. else
  9. fail=$((fail+1)); echo "FAIL(ok, rejected): $1"
  10. fi
  11. collect_mcd
  12. }
  13. expect_fail() {
  14. if ./M2comp "$1" 2>&1 | grep -q "Incorrect source"; then
  15. pass=$((pass+1)); echo "PASS(fail): $1"
  16. else
  17. fail=$((fail+1)); echo "FAIL(fail, accepted): $1"
  18. fi
  19. collect_mcd
  20. }
  21. expect_dump() {
  22. if ./M2comp "$1" 2>&1 | grep -q "$2"; then
  23. pass=$((pass+1)); echo "PASS(ast): $1 [$2]"
  24. else
  25. fail=$((fail+1)); echo "FAIL(ast): $1 [$2]"
  26. fi
  27. collect_mcd
  28. }
  29. MCINT="${MCINT:-../m-code-64/mcint}"
  30. mkdir -p MC4
  31. MCTIMEOUT="${MCTIMEOUT:-10}"
  32. # MGen emits <Module>.MC4 in the current directory; the run helpers
  33. # below collect it into MC4/ and run it from there.
  34. collect_mcd() {
  35. for f in *.MC4; do
  36. [ -f "$f" ] && mv -f "$f" MC4/
  37. done
  38. }
  39. expect_run() {
  40. # $1 = test file, $2 = expected printed ExitCode value
  41. name="$1"
  42. want="$2"
  43. mod=$(head -n 1 "tests/$name" | cut -d' ' -f2 | cut -d';' -f1)
  44. mcd="MC4/$mod.MC4"
  45. rm -f "$mcd" "$mod.MC4"
  46. if ./M2comp "tests/$name" 2>&1 | grep -q "Incorrect source"; then
  47. fail=$((fail+1)); echo "FAIL(run): $name rejected"; return
  48. fi
  49. [ -f "$mod.MC4" ] && mv -f "$mod.MC4" "$mcd"
  50. if [ ! -f "$mcd" ]; then
  51. fail=$((fail+1)); echo "FAIL(run): $name no $mcd"; return
  52. fi
  53. timeout "$MCTIMEOUT" "$MCINT" "$mcd" > /tmp/m2comp_out.txt 2>&1; rc=$?
  54. if [ "$rc" -ne 0 ]; then
  55. fail=$((fail+1)); echo "FAIL(run): $name vm rc=$rc (diverges?)"; return
  56. fi
  57. got=$(head -n 1 /tmp/m2comp_out.txt | tr -d '\r')
  58. if [ "$got" = "$want" ]; then
  59. pass=$((pass+1)); echo "PASS(run): $name -> $got"
  60. else
  61. fail=$((fail+1)); echo "FAIL(run): $name printed [$got], want [$want]"
  62. fi
  63. }
  64. expect_run_none() {
  65. # $1 = test file — must compile and run silent (terminating)
  66. name="$1"
  67. mod=$(head -n 1 "tests/$name" | cut -d' ' -f2 | cut -d';' -f1)
  68. mcd="MC4/$mod.MC4"
  69. rm -f "$mcd" "$mod.MC4"
  70. if ./M2comp "tests/$name" 2>&1 | grep -q "Incorrect source"; then
  71. fail=$((fail+1)); echo "FAIL(silent): $name rejected"; return
  72. fi
  73. [ -f "$mod.MC4" ] && mv -f "$mod.MC4" "$mcd"
  74. if [ ! -f "$mcd" ]; then
  75. fail=$((fail+1)); echo "FAIL(silent): $name no $mcd"; return
  76. fi
  77. timeout "$MCTIMEOUT" "$MCINT" "$mcd" > /tmp/m2comp_out.txt 2>&1; rc=$?
  78. if [ "$rc" -ne 0 ]; then
  79. fail=$((fail+1)); echo "FAIL(silent): $name vm rc=$rc (diverges?)"; return
  80. fi
  81. got=$(head -n 1 /tmp/m2comp_out.txt)
  82. if [ -z "$got" ]; then
  83. pass=$((pass+1)); echo "PASS(silent): $name runs silent"
  84. else
  85. fail=$((fail+1)); echo "FAIL(silent): $name output [$got]"
  86. fi
  87. }
  88. expect_ok tests/ok_minimal.mod
  89. expect_ok tests/ok_proc.mod
  90. expect_ok tests/showcase.mod
  91. expect_fail tests/bad_mismatch.mod
  92. expect_fail tests/t_dup.mod
  93. expect_fail tests/t_undecl.mod
  94. expect_fail tests/t_assign.mod
  95. expect_fail tests/t_arith.mod
  96. expect_fail tests/t_bool.mod
  97. expect_fail tests/t_rel.mod
  98. expect_fail tests/t_cond.mod
  99. expect_fail tests/t_field.mod
  100. expect_fail tests/t_index.mod
  101. expect_fail tests/t_ptr.mod
  102. expect_fail tests/t_for.mod
  103. expect_fail tests/t_call.mod
  104. expect_fail tests/t_call2.mod
  105. expect_fail tests/t_return.mod
  106. expect_fail tests/t_exit.mod
  107. expect_dump tests/showcase.mod "Module Showcase"
  108. expect_dump tests/showcase.mod "Proc Work"
  109. expect_dump tests/showcase.mod "CallExpr"
  110. expect_dump tests/showcase.mod "Field q"
  111. expect_dump tests/showcase.mod "Int 255"
  112. expect_dump tests/ok_proc.mod "Proc P"
  113. expect_run_none ok_minimal.mod
  114. expect_run_none ok_proc.mod
  115. expect_run r_arith.mod 8
  116. expect_run r_flow.mod 69
  117. expect_run r_bool.mod 11
  118. expect_run r_real.mod 1111
  119. expect_run r_proc.mod 162
  120. expect_run r_varpar.mod 48
  121. expect_run r_nested.mod 213
  122. expect_run r_array.mod 39
  123. expect_run r_record.mod 15
  124. expect_run r_set.mod 12
  125. expect_run r_string.mod 111
  126. expect_run r_ptr.mod 111
  127. expect_run r_module.mod 83
  128. expect_run r_const.mod 1102
  129. echo "--- $pass passed, $fail failed ---"
  130. [ "$fail" -eq 0 ]