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 32 # Make any required results directory. 33 34 if [ "$OPTION" = '--build' ]; then 35 if [ ! -e "_results" ]; then 36 mkdir "_results" 37 else 38 rm "_results/"* 39 fi 40 fi 41 42 TESTINPUT="tests/testinput.txt" 43 44 # Perform each test. 45 46 for FILENAME in tests/* ; do 47 TESTNAME=`basename "$FILENAME" .py` 48 49 # Detect tests in their own subdirectories. 50 51 if [ -d "$FILENAME" ] ; then 52 if [ -e "$FILENAME/main.py" ] ; then 53 FILENAME="$FILENAME/main.py" 54 else 55 continue 56 fi 57 fi 58 59 # Skip non-program files. 60 61 if [ `basename "$FILENAME"` = "$TESTNAME" ]; then 62 continue 63 fi 64 65 # Run tests without an existing cache. 66 67 echo "$FILENAME..." 1>&2 68 if ! "$LPLC" -c -r "$FILENAME" ; then 69 if ! expect_failure ; then 70 exit 1 71 else 72 echo 1>&2 73 continue 74 fi 75 fi 76 77 # Check for unresolved names in the cache. 78 79 echo " (depends)..." 1>&2 80 for CACHEFILE in "$DATADIR/_cache/"* ; do 81 STARTLINE=`grep -n '^deferred:' "$CACHEFILE" | cut -d: -f 1` 82 if tail -n +$(($STARTLINE + 2)) "$CACHEFILE" | grep -q '<depends>' ; then 83 echo "Unresolved names in the cache." 1>&2 84 exit 1 85 fi 86 done 87 88 # Check for type warnings in deduction output. 89 90 echo " (warnings)..." 1>&2 91 if ! check_type_warnings ; then exit 1 ; fi 92 93 # Run tests with an existing cache. 94 95 echo " (cached)..." 1>&2 96 if ! "$LPLC" -c "$FILENAME" ; then exit 1 ; fi 97 98 echo " (warnings)..." 1>&2 99 if ! check_type_warnings ; then exit 1 ; fi 100 101 # Build and run if appropriate. 102 103 if [ "$OPTION" = '--build' ]; then 104 BUILDLOG="_results/$TESTNAME.build" 105 OUTLOG="_results/$TESTNAME.out" 106 107 echo " (build)..." 1>&2 108 if ! make -C "$DATADIR/_generated" clean > "$BUILDLOG" || \ 109 ! make -C "$DATADIR/_generated" > "$BUILDLOG" ; then 110 exit 1 111 fi 112 113 echo " (run)..." 1>&2 114 if ! "$DATADIR/_generated/main" > "$OUTLOG" < "$TESTINPUT" ; then 115 exit 1 116 fi 117 fi 118 119 echo 1>&2 120 done