Aaron Lee | 2355a4b | 2011-10-13 13:43:16 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | function usage { |
| 4 | echo "Usage: $0 [OPTION]..." |
| 5 | echo "Run the Kong test suite(s)" |
| 6 | echo "" |
| 7 | echo " -V, --virtual-env Always use virtualenv. Install automatically if not present" |
| 8 | echo " -N, --no-virtual-env Don't use virtualenv. Run tests in local environment" |
| 9 | echo " -f, --force Force a clean re-build of the virtual environment. Useful when dependencies have been added." |
| 10 | echo " -p, --pep8 Just run pep8" |
Dolph Mathews | 4556a60 | 2011-11-13 21:03:08 -0600 | [diff] [blame] | 11 | echo " --nova Run all tests tagged as \"nova\"." |
| 12 | echo " --swift Run all tests tagged as \"swift\"." |
| 13 | echo " --glance Run all tests tagged as \"glance\"." |
| 14 | echo " --auth Run all tests tagged as \"auth\"." |
Aaron Lee | 2355a4b | 2011-10-13 13:43:16 -0500 | [diff] [blame] | 15 | echo " -h, --help Print this usage message" |
| 16 | echo "" |
| 17 | echo "Note: with no options specified, the script will try to run the tests in a virtual environment," |
| 18 | echo " If no virtualenv is found, the script will ask if you would like to create one. If you " |
| 19 | echo " prefer to run tests NOT in a virtual environment, simply pass the -N option." |
| 20 | exit |
| 21 | } |
| 22 | |
| 23 | function process_option { |
| 24 | case "$1" in |
| 25 | -h|--help) usage;; |
| 26 | -V|--virtual-env) let always_venv=1; let never_venv=0;; |
| 27 | -N|--no-virtual-env) let always_venv=0; let never_venv=1;; |
| 28 | -f|--force) let force=1;; |
| 29 | -p|--pep8) let just_pep8=1;; |
| 30 | --nova) noseargs="$noseargs -a tags=nova";; |
| 31 | --glance) noseargs="$noseargs -a tags=glance";; |
| 32 | --swift) noseargs="$noseargs -a tags=swift";; |
Dolph Mathews | 4556a60 | 2011-11-13 21:03:08 -0600 | [diff] [blame] | 33 | --auth) noseargs="$noseargs -a tags=auth";; |
Aaron Lee | 2355a4b | 2011-10-13 13:43:16 -0500 | [diff] [blame] | 34 | *) noseargs="$noseargs $1" |
| 35 | esac |
| 36 | } |
| 37 | |
Aaron Lee | 78dbb64 | 2011-10-18 10:27:02 -0500 | [diff] [blame] | 38 | base_dir=$(dirname $0) |
Aaron Lee | 2355a4b | 2011-10-13 13:43:16 -0500 | [diff] [blame] | 39 | venv=.kong-venv |
Aaron Lee | 78dbb64 | 2011-10-18 10:27:02 -0500 | [diff] [blame] | 40 | with_venv=../tools/with_venv.sh |
Aaron Lee | 2355a4b | 2011-10-13 13:43:16 -0500 | [diff] [blame] | 41 | always_venv=0 |
| 42 | never_venv=0 |
| 43 | force=0 |
| 44 | noseargs= |
| 45 | wrapper="" |
| 46 | just_pep8=0 |
| 47 | |
| 48 | for arg in "$@"; do |
| 49 | process_option $arg |
| 50 | done |
| 51 | |
| 52 | function run_tests { |
| 53 | # Just run the test suites in current environment |
| 54 | ${wrapper} $NOSETESTS 2> run_tests.err.log |
| 55 | } |
| 56 | |
| 57 | function run_pep8 { |
| 58 | echo "Running pep8 ..." |
| 59 | PEP8_EXCLUDE=vcsversion.y |
| 60 | PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source" |
| 61 | PEP8_INCLUDE="tests tools run_tests.py" |
| 62 | ${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE || exit 1 |
| 63 | } |
| 64 | NOSETESTS="env python run_tests.py $noseargs" |
Aaron Lee | 78dbb64 | 2011-10-18 10:27:02 -0500 | [diff] [blame] | 65 | function setup_venv { |
| 66 | if [ $never_venv -eq 0 ] |
| 67 | then |
| 68 | # Remove the virtual environment if --force used |
| 69 | if [ $force -eq 1 ]; then |
| 70 | echo "Cleaning virtualenv..." |
| 71 | rm -rf ${venv} |
| 72 | fi |
Brian Waldon | 3f6c9d5 | 2011-10-27 12:37:34 -0400 | [diff] [blame] | 73 | if [ -e "../${venv}" ]; then |
Aaron Lee | 78dbb64 | 2011-10-18 10:27:02 -0500 | [diff] [blame] | 74 | wrapper="${with_venv}" |
| 75 | else |
| 76 | if [ $always_venv -eq 1 ]; then |
| 77 | # Automatically install the virtualenv |
| 78 | use_ve='y' |
| 79 | else |
| 80 | echo -e "No virtual environment found...create one? (Y/n) \c" |
| 81 | read use_ve |
| 82 | fi |
| 83 | if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 84 | # Install the virtualenv and run the test suite in it |
| 85 | env python ../tools/install_venv.py |
| 86 | wrapper=${with_venv} |
| 87 | fi |
| 88 | fi |
Aaron Lee | 2355a4b | 2011-10-13 13:43:16 -0500 | [diff] [blame] | 89 | fi |
Aaron Lee | 78dbb64 | 2011-10-18 10:27:02 -0500 | [diff] [blame] | 90 | } |
Aaron Lee | 2355a4b | 2011-10-13 13:43:16 -0500 | [diff] [blame] | 91 | |
| 92 | if [ $just_pep8 -eq 1 ]; then |
| 93 | run_pep8 |
| 94 | exit |
| 95 | fi |
| 96 | |
Aaron Lee | 78dbb64 | 2011-10-18 10:27:02 -0500 | [diff] [blame] | 97 | cd $base_dir |
| 98 | setup_venv |
Aaron Lee | 2355a4b | 2011-10-13 13:43:16 -0500 | [diff] [blame] | 99 | run_tests || exit |