run_tests.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/bin/sh
  2. # M2make regression tests. Builds M2make with both compilers (via the
  3. # sibling build scripts) and exercises ordering, up-to-date checks,
  4. # rebuilds, cycles, and real builds.
  5. # Usage: ./run_tests.sh (from the tools/m2make directory)
  6. pass=0; fail=0
  7. ok() { pass=$((pass+1)); echo "PASS: $1"; }
  8. no() { fail=$((fail+1)); echo "FAIL: $1"; }
  9. # --- bootstrapping: both compilers must build M2make ---
  10. ./build_gm2.sh > /tmp/m2make_t.log 2>&1
  11. if [ -x b_gm2/M2make ]; then ok "gm2 builds M2make"; else no "gm2 builds M2make"; fi
  12. ./build_m2.sh > /tmp/m2make_t.log 2>&1
  13. if [ -x b_v3/M2make ]; then ok "M2 builds M2make"; else no "M2 builds M2make"; fi
  14. GM2=b_gm2/M2make
  15. V3M=b_v3/M2make
  16. # --- dry-run ordering (both binaries must agree) ---
  17. for bin in "$GM2" "$V3M"; do
  18. out=$($bin -n -c gm2 tests/Main2.mod 2>&1)
  19. calc_line=$(printf '%s\n' "$out" | grep -n "Calc :" | cut -d: -f1)
  20. main_line=$(printf '%s\n' "$out" | grep -n "M2makeMain" | cut -d: -f1)
  21. if [ -n "$calc_line" ] && [ -n "$main_line" ] && [ "$calc_line" -lt "$main_line" ]; then
  22. ok "$bin order (Calc before Main2)"
  23. else
  24. no "$bin order (Calc before Main2): $out"
  25. fi
  26. case "$out" in
  27. *"Add"*) no "$bin leaks FROM-items as modules: $out" ;;
  28. *) ok "$bin ignores FROM-items" ;;
  29. esac
  30. done
  31. # --- cycle detection ---
  32. for bin in "$GM2" "$V3M"; do
  33. out=$($bin -n -c gm2 tests/CycA.mod 2>&1); rc=$?
  34. case "$out" in
  35. *"cyclic import"*) ok "$bin reports cycle" ;;
  36. *) no "$bin reports cycle: $out" ;;
  37. esac
  38. if [ "$rc" = "1" ]; then ok "$bin cycle exit code 1"; else no "$bin cycle exit code ($rc)"; fi
  39. done
  40. # --- real gm2 build, run, up-to-date, rebuild ---
  41. rm -f Main2 *.o
  42. if $GM2 -c gm2 -o Main2 tests/Main2.mod > /tmp/m2make_t.log 2>&1; then
  43. ok "gm2-mode real build"
  44. else
  45. no "gm2-mode real build"
  46. fi
  47. if [ "$(./Main2 2>/dev/null)" = "ok42" ]; then
  48. ok "gm2-built program runs (ok42)"
  49. else
  50. no "gm2-built program runs"
  51. fi
  52. out=$($GM2 -c gm2 -o Main2 tests/Main2.mod 2>&1)
  53. case "$out" in
  54. *"up to date"*) ok "gm2-mode up-to-date skip" ;;
  55. *) no "gm2-mode up-to-date skip: $out" ;;
  56. esac
  57. sleep 1
  58. touch tests/Calc.mod
  59. out=$($GM2 -c gm2 -o Main2 tests/Main2.mod 2>&1)
  60. case "$out" in
  61. *"-c tests/Calc.mod"*) ok "gm2-mode recompiles touched dep" ;;
  62. *) no "gm2-mode recompiles touched dep: $out" ;;
  63. esac
  64. touch tests/Calc.def tests/Calc.mod tests/Main2.mod
  65. # --- real m2 build via the V3-built M2make ---
  66. rm -rf gen_ssa Main m2make.log
  67. if $V3M -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  68. -I ../../stdlib -o Main tests/Main.mod > /tmp/m2make_t.log 2>&1; then
  69. ok "m2-mode real build (V3 M2make)"
  70. else
  71. no "m2-mode real build (V3 M2make)"
  72. fi
  73. if ./Main 2>/dev/null | grep -q "42"; then
  74. ok "m2-built program runs (42)"
  75. else
  76. no "m2-built program runs"
  77. fi
  78. out=$($V3M -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  79. -I ../../stdlib -o Main tests/Main.mod 2>&1)
  80. case "$out" in
  81. *"up to date"*) ok "m2-mode up-to-date skip" ;;
  82. *) no "m2-mode up-to-date skip: $out" ;;
  83. esac
  84. # --- cross-check: gm2-built M2make drives an m2 build too ---
  85. rm -rf gen_ssa MainX m2make.log
  86. if $GM2 -c m2 --m2bin ../../compiler/M2 --shim ../../runtime/syslib/shim.c \
  87. -I ../../stdlib -o MainX tests/Main.mod > /tmp/m2make_t.log 2>&1 \
  88. && ./MainX 2>/dev/null | grep -q "42"; then
  89. ok "gm2-built M2make drives m2 build"
  90. else
  91. no "gm2-built M2make drives m2 build"
  92. fi
  93. rm -f Main MainX Main2 *.o
  94. rm -rf gen_ssa
  95. rm -f m2make.log
  96. echo "--- $pass passed, $fail failed ---"
  97. [ "$fail" -eq 0 ]