1 #! /bin/sh 2 # vim:et:ft=sh:sts=2:sw=2 3 # 4 # shFlags unit test suite runner. 5 # 6 # This script runs all the unit tests that can be found, and generates a nice 7 # report of the tests. 8 9 MY_NAME=`basename $0` 10 MY_PATH=`dirname $0` 11 12 PREFIX='shflags_test_' 13 SHELLS='/bin/sh /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh' 14 TESTS='' 15 for test in ${PREFIX}[a-z]*.sh; do 16 TESTS="${TESTS} ${test}" 17 done 18 19 # load libraries 20 . ../lib/versions 21 . ./shflags_test_helpers 22 23 usage() 24 { 25 echo "usage: ${MY_NAME} [-e key=val ...] [-s shell(s)] [-t test(s)]" 26 } 27 28 env='' 29 30 # process command line flags 31 while getopts 'e:hs:t:' opt; do 32 case ${opt} in 33 e) # set an environment variable 34 key=`expr "${OPTARG}" : '\([^=]*\)='` 35 val=`expr "${OPTARG}" : '[^=]*=\(.*\)'` 36 if [ -z "${key}" -o -z "${val}" ]; then 37 usage 38 exit 1 39 fi 40 eval "${key}='${val}'" 41 export ${key} 42 env="${env:+${env} }${key}" 43 ;; 44 h) usage; exit 0 ;; # help output 45 s) shells=${OPTARG} ;; # list of shells to run 46 t) tests=${OPTARG} ;; # list of tests to run 47 *) usage; exit 1 ;; 48 esac 49 done 50 shift `expr ${OPTIND} - 1` 51 52 # fill shells and/or tests 53 shells=${shells:-${SHELLS}} 54 tests=${tests:-${TESTS}} 55 56 # error checking 57 if [ -z "${tests}" ]; then 58 th_error 'no tests found to run; exiting' 59 exit 1 60 fi 61 62 cat <<EOF 63 #------------------------------------------------------------------------------ 64 # System data 65 # 66 67 # test run info 68 shells="${shells}" 69 tests="${tests}" 70 EOF 71 for key in ${env}; do 72 eval "echo \"${key}=\$${key}\"" 73 done 74 echo 75 76 # output system data 77 echo "# system info" 78 echo "$ date" 79 date 80 81 echo "$ uname -mprsv" 82 uname -mprsv 83 84 # 85 # run tests 86 # 87 88 for shell in ${shells}; do 89 echo 90 91 cat <<EOF 92 93 #------------------------------------------------------------------------------ 94 # Running the test suite with ${shell} 95 # 96 EOF 97 # check for existance of shell 98 if [ ! -x ${shell} ]; then 99 th_warn "unable to run tests with the ${shell} shell" 100 continue 101 fi 102 103 shell_name=`basename ${shell}` 104 shell_version=`versions_shellVersion "${shell}"` 105 106 echo "shell name: ${shell_name}" 107 echo "shell version: ${shell_version}" 108 109 # execute the tests 110 for suite in ${tests}; do 111 suiteName=`expr "${suite}" : "${PREFIX}\(.*\).sh"` 112 echo 113 echo "--- Executing the '${suiteName}' test suite ---" 114 ( exec ${shell} ./${suite} 2>&1; ) 115 done 116 done 117