Justin Shepherd | 0d9bbd1 | 2011-08-11 12:57:44 -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" |
| 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 " -h, --help Print this usage message" |
| 15 | echo "" |
| 16 | echo "Note: with no options specified, the script will try to run the tests in a virtual environment," |
| 17 | echo " If no virtualenv is found, the script will ask if you would like to create one. If you " |
| 18 | echo " prefer to run tests NOT in a virtual environment, simply pass the -N option." |
| 19 | exit |
| 20 | } |
| 21 | |
| 22 | function process_option { |
| 23 | case "$1" in |
| 24 | -h|--help) usage;; |
| 25 | -V|--virtual-env) let always_venv=1; let never_venv=0;; |
| 26 | -N|--no-virtual-env) let always_venv=0; let never_venv=1;; |
| 27 | -f|--force) let force=1;; |
| 28 | -p|--pep8) let just_pep8=1;; |
| 29 | --nova) noseargs="$noseargs -a tags=nova";; |
| 30 | --glance) noseargs="$noseargs -a tags=glance";; |
| 31 | --swift) noseargs="$noseargs -a tags=swift";; |
| 32 | *) noseargs="$noseargs $1" |
| 33 | esac |
| 34 | } |
| 35 | |
| 36 | venv=.kong-venv |
| 37 | with_venv=tools/with_venv.sh |
| 38 | always_venv=0 |
| 39 | never_venv=0 |
| 40 | force=0 |
| 41 | noseargs= |
| 42 | wrapper="" |
| 43 | just_pep8=0 |
| 44 | |
| 45 | for arg in "$@"; do |
| 46 | process_option $arg |
| 47 | done |
| 48 | |
| 49 | function run_tests { |
| 50 | # Just run the test suites in current environment |
| 51 | ${wrapper} $NOSETESTS 2> run_tests.err.log |
| 52 | } |
| 53 | |
| 54 | function run_pep8 { |
| 55 | echo "Running pep8 ..." |
| 56 | PEP8_EXCLUDE=vcsversion.y |
| 57 | PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source" |
| 58 | PEP8_INCLUDE="tests tools run_tests.py" |
| 59 | ${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE || exit 1 |
| 60 | } |
| 61 | NOSETESTS="env python run_tests.py $noseargs" |
| 62 | |
| 63 | if [ $never_venv -eq 0 ] |
| 64 | then |
| 65 | # Remove the virtual environment if --force used |
| 66 | if [ $force -eq 1 ]; then |
| 67 | echo "Cleaning virtualenv..." |
| 68 | rm -rf ${venv} |
| 69 | fi |
| 70 | if [ -e ${venv} ]; then |
| 71 | wrapper="${with_venv}" |
| 72 | else |
| 73 | if [ $always_venv -eq 1 ]; then |
| 74 | # Automatically install the virtualenv |
| 75 | env python tools/install_venv.py |
| 76 | wrapper="${with_venv}" |
| 77 | else |
| 78 | echo -e "No virtual environment found...create one? (Y/n) \c" |
| 79 | read use_ve |
| 80 | if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then |
| 81 | # Install the virtualenv and run the test suite in it |
| 82 | env python tools/install_venv.py |
| 83 | wrapper=${with_venv} |
| 84 | fi |
| 85 | fi |
| 86 | fi |
| 87 | fi |
| 88 | |
| 89 | if [ $just_pep8 -eq 1 ]; then |
| 90 | run_pep8 |
| 91 | exit |
| 92 | fi |
| 93 | |
| 94 | run_tests || exit |