blob: d7b46467618526b49cf3607579f77c3e222b62c8 [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
Barry Warsaw34bbf002008-10-17 12:05:40 +000025PYTHON="$PYTHON -bb"
26
Guido van Rossum5f7b0872007-08-29 18:15:48 +000027# Unset PYTHONPATH, just to be sure.
28unset PYTHONPATH
29
Guido van Rossume53309c2007-05-23 17:28:08 +000030# Create the output directory if necessary.
31mkdir -p OUT
32
33# Empty the summary files.
34>GOOD
35>BAD
36>SKIPPED
37
Guido van Rossum360f2f82007-08-20 20:17:57 +000038# Process flags (transparently pass these on to regrtest.py)
39FLAGS=""
40EXCEPT=""
41while :
42do
43 case $1 in
44 -h|--h|-help|--help) echo "$HELP"; exit;;
45 --) FLAGS="$FLAGS $1"; shift; break;;
46 -x) EXCEPT="$1"; shift;;
47 -*) FLAGS="$FLAGS $1"; shift;;
48 *) break;;
49 esac
50done
Guido van Rossum53970392007-06-12 00:28:30 +000051
Guido van Rossume53309c2007-05-23 17:28:08 +000052# Compute the list of tests to run.
Guido van Rossum360f2f82007-08-20 20:17:57 +000053case "$#$EXCEPT" in
Guido van Rossume53309c2007-05-23 17:28:08 +0000540)
Guido van Rossum2bf71382007-06-08 00:07:57 +000055 TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//')`
Guido van Rossume53309c2007-05-23 17:28:08 +000056 ;;
Guido van Rossum360f2f82007-08-20 20:17:57 +000057*-x)
R. David Murrayb78b4892010-09-28 22:25:18 +000058 PAT="^(`echo $@ | sed 's/\.py//g' | sed 's/ /|/g'`)$"
Guido van Rossum360f2f82007-08-20 20:17:57 +000059 TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//' | egrep -v "$PAT")`
60 ;;
Guido van Rossume53309c2007-05-23 17:28:08 +000061*)
62 TESTS="$@"
63 ;;
64esac
65
66# Run the tests.
67for T in $TESTS
68do
69 echo -n $T
Guido van Rossum97a7f1e2007-07-26 18:43:46 +000070 if case $T in
Guido van Rossuma62b45c2007-08-22 21:46:00 +000071 *curses*)
72 echo
73 $PYTHON -E Lib/test/regrtest.py $FLAGS $T 2>OUT/$T.out
74 ;;
75 *) $PYTHON -E Lib/test/regrtest.py $FLAGS $T >OUT/$T.out 2>&1;;
Guido van Rossum97a7f1e2007-07-26 18:43:46 +000076 esac
Guido van Rossume53309c2007-05-23 17:28:08 +000077 then
Guido van Rossum360f2f82007-08-20 20:17:57 +000078 if grep -q "1 test skipped:" OUT/$T.out
79 then
80 echo " SKIPPED"
Guido van Rossume53309c2007-05-23 17:28:08 +000081 echo $T >>SKIPPED
Guido van Rossum360f2f82007-08-20 20:17:57 +000082 else
83 echo
Guido van Rossume53309c2007-05-23 17:28:08 +000084 echo $T >>GOOD
Guido van Rossum360f2f82007-08-20 20:17:57 +000085 fi
Guido van Rossume53309c2007-05-23 17:28:08 +000086 else
Guido van Rossum360f2f82007-08-20 20:17:57 +000087 echo " BAD"
Guido van Rossume53309c2007-05-23 17:28:08 +000088 echo $T >>BAD
Guido van Rossume53309c2007-05-23 17:28:08 +000089 fi
90done
Guido van Rossum360f2f82007-08-20 20:17:57 +000091
92# Summarize results
93wc -l BAD GOOD SKIPPED