paul@4 | 1 | #!/bin/sh |
paul@4 | 2 | |
paul@442 | 3 | LPLC="./lplc" |
paul@442 | 4 | DATADIR="_lplc" |
paul@442 | 5 | |
paul@45 | 6 | # Expect failure from the "bad" tests. |
paul@45 | 7 | |
paul@45 | 8 | expect_failure() { |
paul@45 | 9 | return `echo "$FILENAME" | grep -q '_bad[._]'` |
paul@45 | 10 | } |
paul@45 | 11 | |
paul@45 | 12 | # Check deduction output for type warnings, indicating that the program contains |
paul@45 | 13 | # errors. |
paul@45 | 14 | |
paul@45 | 15 | check_type_warnings() { |
paul@45 | 16 | |
paul@442 | 17 | if [ -e "$DATADIR/_deduced/type_warnings" ] && \ |
paul@442 | 18 | [ `stat -c %s "$DATADIR/_deduced/type_warnings"` -ne 0 ] ; then |
paul@45 | 19 | |
paul@45 | 20 | echo "Type warnings in deduced information." 1>&2 |
paul@45 | 21 | return 1 |
paul@45 | 22 | fi |
paul@45 | 23 | |
paul@45 | 24 | return 0 |
paul@45 | 25 | } |
paul@45 | 26 | |
paul@45 | 27 | # Main program. |
paul@45 | 28 | |
paul@323 | 29 | OPTION=$1 |
paul@323 | 30 | |
paul@323 | 31 | # Make any required results directory. |
paul@323 | 32 | |
paul@323 | 33 | if [ "$OPTION" = '--build' ]; then |
paul@323 | 34 | if [ ! -e "_results" ]; then |
paul@323 | 35 | mkdir "_results" |
paul@323 | 36 | else |
paul@323 | 37 | rm "_results/"* |
paul@323 | 38 | fi |
paul@323 | 39 | fi |
paul@323 | 40 | |
paul@331 | 41 | TESTINPUT="tests/testinput.txt" |
paul@331 | 42 | |
paul@323 | 43 | # Perform each test. |
paul@323 | 44 | |
paul@4 | 45 | for FILENAME in tests/* ; do |
paul@323 | 46 | TESTNAME=`basename "$FILENAME" .py` |
paul@4 | 47 | |
paul@4 | 48 | # Detect tests in their own subdirectories. |
paul@4 | 49 | |
paul@4 | 50 | if [ -d "$FILENAME" ] ; then |
paul@4 | 51 | if [ -e "$FILENAME/main.py" ] ; then |
paul@4 | 52 | FILENAME="$FILENAME/main.py" |
paul@4 | 53 | else |
paul@4 | 54 | continue |
paul@4 | 55 | fi |
paul@4 | 56 | fi |
paul@4 | 57 | |
paul@331 | 58 | # Skip non-program files. |
paul@331 | 59 | |
paul@331 | 60 | if [ `basename "$FILENAME"` = "$TESTNAME" ]; then |
paul@331 | 61 | continue |
paul@331 | 62 | fi |
paul@331 | 63 | |
paul@4 | 64 | # Run tests without an existing cache. |
paul@4 | 65 | |
paul@4 | 66 | echo "$FILENAME..." 1>&2 |
paul@442 | 67 | if ! "$LPLC" -c -r "$FILENAME" ; then |
paul@275 | 68 | if ! expect_failure; then |
paul@275 | 69 | exit 1 |
paul@275 | 70 | else |
paul@275 | 71 | echo 1>&2 |
paul@275 | 72 | continue |
paul@275 | 73 | fi |
paul@275 | 74 | fi |
paul@39 | 75 | |
paul@39 | 76 | # Check for unresolved names in the cache. |
paul@39 | 77 | |
paul@39 | 78 | echo " (depends)..." 1>&2 |
paul@442 | 79 | for CACHEFILE in "$DATADIR/_cache/"* ; do |
paul@393 | 80 | STARTLINE=`grep -n '^deferred:' "$CACHEFILE" | cut -d: -f 1` |
paul@393 | 81 | if tail -n +$(($STARTLINE + 2)) "$CACHEFILE" | grep -q '<depends>' ; then |
paul@393 | 82 | echo "Unresolved names in the cache." 1>&2 |
paul@393 | 83 | exit 1 |
paul@393 | 84 | fi |
paul@393 | 85 | done |
paul@4 | 86 | |
paul@45 | 87 | # Check for type warnings in deduction output. |
paul@45 | 88 | |
paul@45 | 89 | echo " (warnings)..." 1>&2 |
paul@45 | 90 | if ! check_type_warnings ; then exit 1 ; fi |
paul@45 | 91 | |
paul@4 | 92 | # Run tests with an existing cache. |
paul@4 | 93 | |
paul@39 | 94 | echo " (cached)..." 1>&2 |
paul@442 | 95 | if ! "$LPLC" -c "$FILENAME" ; then exit 1 ; fi |
paul@4 | 96 | |
paul@45 | 97 | echo " (warnings)..." 1>&2 |
paul@45 | 98 | if ! check_type_warnings ; then exit 1 ; fi |
paul@45 | 99 | |
paul@323 | 100 | # Build and run if appropriate. |
paul@323 | 101 | |
paul@323 | 102 | if [ "$OPTION" = '--build' ]; then |
paul@323 | 103 | BUILDLOG="_results/$TESTNAME.build" |
paul@323 | 104 | OUTLOG="_results/$TESTNAME.out" |
paul@323 | 105 | |
paul@323 | 106 | echo " (build)..." 1>&2 |
paul@442 | 107 | if ! make -C "$DATADIR/_generated" clean > "$BUILDLOG" || \ |
paul@442 | 108 | ! make -C "$DATADIR/_generated" > "$BUILDLOG" ; then |
paul@323 | 109 | exit 1 |
paul@323 | 110 | fi |
paul@323 | 111 | |
paul@323 | 112 | echo " (run)..." 1>&2 |
paul@442 | 113 | if ! "$DATADIR/_generated/main" > "$OUTLOG" < "$TESTINPUT" ; then |
paul@323 | 114 | exit 1 |
paul@323 | 115 | fi |
paul@323 | 116 | fi |
paul@323 | 117 | |
paul@45 | 118 | echo 1>&2 |
paul@4 | 119 | done |