blob: 93ef83303c9b6d06f8445705c3ecb1284b58d43e [file] [log] [blame]
Guido van Rossumf7ec7a82008-01-12 19:47:54 +00001#!/bin/bash
Guido van Rossume53309c2007-05-23 17:28:08 +00002
Guido van Rossum360f2f82007-08-20 20:17:57 +00003HELP="Usage: ./runtests.py [-h] [-x] [flags] [tests]
4
5Runs each unit test independently, with output directed to a file in
6OUT/<test>.out. If no tests are given, all tests are run; otherwise,
7only the specified tests are run, unless -x is also given, in which
8case all tests *except* those given are run.
9
10Standard output shows the name of the tests run, with 'BAD' or
11'SKIPPED' added if the test didn't produce a positive result. Also,
12three files are created, named 'BAD', 'GOOD' and 'SKIPPED', to which
13are written the names of the tests categorized by result.
14
15Flags (arguments starting with '-') are passed transparently to
16regrtest.py, except for -x, which is processed here."
Guido van Rossume53309c2007-05-23 17:28:08 +000017
Guido van Rossume53309c2007-05-23 17:28:08 +000018# Choose the Python binary.
19case `uname` in
20Darwin) PYTHON=./python.exe;;
Guido van Rossum5ed317d2007-07-18 16:59:11 +000021CYGWIN*) PYTHON=./python.exe;;
Guido van Rossume53309c2007-05-23 17:28:08 +000022*) PYTHON=./python;;
23esac
24
Guido van Rossum5f7b0872007-08-29 18:15:48 +000025# Unset PYTHONPATH, just to be sure.
26unset PYTHONPATH
27
Guido van Rossume53309c2007-05-23 17:28:08 +000028# Create the output directory if necessary.
29mkdir -p OUT
30
31# Empty the summary files.
32>GOOD
33>BAD
34>SKIPPED
35
Guido van Rossum360f2f82007-08-20 20:17:57 +000036# Process flags (transparently pass these on to regrtest.py)
37FLAGS=""
38EXCEPT=""
39while :
40do
41 case $1 in
42 -h|--h|-help|--help) echo "$HELP"; exit;;
43 --) FLAGS="$FLAGS $1"; shift; break;;
44 -x) EXCEPT="$1"; shift;;
45 -*) FLAGS="$FLAGS $1"; shift;;
46 *) break;;
47 esac
48done
Guido van Rossum53970392007-06-12 00:28:30 +000049
Guido van Rossume53309c2007-05-23 17:28:08 +000050# Compute the list of tests to run.
Guido van Rossum360f2f82007-08-20 20:17:57 +000051case "$#$EXCEPT" in
Guido van Rossume53309c2007-05-23 17:28:08 +0000520)
Guido van Rossum2bf71382007-06-08 00:07:57 +000053 TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//')`
Guido van Rossume53309c2007-05-23 17:28:08 +000054 ;;
Guido van Rossum360f2f82007-08-20 20:17:57 +000055*-x)
56 PAT="^(`echo $@ | sed 's/\.py//' | sed 's/ /|/'`)$"
57 TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//' | egrep -v "$PAT")`
58 ;;
Guido van Rossume53309c2007-05-23 17:28:08 +000059*)
60 TESTS="$@"
61 ;;
62esac
63
64# Run the tests.
65for T in $TESTS
66do
67 echo -n $T
Guido van Rossum97a7f1e2007-07-26 18:43:46 +000068 if case $T in
Guido van Rossuma62b45c2007-08-22 21:46:00 +000069 *curses*)
70 echo
71 $PYTHON -E Lib/test/regrtest.py $FLAGS $T 2>OUT/$T.out
72 ;;
73 *) $PYTHON -E Lib/test/regrtest.py $FLAGS $T >OUT/$T.out 2>&1;;
Guido van Rossum97a7f1e2007-07-26 18:43:46 +000074 esac
Guido van Rossume53309c2007-05-23 17:28:08 +000075 then
Guido van Rossum360f2f82007-08-20 20:17:57 +000076 if grep -q "1 test skipped:" OUT/$T.out
77 then
78 echo " SKIPPED"
Guido van Rossume53309c2007-05-23 17:28:08 +000079 echo $T >>SKIPPED
Guido van Rossum360f2f82007-08-20 20:17:57 +000080 else
81 echo
Guido van Rossume53309c2007-05-23 17:28:08 +000082 echo $T >>GOOD
Guido van Rossum360f2f82007-08-20 20:17:57 +000083 fi
Guido van Rossume53309c2007-05-23 17:28:08 +000084 else
Guido van Rossum360f2f82007-08-20 20:17:57 +000085 echo " BAD"
Guido van Rossume53309c2007-05-23 17:28:08 +000086 echo $T >>BAD
Guido van Rossume53309c2007-05-23 17:28:08 +000087 fi
88done
Guido van Rossum360f2f82007-08-20 20:17:57 +000089
90# Summarize results
91wc -l BAD GOOD SKIPPED