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