runtests.sh 2.12 KB
Newer Older
1
#!/bin/bash
2

3 4 5 6 7 8 9 10 11 12 13 14 15 16
HELP="Usage: ./runtests.py [-h] [-x] [flags] [tests]

Runs each unit test independently, with output directed to a file in
OUT/<test>.out.  If no tests are given, all tests are run; otherwise,
only the specified tests are run, unless -x is also given, in which
case all tests *except* those given are run.

Standard output shows the name of the tests run, with 'BAD' or
'SKIPPED' added if the test didn't produce a positive result.  Also,
three files are created, named 'BAD', 'GOOD' and 'SKIPPED', to which
are written the names of the tests categorized by result.

Flags (arguments starting with '-') are passed transparently to
regrtest.py, except for -x, which is processed here."
17 18 19 20

# Choose the Python binary.
case `uname` in
Darwin) PYTHON=./python.exe;;
21
CYGWIN*) PYTHON=./python.exe;;
22 23 24
*)      PYTHON=./python;;
esac

25 26
PYTHON="$PYTHON -bb"

27 28 29
# Unset PYTHONPATH, just to be sure.
unset PYTHONPATH

30 31 32 33 34 35 36 37
# Create the output directory if necessary.
mkdir -p OUT

# Empty the summary files.
>GOOD
>BAD
>SKIPPED

38 39 40 41 42 43 44 45 46 47 48 49 50
# Process flags (transparently pass these on to regrtest.py)
FLAGS=""
EXCEPT=""
while :
do
    case $1 in
    -h|--h|-help|--help) echo "$HELP"; exit;;
    --) FLAGS="$FLAGS $1"; shift; break;;
    -x) EXCEPT="$1"; shift;;
    -*) FLAGS="$FLAGS $1"; shift;;
    *)  break;;
    esac
done
51

52
# Compute the list of tests to run.
53
case "$#$EXCEPT" in
54
0) 
55
    TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//')`
56
    ;;
57 58 59 60
*-x)
    PAT="^(`echo $@ | sed 's/\.py//' | sed 's/ /|/'`)$"
    TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//' | egrep -v "$PAT")`
    ;;
61 62 63 64 65 66 67 68 69
*)
    TESTS="$@"
    ;;
esac

# Run the tests.
for T in $TESTS
do
    echo -n $T
70
    if   case $T in
71 72 73 74 75
         *curses*)
	     echo
	     $PYTHON -E Lib/test/regrtest.py $FLAGS $T 2>OUT/$T.out
	     ;;
         *)  $PYTHON -E Lib/test/regrtest.py $FLAGS $T >OUT/$T.out 2>&1;;
76
         esac
77
    then
78 79 80
        if grep -q "1 test skipped:" OUT/$T.out
        then
            echo " SKIPPED"
81
            echo $T >>SKIPPED
82 83
        else
            echo
84
            echo $T >>GOOD
85
        fi
86
    else
87
        echo " BAD"
88 89 90
        echo $T >>BAD
    fi
done
91 92 93

# Summarize results
wc -l BAD GOOD SKIPPED