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