aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2017-10-17 23:27:49 +0200
committerKate Ward <kate.ward@forestent.com>2017-10-17 23:27:49 +0200
commit0fcacd13accb5cd0e2aac61b6a527e7706842154 (patch)
treec00532a276cf1c76a740d8e84158aaeb9110ccdc
parent9d30fb6172c635b269e466a4ba7280f201310d26 (diff)
downloadshflags-0fcacd13accb5cd0e2aac61b6a527e7706842154.tar.gz
Upgraded test_runner to latest from kward/shlib.
-rwxr-xr-xtest_runner72
1 files changed, 46 insertions, 26 deletions
diff --git a/test_runner b/test_runner
index f7bbae9..64065a8 100755
--- a/test_runner
+++ b/test_runner
@@ -7,23 +7,41 @@
# Released under the Apache 2.0 license.
#
# Author: kate.ward@forestent.com (Kate Ward)
-# https://github.com/kward/shunit2
+# https://github.com/kward/shlib
#
# This script runs all the unit tests that can be found, and generates a nice
# report of the tests.
+#
+### ShellCheck (http://www.shellcheck.net/)
+# Disable source following.
+# shellcheck disable=SC1090,SC1091
+# expr may be antiquated, but it is the only solution in some cases.
+# shellcheck disable=SC2003
-BASENAME=`basename "$0"`
+BASENAME=$(basename "$0")
SHELLS="${SHELLS:-/bin/sh ash /bin/bash /bin/dash /bin/ksh /bin/pdksh /bin/zsh}"
-TESTS=`echo *_test.sh`
+# shellcheck disable=SC2035
+TESTS=$(echo *_test.sh)
-die() { [ $# -gt 0 ] && echo $@ >&2; exit 1; }
+runner_die() { [ $# -gt 0 ] && echo "$@" >&2; exit 1; }
-usage() {
+runner_usage() {
echo "usage: ${BASENAME} [-e key=val ...] [-s shell(s)] [-t test(s)]"
}
-# Load libraries.
-. ${LIB_DIR:-lib}/versions || die 'Unable to load versions library.'
+runner_warn() { echo "runner:WARN $*" >&2; }
+
+# Find versions library.
+for d in . ${LIB_DIR:-lib}; do
+ if [ -r "${d}/versions" ]; then
+ lib_dir="${d}"
+ break
+ fi
+done
+[ -n "${lib_dir}" ] || runner_die 'Unable to find versions library.'
+
+### Load libraries.
+. "${lib_dir}/versions" || runner_die 'Unable to load versions library.'
env=''
@@ -31,23 +49,24 @@ env=''
while getopts 'e:hs:t:' opt; do
case ${opt} in
e) # set an environment variable
- key=`expr "${OPTARG}" : '\([^=]*\)='`
- val=`expr "${OPTARG}" : '[^=]*=\(.*\)'`
+ key=$(expr "${OPTARG}" : '\([^=]*\)=')
+ val=$(expr "${OPTARG}" : '[^=]*=\(.*\)')
+ # shellcheck disable=SC2166
if [ -z "${key}" -o -z "${val}" ]; then
- usage
+ runner_usage
exit 1
fi
eval "${key}='${val}'"
- export ${key}
+ eval "export ${key}"
env="${env:+${env} }${key}"
;;
- h) usage; exit 0 ;; # help output
+ h) runner_usage; exit 0 ;; # help output
s) shells=${OPTARG} ;; # list of shells to run
t) tests=${OPTARG} ;; # list of tests to run
- *) usage; exit 1 ;;
+ *) runner_usage; exit 1 ;;
esac
done
-shift `expr ${OPTIND} - 1`
+shift "$(expr ${OPTIND} - 1)"
# Fill shells and/or tests.
shells=${shells:-${SHELLS}}
@@ -65,10 +84,10 @@ cat <<EOF
#
$ uname -mprsv
-`uname -mprsv`
+$(uname -mprsv)
-OS Name: `versions_osName`
-OS Version: `versions_osVersion`
+OS Name: $(versions_osName)
+OS Version: $(versions_osVersion)
### Test run info.
shells: ${shells}
@@ -95,31 +114,32 @@ EOF
shell_present=${FALSE}
case ${shell} in
ash)
- shell_bin=`which busybox`
- [ $? -eq ${TRUE} ] && shell_present=${TRUE}
+ shell_bin=$(which busybox)
+ [ $? -eq "${TRUE}" ] && shell_present="${TRUE}"
shell_bin="${shell_bin} ash"
shell_name=${shell}
;;
*)
- [ -x "${shell_bin}" ] && shell_present=${TRUE}
- shell_name=`basename ${shell}`
+ [ -x "${shell_bin}" ] && shell_present="${TRUE}"
+ shell_name=$(basename "${shell}")
;;
esac
- if [ ${shell_present} -eq ${FALSE} ]; then
- th_warn "unable to run tests with the ${shell_name} shell"
+ if [ "${shell_present}" -eq "${FALSE}" ]; then
+ runner_warn "unable to run tests with the ${shell_name} shell"
continue
fi
- shell_version=`versions_shellVersion "${shell}"`
+ shell_version=$(versions_shellVersion "${shell}")
echo "shell name: ${shell_name}"
echo "shell version: ${shell_version}"
# Execute the tests.
for suite in ${tests}; do
- suiteName=`expr "${suite}" : "${TESTS_PREFIX}\(.*\).sh"`
+ # shellcheck disable=SC1117
+ suiteName=$(expr "${suite}" : "${TESTS_PREFIX}\(.*\).sh")
echo
echo "--- Executing the '${suiteName}' test suite. ---"
- ( exec ${shell_bin} ./${suite} 2>&1; )
+ ( exec "${shell_bin}" "./${suite}" 2>&1; )
done
done