calc_ladder.sh 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/bash
  2. # The CALC ladder — a NUMBER for "how far into CALC.PAS does the compiler get".
  3. #
  4. # CALC-COMPILE.md §1: a 1,763-line program that stops on one line is not
  5. # progress unless the stopping point is asserted somewhere. Each row of
  6. # tests/fixtures/calc_ladder.tsv is that assertion — the exact verdict, and
  7. # once it compiles the exact code/data sizes — and every stage of that plan
  8. # moves the row forward, never backward.
  9. #
  10. # The compiler runs on a COPY, staged in tmp/calc_ladder/, for two reasons:
  11. # - the include (CALC-COMPILE.md Stage 2) is resolved relative to the
  12. # including file, so CALC.INC must sit beside CALC.PAS in the staged tree;
  13. # - the row then measures THIS compiler, not an edit-in-place of Resources.
  14. #
  15. # The build is deliberately not redone here. tests/run_compile_tests.sh
  16. # --build-only is the one recipe that builds and freshness-checks compiletest,
  17. # so there is no second staleness test to drift from the first — which is how
  18. # this project once reported the previous compiler's verdicts with total
  19. # confidence.
  20. set -u
  21. D=/home/eric/Projets/Projets-Modula2/MyWork/TP3-comp/shell
  22. cd "$D" || exit 9
  23. # One build recipe: run_compile_tests.sh checks compiletest against every input
  24. # and rebuilds when it is older. Its build line is kept visible.
  25. tests/run_compile_tests.sh --build-only || exit 1
  26. [ -x compiletest ] || { echo "no compiletest after the build"; exit 1; }
  27. TSV=tests/fixtures/calc_ladder.tsv
  28. [ -f "$TSV" ] || { echo "no ladder file $TSV"; exit 1; }
  29. STAGE=../tmp/calc_ladder
  30. mkdir -p "$STAGE"
  31. rm -f "$STAGE"/*
  32. # Stage a program and everything that has to sit beside it. Companions are
  33. # copied whether or not the compiler can read them yet: once {$I} lands, the
  34. # include is what turns CALC.PAS into the whole program, and a ladder that
  35. # reported "cannot open CALC.INC" for a file that was never staged would be
  36. # measuring the staging, not the compiler.
  37. stage () {
  38. prog=$1
  39. cp "../Resources/TP3/$prog" "$STAGE/$prog" || exit 1
  40. case $prog in
  41. CALC.PAS) cp ../Resources/TP3/CALC.INC "$STAGE/CALC.INC" || exit 1 ;;
  42. esac
  43. }
  44. # Normalise compiletest's one-line verdict the same way run_compile_tests.sh
  45. # does: drop the path, and turn "OK code=N data=M" / "ERROR n at pos p" into
  46. # the row spelling "OK N M" / "ERR n p".
  47. verdict_for () {
  48. printf '%s\n' "$1" | ./compiletest \
  49. | grep -F "$1" | head -1 | tr -d '\r' \
  50. | sed -E 's/^[^ ]+[[:space:]]+//' | tr -s ' ' \
  51. | sed -E 's/^OK code=([0-9]+) data=([0-9]+)$/OK \1 \2/;
  52. s/^ERROR ([0-9]+) at pos ([0-9]+)$/ERR \1 \2/'
  53. }
  54. pass=0
  55. fail=0
  56. while IFS=$'\t' read -r prog v a b; do
  57. case $prog in '' | '#'*) continue ;; esac
  58. stage "$prog"
  59. src="$STAGE/$prog"
  60. actual=$(verdict_for "$src")
  61. want=$(printf '%s %s %s' "$v" "$a" "$b" | tr -s ' ')
  62. if [ "$actual" = "$want" ]; then
  63. printf ' %-14s PASS %s\n' "$prog" "$actual"
  64. pass=$((pass + 1))
  65. else
  66. printf ' %-14s FAIL\n expected: %s\n actual: %s\n' \
  67. "$prog" "$want" "$actual"
  68. fail=$((fail + 1))
  69. fi
  70. done < "$TSV"
  71. echo "----------------------------------------------------------------"
  72. echo "CALC ladder: $pass passed, $fail failed (of $((pass + fail)))"
  73. [ "$fail" -eq 0 ] || exit 1