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 | |
Barry Warsaw | 34bbf00 | 2008-10-17 12:05:40 +0000 | [diff] [blame] | 25 | PYTHON="$PYTHON -bb" |
| 26 | |
Guido van Rossum | 5f7b087 | 2007-08-29 18:15:48 +0000 | [diff] [blame] | 27 | # Unset PYTHONPATH, just to be sure. |
| 28 | unset PYTHONPATH |
| 29 | |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 30 | # Create the output directory if necessary. |
| 31 | mkdir -p OUT |
| 32 | |
| 33 | # Empty the summary files. |
| 34 | >GOOD |
| 35 | >BAD |
| 36 | >SKIPPED |
| 37 | |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 38 | # Process flags (transparently pass these on to regrtest.py) |
| 39 | FLAGS="" |
| 40 | EXCEPT="" |
| 41 | while : |
| 42 | do |
| 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 |
| 50 | done |
Guido van Rossum | 5397039 | 2007-06-12 00:28:30 +0000 | [diff] [blame] | 51 | |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 52 | # Compute the list of tests to run. |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 53 | case "$#$EXCEPT" in |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 54 | 0) |
Guido van Rossum | 2bf7138 | 2007-06-08 00:07:57 +0000 | [diff] [blame] | 55 | TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//')` |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 56 | ;; |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 57 | *-x) |
| 58 | PAT="^(`echo $@ | sed 's/\.py//' | sed 's/ /|/'`)$" |
| 59 | TESTS=`(cd Lib/test; ls test_*.py | sed 's/\.py//' | egrep -v "$PAT")` |
| 60 | ;; |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 61 | *) |
| 62 | TESTS="$@" |
| 63 | ;; |
| 64 | esac |
| 65 | |
| 66 | # Run the tests. |
| 67 | for T in $TESTS |
| 68 | do |
| 69 | echo -n $T |
Guido van Rossum | 97a7f1e | 2007-07-26 18:43:46 +0000 | [diff] [blame] | 70 | if case $T in |
Guido van Rossum | a62b45c | 2007-08-22 21:46:00 +0000 | [diff] [blame] | 71 | *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 Rossum | 97a7f1e | 2007-07-26 18:43:46 +0000 | [diff] [blame] | 76 | esac |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 77 | then |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 78 | if grep -q "1 test skipped:" OUT/$T.out |
| 79 | then |
| 80 | echo " SKIPPED" |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 81 | echo $T >>SKIPPED |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 82 | else |
| 83 | echo |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 84 | echo $T >>GOOD |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 85 | fi |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 86 | else |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 87 | echo " BAD" |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 88 | echo $T >>BAD |
Guido van Rossum | e53309c | 2007-05-23 17:28:08 +0000 | [diff] [blame] | 89 | fi |
| 90 | done |
Guido van Rossum | 360f2f8 | 2007-08-20 20:17:57 +0000 | [diff] [blame] | 91 | |
| 92 | # Summarize results |
| 93 | wc -l BAD GOOD SKIPPED |