test.sh 2.67 KB
Newer Older
1
#!/bin/bash
2 3 4 5 6

# This script checks that the code back-end, the table back-end, and the
# reference interpreter appear to be working correctly. It uses the calc
# demo for this purpose.

7
. ./config.sh
8

9
# Make sure Menhir and MenhirLib are up-to-date.
10
./build.sh || exit 1
11 12 13

# Build the parser with the code back-end and run it.
echo "Building and running (code)..."
POTTIER Francois's avatar
POTTIER Francois committed
14 15
make -C $CALC MENHIR="$MENHIR --trace" clean >/dev/null
make -C $CALC MENHIR="$MENHIR --trace"       >/dev/null
16
for f in $DATA/*.real.in ; do
17
  b=${f%.in}
18
  $CALC/calc < $f > $b.code.out 2> $b.code.err
19
done
20 21 22

# Build the parser with the table back-end and run it.
echo "Building and running (table)..."
POTTIER Francois's avatar
POTTIER Francois committed
23 24
make -C $CALC MENHIR="$MENHIR --trace --table" clean >/dev/null
make -C $CALC MENHIR="$MENHIR --trace --table"       >/dev/null
25
for f in $DATA/*.real.in ; do
26
  b=${f%.in}
27
  $CALC/calc < $f > $b.table.out 2> $b.table.err
28
done
29

30 31 32 33 34 35 36 37 38
# Build the parser with the table back-end (with --inspection) and run it.
echo "Building and running (inspection)..."
make -C $CALC MENHIR="$MENHIR --trace --table --inspection" clean >/dev/null
make -C $CALC MENHIR="$MENHIR --trace --table --inspection"       >/dev/null
for f in $DATA/*.real.in ; do
  b=${f%.in}
  $CALC/calc < $f > $b.inspection.out 2> $b.inspection.err
done

39 40
# Run the reference interpreter.
echo "Running the reference interpreter..."
41
for f in $DATA/*.ideal.in ; do
42
  b=${f%.in}
43
  $MENHIR --trace --interpret $CALC/parser.mly < $f > $b.interpret.out 2> $b.interpret.err
44
done
45 46 47

echo "Comparing results..."

48
# Compare the results to the reference.
49
for f in $DATA/*.real.in ; do
50
  b=${f%.in}
51
  for mode in code table inspection ; do
52
    echo "($b) Checking output of $mode parser..."
53
    if ! diff -q $b.ref.out $b.$mode.out >/dev/null ; then
54
      echo "($b) The $mode parser produces a wrong result!"
55 56 57 58 59
      echo "Expected:"
      cat $b.ref.out
      echo "Got:"
      cat $b.$mode.out
    fi
60 61 62 63 64
    echo "($b) Checking trace of $mode parser..."
    if ! diff -q $b.ref.err $b.$mode.err >/dev/null ; then
      echo "($b) The $mode parser produces a wrong trace!"
      diff $b.ref.err $b.$mode.err
    fi
65
  done
66 67 68
done

# Check the results of the reference interpreter.
69
for f in $DATA/*.ideal.in ; do
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
  b=${f%.in}
  echo "($b) Checking output of reference interpreter..."
  if ! diff -q $b.ref.out $b.interpret.out >/dev/null ; then
    echo "The reference interpreter produces a wrong result!"
    echo "Expected:"
    cat $b.ref.out
    echo "Got:"
    cat $b.interpret.out
  fi
  echo "($b) Checking trace of reference interpreter..."
  if ! diff -q $b.ref.err $b.interpret.err >/dev/null ; then
    echo "The reference interpreter produces a wrong trace!"
    diff $b.ref.err $b.interpret.err
  fi
done
85 86

echo "Done."