2 # $Id: shunit2_test.sh 322 2011-04-24 00:09:45Z kate.ward@forestent.com $
3 # vim:et:ft=sh:sts=2:sw=2
5 # Copyright 2008 Kate Ward. All Rights Reserved.
6 # Released under the LGPL (GNU Lesser General Public License)
7 # Author: kate.ward@forestent.com (Kate Ward)
9 # shUnit2 unit test suite runner.
11 # This script runs all the unit tests that can be found, and generates a nice
12 # report of the tests.
17 PREFIX='shunit2_test_'
18 SHELLS='/bin/sh /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh'
20 for test in ${PREFIX}[a-z]*.sh; do
21 TESTS="${TESTS} ${test}"
24 # load common unit test functions
26 . ./shunit2_test_helpers
30 echo "usage: ${MY_NAME} [-e key=val ...] [-s shell(s)] [-t test(s)]"
35 # process command line flags
36 while getopts 'e:hs:t:' opt; do
38 e) # set an environment variable
39 key=`expr "${OPTARG}" : '\([^=]*\)='`
40 val=`expr "${OPTARG}" : '[^=]*=\(.*\)'`
41 if [ -z "${key}" -o -z "${val}" ]; then
45 eval "${key}='${val}'"
47 env="${env:+${env} }${key}"
49 h) usage; exit 0 ;; # output help
50 s) shells=${OPTARG} ;; # list of shells to run
51 t) tests=${OPTARG} ;; # list of tests to run
55 shift `expr ${OPTIND} - 1`
57 # fill shells and/or tests
58 shells=${shells:-${SHELLS}}
59 tests=${tests:-${TESTS}}
62 if [ -z "${tests}" ]; then
63 th_error 'no tests found to run; exiting'
68 #------------------------------------------------------------------------------
77 eval "echo \"${key}=\$${key}\""
94 for shell in ${shells}; do
97 # check for existance of shell
98 if [ ! -x ${shell} ]; then
99 th_warn "unable to run tests with the ${shell} shell"
105 #------------------------------------------------------------------------------
106 # Running the test suite with ${shell}
110 SHUNIT_SHELL=${shell} # pass shell onto tests
111 shell_name=`basename ${shell}`
112 shell_version=`versions_shellVersion "${shell}"`
114 echo "shell name: ${shell_name}"
115 echo "shell version: ${shell_version}"
118 for suite in ${tests}; do
119 suiteName=`expr "${suite}" : "${PREFIX}\(.*\).sh"`
121 echo "--- Executing the '${suiteName}' test suite ---"
122 ( exec ${shell} ./${suite} 2>&1; )