Guido van Rossum | f7ec7a8 | 2008-01-12 19:47:54 +0000 | [diff] [blame] | 1 | #!/bin/bash |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 2 | |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 3 | HELP="Usage: ./runtests.py [-h] [-x] [flags] [tests] |
| 4 | |
| 5 | Runs each unit test independently, with output directed to a file in |
| 6 | OUT/<test>.out. If no tests are given, all tests are run; otherwise, |
| 7 | only the specified tests are run, unless -x is also given, in which |
| 8 | case all tests *except* those given are run. |
| 9 | |
| 10 | Standard output shows the name of the tests run, with 'BAD' or |
| 11 | 'SKIPPED' added if the test didn't produce a positive result. Also, |
| 12 | three files are created, named 'BAD', 'GOOD' and 'SKIPPED', to which |
| 13 | are written the names of the tests categorized by result. |
| 14 | |
| 15 | Flags (arguments starting with '-') are passed transparently to |
| 16 | regrtest.py, except for -x, which is processed here." |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 17 | |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 18 | # Choose the Python binary. |
| 19 | case `uname` in |
| 20 | Darwin) PYTHON=./python.exe;; |
Guido van Rossum | 5ed317d | 2007-07-18 16:59:11 +0000 | [diff] [blame] | 21 | CYGWIN*) PYTHON=./python.exe;; |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 22 | *) PYTHON=./python;; |
| 23 | esac |
| 24 | |
Guido van Rossum | 5f7b087 | 2007-08-29 18:15:48 +0000 | [diff] [blame] | 25 | # Unset PYTHONPATH, just to be sure. |
| 26 | unset PYTHONPATH |
| 27 | |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 28 | # Create the output directory if necessary. |
| 29 | mkdir -p OUT |
| 30 | |
| 31 | # Empty the summary files. |
| 32 | >GOOD |
| 33 | >BAD |
| 34 | >SKIPPED |
| 35 | |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 36 | # Process flags (transparently pass these on to regrtest.py) |
| 37 | FLAGS="" |
| 38 | EXCEPT="" |
| 39 | while : |
| 40 | do |
| 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 |
| 48 | done |
Guido van Rossum | 5397039 | 2007-06-12 00:28:30 +0000 | [diff] [blame] | 49 | |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 50 | # Compute the list of tests to run. |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 51 | case "$#$EXCEPT" in |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 52 | 0) |
Guido van Rossum | 2bf7138 | 2007-06-08 00:07:57 +0000 | [diff] [blame] | 53 | TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//')` |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 54 | ;; |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 55 | *-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 Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 59 | *) |
| 60 | TESTS="$@" |
| 61 | ;; |
| 62 | esac |
| 63 | |
| 64 | # Run the tests. |
| 65 | for T in $TESTS |
| 66 | do |
| 67 | echo -n $T |
Guido van Rossum | 97a7f1e | 2007-07-26 18:43:46 +0000 | [diff] [blame] | 68 | if case $T in |
Guido van Rossum | a62b45c | 2007-08-22 21:46:00 +0000 | [diff] [blame] | 69 | *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 Rossum | 97a7f1e | 2007-07-26 18:43:46 +0000 | [diff] [blame] | 74 | esac |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 75 | then |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 76 | if grep -q "1 test skipped:" OUT/$T.out |
| 77 | then |
| 78 | echo " SKIPPED" |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 79 | echo $T >>SKIPPED |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 80 | else |
| 81 | echo |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 82 | echo $T >>GOOD |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 83 | fi |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 84 | else |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 85 | echo " BAD" |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 86 | echo $T >>BAD |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 87 | fi |
| 88 | done |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 89 | |
| 90 | # Summarize results |
| 91 | wc -l BAD GOOD SKIPPED |