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 9MY_NAME=`basename $0` 10MY_PATH=`dirname $0` 11 12PREFIX='shflags_test_' 13SHELLS='/bin/sh /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh' 14TESTS='' 15for test in ${PREFIX}[a-z]*.sh; do 16 TESTS="${TESTS} ${test}" 17done 18 19# load libraries 20. ../lib/versions 21. ./shflags_test_helpers 22 23usage() 24{ 25 echo "usage: ${MY_NAME} [-e key=val ...] [-s shell(s)] [-t test(s)]" 26} 27 28env='' 29 30# process command line flags 31while 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 49done 50shift `expr ${OPTIND} - 1` 51 52# fill shells and/or tests 53shells=${shells:-${SHELLS}} 54tests=${tests:-${TESTS}} 55 56# error checking 57if [ -z "${tests}" ]; then 58 th_error 'no tests found to run; exiting' 59 exit 1 60fi 61 62cat <<EOF 63#------------------------------------------------------------------------------ 64# System data 65# 66 67# test run info 68shells="${shells}" 69tests="${tests}" 70EOF 71for key in ${env}; do 72 eval "echo \"${key}=\$${key}\"" 73done 74echo 75 76# output system data 77echo "# system info" 78echo "$ date" 79date 80 81echo "$ uname -mprsv" 82uname -mprsv 83 84# 85# run tests 86# 87 88for shell in ${shells}; do 89 echo 90 91 cat <<EOF 92 93#------------------------------------------------------------------------------ 94# Running the test suite with ${shell} 95# 96EOF 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 116done 117