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