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@455 | 31 | TESTINPUT="_results/testinput.txt" |
paul@323 | 32 | |
paul@323 | 33 | # Make any required results directory. |
paul@323 | 34 | |
paul@455 | 35 | if [ "$OPTION" = '--build' ] || [ "$OPTION" = '--build-only' ] ; then |
paul@323 | 36 | if [ ! -e "_results" ]; then |
paul@323 | 37 | mkdir "_results" |
paul@323 | 38 | else |
paul@323 | 39 | rm "_results/"* |
paul@323 | 40 | fi |
paul@455 | 41 | |
paul@455 | 42 | cp "tests/testinput.txt" "$TESTINPUT" |
paul@323 | 43 | fi |
paul@323 | 44 | |
paul@455 | 45 | # If just running existing programs, do so now and exit. |
paul@455 | 46 | |
paul@455 | 47 | if [ "$OPTION" = '--run-built' ] ; then |
paul@455 | 48 | for FILENAME in _results/* ; do |
paul@455 | 49 | TESTNAME=`basename "$FILENAME"` |
paul@455 | 50 | |
paul@455 | 51 | # Skip non-program files. |
paul@455 | 52 | |
paul@455 | 53 | if [ ! -x "$FILENAME" ]; then |
paul@455 | 54 | continue |
paul@455 | 55 | fi |
paul@455 | 56 | |
paul@455 | 57 | echo "$FILENAME..." 1>&2 |
paul@455 | 58 | OUTLOG="_results/$TESTNAME.out" |
paul@455 | 59 | |
paul@455 | 60 | echo " (run)..." 1>&2 |
paul@455 | 61 | if ! "$FILENAME" > "$OUTLOG" < "$TESTINPUT" ; then |
paul@455 | 62 | exit 1 |
paul@455 | 63 | fi |
paul@455 | 64 | done |
paul@455 | 65 | |
paul@455 | 66 | exit 0 |
paul@455 | 67 | fi |
paul@331 | 68 | |
paul@323 | 69 | # Perform each test. |
paul@323 | 70 | |
paul@4 | 71 | for FILENAME in tests/* ; do |
paul@323 | 72 | TESTNAME=`basename "$FILENAME" .py` |
paul@4 | 73 | |
paul@4 | 74 | # Detect tests in their own subdirectories. |
paul@4 | 75 | |
paul@4 | 76 | if [ -d "$FILENAME" ] ; then |
paul@4 | 77 | if [ -e "$FILENAME/main.py" ] ; then |
paul@4 | 78 | FILENAME="$FILENAME/main.py" |
paul@4 | 79 | else |
paul@4 | 80 | continue |
paul@4 | 81 | fi |
paul@4 | 82 | fi |
paul@4 | 83 | |
paul@331 | 84 | # Skip non-program files. |
paul@331 | 85 | |
paul@331 | 86 | if [ `basename "$FILENAME"` = "$TESTNAME" ]; then |
paul@331 | 87 | continue |
paul@331 | 88 | fi |
paul@331 | 89 | |
paul@4 | 90 | # Run tests without an existing cache. |
paul@4 | 91 | |
paul@4 | 92 | echo "$FILENAME..." 1>&2 |
paul@442 | 93 | if ! "$LPLC" -c -r "$FILENAME" ; then |
paul@447 | 94 | if ! expect_failure ; then |
paul@275 | 95 | exit 1 |
paul@275 | 96 | else |
paul@275 | 97 | echo 1>&2 |
paul@275 | 98 | continue |
paul@275 | 99 | fi |
paul@275 | 100 | fi |
paul@39 | 101 | |
paul@39 | 102 | # Check for unresolved names in the cache. |
paul@39 | 103 | |
paul@39 | 104 | echo " (depends)..." 1>&2 |
paul@442 | 105 | for CACHEFILE in "$DATADIR/_cache/"* ; do |
paul@393 | 106 | STARTLINE=`grep -n '^deferred:' "$CACHEFILE" | cut -d: -f 1` |
paul@393 | 107 | if tail -n +$(($STARTLINE + 2)) "$CACHEFILE" | grep -q '<depends>' ; then |
paul@393 | 108 | echo "Unresolved names in the cache." 1>&2 |
paul@393 | 109 | exit 1 |
paul@393 | 110 | fi |
paul@393 | 111 | done |
paul@4 | 112 | |
paul@45 | 113 | # Check for type warnings in deduction output. |
paul@45 | 114 | |
paul@45 | 115 | echo " (warnings)..." 1>&2 |
paul@45 | 116 | if ! check_type_warnings ; then exit 1 ; fi |
paul@45 | 117 | |
paul@4 | 118 | # Run tests with an existing cache. |
paul@4 | 119 | |
paul@39 | 120 | echo " (cached)..." 1>&2 |
paul@442 | 121 | if ! "$LPLC" -c "$FILENAME" ; then exit 1 ; fi |
paul@4 | 122 | |
paul@45 | 123 | echo " (warnings)..." 1>&2 |
paul@45 | 124 | if ! check_type_warnings ; then exit 1 ; fi |
paul@45 | 125 | |
paul@323 | 126 | # Build and run if appropriate. |
paul@323 | 127 | |
paul@455 | 128 | if [ "$OPTION" = '--build' ] || [ "$OPTION" = "--build-only" ] ; then |
paul@323 | 129 | BUILDLOG="_results/$TESTNAME.build" |
paul@323 | 130 | OUTLOG="_results/$TESTNAME.out" |
paul@323 | 131 | |
paul@323 | 132 | echo " (build)..." 1>&2 |
paul@442 | 133 | if ! make -C "$DATADIR/_generated" clean > "$BUILDLOG" || \ |
paul@442 | 134 | ! make -C "$DATADIR/_generated" > "$BUILDLOG" ; then |
paul@323 | 135 | exit 1 |
paul@323 | 136 | fi |
paul@323 | 137 | |
paul@455 | 138 | if [ "$OPTION" = "--build-only" ]; then |
paul@455 | 139 | mv "$DATADIR/_generated/main" "_results/$TESTNAME" |
paul@455 | 140 | else |
paul@455 | 141 | echo " (run)..." 1>&2 |
paul@455 | 142 | if ! "$DATADIR/_generated/main" > "$OUTLOG" < "$TESTINPUT" ; then |
paul@455 | 143 | exit 1 |
paul@455 | 144 | fi |
paul@323 | 145 | fi |
paul@323 | 146 | fi |
paul@323 | 147 | |
paul@45 | 148 | echo 1>&2 |
paul@4 | 149 | done |