aboutsummaryrefslogtreecommitdiff
path: root/bin/gen_test_results.sh
diff options
context:
space:
mode:
authorKate Ward <kate.ward@forestent.com>2016-01-10 16:53:04 +0100
committerKate Ward <kate.ward@forestent.com>2016-01-10 16:53:04 +0100
commit4b66ecdc0d3f6b89d3132b75f5aca1773a29a1a3 (patch)
tree9668b6e23a484f660f25ff34c98876db0276ffe6 /bin/gen_test_results.sh
parentb11509fad7f5e9e66a734116fcec7c418419ee1f (diff)
downloadshflags-4b66ecdc0d3f6b89d3132b75f5aca1773a29a1a3.tar.gz
restructured source for GitHub
Diffstat (limited to 'bin/gen_test_results.sh')
-rwxr-xr-xbin/gen_test_results.sh88
1 files changed, 88 insertions, 0 deletions
diff --git a/bin/gen_test_results.sh b/bin/gen_test_results.sh
new file mode 100755
index 0000000..79d2fd4
--- /dev/null
+++ b/bin/gen_test_results.sh
@@ -0,0 +1,88 @@
+#! /bin/sh
+# $Id$
+# vim:et:ft=sh:sts=2:sw=2
+#
+# Copyright 2008 Kate Ward. All Rights Reserved.
+# Released under the LGPL (GNU Lesser General Public License)
+#
+# Author: kate.ward@forestent.com (Kate Ward)
+#
+# This script runs the provided unit tests and sends the output to the
+# appropriate file.
+#
+
+# treat unset variables as an error
+set -u
+
+die()
+{
+ [ $# -gt 0 ] && echo "error: $@" >&2
+ exit 1
+}
+
+BASE_DIR="`dirname $0`/.."
+LIB_DIR="${BASE_DIR}/lib"
+
+# load libraries
+. ${LIB_DIR}/shflags || die 'unable to load shflags library'
+. ${LIB_DIR}/shlib || die 'unable to load shlib library'
+. ${LIB_DIR}/versions || die 'unable to load versions library'
+
+# redefining BASE_DIR now that we have the shlib functions
+BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"`
+BIN_DIR="${BASE_DIR}/bin"
+SRC_DIR="${BASE_DIR}/src"
+
+os_name=`versions_osName |sed 's/ /_/g'`
+os_version=`versions_osVersion`
+
+# load external flags
+. ${BIN_DIR}/gen_test_results.flags
+
+# define flags
+DEFINE_boolean force false 'force overwrite' f
+DEFINE_string output_dir "`pwd`" 'output dir' d
+DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o
+DEFINE_boolean dry_run false "supress logging to a file" n
+
+main()
+{
+ # determine output filename
+ output="${FLAGS_output_dir:+${FLAGS_output_dir}/}${FLAGS_output_file}"
+ output=`shlib_relToAbsPath "${output}"`
+
+ # checks
+ [ -n "${FLAGS_suite:-}" ] || die 'suite flag missing'
+
+ if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} -a -f "${output}" ]; then
+ if [ ${FLAGS_force} -eq ${FLAGS_TRUE} ]; then
+ rm -f "${output}"
+ else
+ echo "not overwriting '${output}'" >&2
+ exit ${FLAGS_ERROR}
+ fi
+ fi
+ if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
+ touch "${output}" 2>/dev/null || die "unable to write to '${output}'"
+ fi
+
+ # run tests
+ (
+ cd "${SRC_DIR}";
+ if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
+ ./${FLAGS_suite} |tee "${output}"
+ else
+ ./${FLAGS_suite}
+ fi
+ )
+
+ if [ ! ${FLAGS_dry_run} ]; then
+ echo >&2
+ echo "output written to '${output}'" >&2
+ fi
+}
+
+FLAGS "$@" || exit $?
+[ ${FLAGS_help} -eq ${FALSE} ] || exit
+eval set -- "${FLAGS_ARGV}"
+main "$@"