Lichen

Annotated test_all.sh

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