run_tests.sh 3.6 KB

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