| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #!/bin/bash
- # The CALC ladder — a NUMBER for "how far into CALC.PAS does the compiler get".
- #
- # CALC-COMPILE.md §1: a 1,763-line program that stops on one line is not
- # progress unless the stopping point is asserted somewhere. Each row of
- # tests/fixtures/calc_ladder.tsv is that assertion — the exact verdict, and
- # once it compiles the exact code/data sizes — and every stage of that plan
- # moves the row forward, never backward.
- #
- # The compiler runs on a COPY, staged in tmp/calc_ladder/, for two reasons:
- # - the include (CALC-COMPILE.md Stage 2) is resolved relative to the
- # including file, so CALC.INC must sit beside CALC.PAS in the staged tree;
- # - the row then measures THIS compiler, not an edit-in-place of Resources.
- #
- # The build is deliberately not redone here. tests/run_compile_tests.sh
- # --build-only is the one recipe that builds and freshness-checks compiletest,
- # so there is no second staleness test to drift from the first — which is how
- # this project once reported the previous compiler's verdicts with total
- # confidence.
- set -u
- D=/home/eric/Projets/Projets-Modula2/MyWork/TP3-comp/shell
- cd "$D" || exit 9
- # One build recipe: run_compile_tests.sh checks compiletest against every input
- # and rebuilds when it is older. Its build line is kept visible.
- tests/run_compile_tests.sh --build-only || exit 1
- [ -x compiletest ] || { echo "no compiletest after the build"; exit 1; }
- TSV=tests/fixtures/calc_ladder.tsv
- [ -f "$TSV" ] || { echo "no ladder file $TSV"; exit 1; }
- STAGE=../tmp/calc_ladder
- mkdir -p "$STAGE"
- rm -f "$STAGE"/*
- # Stage a program and everything that has to sit beside it. Companions are
- # copied whether or not the compiler can read them yet: once {$I} lands, the
- # include is what turns CALC.PAS into the whole program, and a ladder that
- # reported "cannot open CALC.INC" for a file that was never staged would be
- # measuring the staging, not the compiler.
- stage () {
- prog=$1
- cp "../Resources/TP3/$prog" "$STAGE/$prog" || exit 1
- case $prog in
- CALC.PAS) cp ../Resources/TP3/CALC.INC "$STAGE/CALC.INC" || exit 1 ;;
- esac
- }
- # Normalise compiletest's one-line verdict the same way run_compile_tests.sh
- # does: drop the path, and turn "OK code=N data=M" / "ERROR n at pos p" into
- # the row spelling "OK N M" / "ERR n p".
- verdict_for () {
- printf '%s\n' "$1" | ./compiletest \
- | grep -F "$1" | head -1 | tr -d '\r' \
- | sed -E 's/^[^ ]+[[:space:]]+//' | tr -s ' ' \
- | sed -E 's/^OK code=([0-9]+) data=([0-9]+)$/OK \1 \2/;
- s/^ERROR ([0-9]+) at pos ([0-9]+)$/ERR \1 \2/'
- }
- pass=0
- fail=0
- while IFS=$'\t' read -r prog v a b; do
- case $prog in '' | '#'*) continue ;; esac
- stage "$prog"
- src="$STAGE/$prog"
- actual=$(verdict_for "$src")
- want=$(printf '%s %s %s' "$v" "$a" "$b" | tr -s ' ')
- if [ "$actual" = "$want" ]; then
- printf ' %-14s PASS %s\n' "$prog" "$actual"
- pass=$((pass + 1))
- else
- printf ' %-14s FAIL\n expected: %s\n actual: %s\n' \
- "$prog" "$want" "$actual"
- fail=$((fail + 1))
- fi
- done < "$TSV"
- echo "----------------------------------------------------------------"
- echo "CALC ladder: $pass passed, $fail failed (of $((pass + fail)))"
- [ "$fail" -eq 0 ] || exit 1
|