blob: 96c2406fd79d88d004222af776f8d1910523b7f1 [file] [log] [blame]
Aaron Lee2355a4b2011-10-13 13:43:16 -05001#!/bin/bash
2
3function 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
22function 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
Aaron Lee78dbb642011-10-18 10:27:02 -050036base_dir=$(dirname $0)
Aaron Lee2355a4b2011-10-13 13:43:16 -050037venv=.kong-venv
Aaron Lee78dbb642011-10-18 10:27:02 -050038with_venv=../tools/with_venv.sh
Aaron Lee2355a4b2011-10-13 13:43:16 -050039always_venv=0
40never_venv=0
41force=0
42noseargs=
43wrapper=""
44just_pep8=0
45
46for arg in "$@"; do
47 process_option $arg
48done
49
50function run_tests {
51 # Just run the test suites in current environment
52 ${wrapper} $NOSETESTS 2> run_tests.err.log
53}
54
55function run_pep8 {
56 echo "Running pep8 ..."
57 PEP8_EXCLUDE=vcsversion.y
58 PEP8_OPTIONS="--exclude=$PEP8_EXCLUDE --repeat --show-pep8 --show-source"
59 PEP8_INCLUDE="tests tools run_tests.py"
60 ${wrapper} pep8 $PEP8_OPTIONS $PEP8_INCLUDE || exit 1
61}
62NOSETESTS="env python run_tests.py $noseargs"
Aaron Lee78dbb642011-10-18 10:27:02 -050063function setup_venv {
64 if [ $never_venv -eq 0 ]
65 then
66 # Remove the virtual environment if --force used
67 if [ $force -eq 1 ]; then
68 echo "Cleaning virtualenv..."
69 rm -rf ${venv}
70 fi
Brian Waldon3f6c9d52011-10-27 12:37:34 -040071 if [ -e "../${venv}" ]; then
Aaron Lee78dbb642011-10-18 10:27:02 -050072 wrapper="${with_venv}"
73 else
74 if [ $always_venv -eq 1 ]; then
75 # Automatically install the virtualenv
76 use_ve='y'
77 else
78 echo -e "No virtual environment found...create one? (Y/n) \c"
79 read use_ve
80 fi
81 if [ "x$use_ve" = "xY" -o "x$use_ve" = "x" -o "x$use_ve" = "xy" ]; then
82 # Install the virtualenv and run the test suite in it
83 env python ../tools/install_venv.py
84 wrapper=${with_venv}
85 fi
86 fi
Aaron Lee2355a4b2011-10-13 13:43:16 -050087 fi
Aaron Lee78dbb642011-10-18 10:27:02 -050088}
Aaron Lee2355a4b2011-10-13 13:43:16 -050089
90if [ $just_pep8 -eq 1 ]; then
91 run_pep8
92 exit
93fi
94
Aaron Lee78dbb642011-10-18 10:27:02 -050095cd $base_dir
96setup_venv
Aaron Lee2355a4b2011-10-13 13:43:16 -050097run_tests || exit