| 1 | #!/bin/sh |
| 2 | # The conformance suite: programs whose behaviour the report defines, |
| 3 | # which every implementation of raz must give, whatever its target. |
| 4 | # |
| 5 | # conform/check.sh [-noreals] COMPILER [MESSAGES] |
| 6 | # |
| 7 | # run from the directory above conform/. COMPILER is run as |
| 8 | # COMPILER -I DIR -o EXE FILE |
| 9 | # to compile FILE, finding the modules it imports, besides the |
| 10 | # library's, in DIR, into the executable EXE; an implementation run |
| 11 | # otherwise is given a script that runs it so. |
| 12 | # |
| 13 | # run/X.raz a program; run/mods holds the modules it imports |
| 14 | # run/X.expect its standard output |
| 15 | # run/X.args its arguments, one per line (optional) |
| 16 | # run/X.status its exit status (optional; 0 if missing) |
| 17 | # run/X.reals there if the program uses reals, which a target may |
| 18 | # leave out (report, appendix A); -noreals skips it |
| 19 | # err/X.raz a program the report says is an error, which must not |
| 20 | # compile; err/mods holds the modules it imports |
| 21 | # |
| 22 | # What a program says on standard error, the compiler's messages |
| 23 | # included, is the implementation's own (appendix A). One that keeps |
| 24 | # its text may give MESSAGES, a directory of X.stderr and X.err, the |
| 25 | # standard error of run/X and of compiling err/X, compared when there, |
| 26 | # with each address it shows, 0x and hex digits, as 0x?. |
| 27 | |
| 28 | noreals= |
| 29 | if [ "$1" = -noreals ]; then noreals=1; shift; fi |
| 30 | raz=$1 |
| 31 | msg=${2:-/nonexistent} |
| 32 | out=build/conform |
| 33 | mkdir -p $out |
| 34 | pass=0 |
| 35 | fail=0 |
| 36 | |
| 37 | for f in conform/run/*.raz; do |
| 38 | name=$(basename $f .raz) |
| 39 | [ -n "$noreals" ] && [ -f conform/run/$name.reals ] && continue |
| 40 | if ! $raz -I conform/run/mods -o $out/$name $f 2>$out/$name.cerr; then |
| 41 | echo "FAIL $f: doesn't compile: $(cat $out/$name.cerr)" |
| 42 | fail=$((fail + 1)); continue |
| 43 | fi |
| 44 | set -- |
| 45 | if [ -f conform/run/$name.args ]; then |
| 46 | while IFS= read -r a; do set -- "$@" "$a"; done < conform/run/$name.args |
| 47 | fi |
| 48 | # in $(...), so that what the shell says of a signal goes nowhere |
| 49 | status=$( { ( exec $out/$name "$@" ) > $out/$name.out 2>$out/$name.err; echo $?; } 2>/dev/null ) |
| 50 | want=0 |
| 51 | [ -f conform/run/$name.status ] && want=$(cat conform/run/$name.status) |
| 52 | if ! cmp -s $out/$name.out conform/run/$name.expect; then |
| 53 | echo "FAIL $f: output differs" |
| 54 | diff $out/$name.out conform/run/$name.expect | head -5 |
| 55 | fail=$((fail + 1)) |
| 56 | elif [ $status != $want ]; then |
| 57 | echo "FAIL $f: status $status, not $want" |
| 58 | fail=$((fail + 1)) |
| 59 | elif [ -f $msg/$name.stderr ] && ! sed 's/0x[0-9a-f]*/0x?/g' $out/$name.err | |
| 60 | cmp -s - $msg/$name.stderr; then |
| 61 | echo "FAIL $f: standard error differs" |
| 62 | diff $out/$name.err $msg/$name.stderr | head -5 |
| 63 | fail=$((fail + 1)) |
| 64 | else |
| 65 | pass=$((pass + 1)) |
| 66 | fi |
| 67 | done |
| 68 | |
| 69 | for f in conform/err/*.raz; do |
| 70 | name=$(basename $f .raz) |
| 71 | if $raz -I conform/err/mods -o $out/$name $f 2>$out/$name.cerr; then |
| 72 | echo "FAIL $f: compiles" |
| 73 | fail=$((fail + 1)) |
| 74 | elif [ -f $msg/$name.err ] && ! cmp -s $msg/$name.err $out/$name.cerr; then |
| 75 | echo "FAIL $f: says"; diff $msg/$name.err $out/$name.cerr |
| 76 | fail=$((fail + 1)) |
| 77 | else |
| 78 | pass=$((pass + 1)) |
| 79 | fi |
| 80 | done |
| 81 | |
| 82 | echo "$pass passed, $fail failed" |
| 83 | [ $fail = 0 ] |