blob: f666fbd980056e1aeb9a74134cb97577a50a3c49 [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"
Dolph Mathews4556a602011-11-13 21:03:08 -060011 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 Lee2355a4b2011-10-13 13:43:16 -050015 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
23function 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 Mathews4556a602011-11-13 21:03:08 -060033 --auth) noseargs="$noseargs -a tags=auth";;
Aaron Lee2355a4b2011-10-13 13:43:16 -050034 *) noseargs="$noseargs $1"
35 esac
36}
37
Aaron Lee78dbb642011-10-18 10:27:02 -050038base_dir=$(dirname $0)
Aaron Lee2355a4b2011-10-13 13:43:16 -050039venv=.kong-venv
Aaron Lee78dbb642011-10-18 10:27:02 -050040with_venv=../tools/with_venv.sh
Aaron Lee2355a4b2011-10-13 13:43:16 -050041always_venv=0
42never_venv=0
43force=0
44noseargs=
45wrapper=""
46just_pep8=0
47
48for arg in "$@"; do
49 process_option $arg
50done
51
52function run_tests {
53 # Just run the test suites in current environment
54 ${wrapper} $NOSETESTS 2> run_tests.err.log
55}
56
57function 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}
64NOSETESTS="env python run_tests.py $noseargs"
Aaron Lee78dbb642011-10-18 10:27:02 -050065function 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 Waldon3f6c9d52011-10-27 12:37:34 -040073 if [ -e "../${venv}" ]; then
Aaron Lee78dbb642011-10-18 10:27:02 -050074 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 Lee2355a4b2011-10-13 13:43:16 -050089 fi
Aaron Lee78dbb642011-10-18 10:27:02 -050090}
Aaron Lee2355a4b2011-10-13 13:43:16 -050091
92if [ $just_pep8 -eq 1 ]; then
93 run_pep8
94 exit
95fi
96
Aaron Lee78dbb642011-10-18 10:27:02 -050097cd $base_dir
98setup_venv
Aaron Lee2355a4b2011-10-13 13:43:16 -050099run_tests || exit