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 if grep '<depends>' -r "_cache" ; then 77 echo "Unresolved names in the cache." 1>&2 78 exit 1 79 fi 80 81 # Check for type warnings in deduction output. 82 83 echo " (warnings)..." 1>&2 84 if ! check_type_warnings ; then exit 1 ; fi 85 86 # Run tests with an existing cache. 87 88 echo " (cached)..." 1>&2 89 if ! ./lplc "$FILENAME" ; then exit 1 ; fi 90 91 echo " (warnings)..." 1>&2 92 if ! check_type_warnings ; then exit 1 ; fi 93 94 # Build and run if appropriate. 95 96 if [ "$OPTION" = '--build' ]; then 97 BUILDLOG="_results/$TESTNAME.build" 98 OUTLOG="_results/$TESTNAME.out" 99 100 echo " (build)..." 1>&2 101 if ! make -C _generated clean > "$BUILDLOG" || \ 102 ! make -C _generated > "$BUILDLOG" ; then 103 exit 1 104 fi 105 106 echo " (run)..." 1>&2 107 if ! "_generated/main" > "$OUTLOG" < "$TESTINPUT" ; then 108 exit 1 109 fi 110 fi 111 112 echo 1>&2 113 done