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