blob: e738d4ca0e6b81284dbdd407b645621b245bd135 [file] [log] [blame]
kate.ward2f3cad92008-10-21 23:29:23 +00001#! /bin/sh
kate.ward2f3cad92008-10-21 23:29:23 +00002# vim:et:ft=sh:sts=2:sw=2
3#
kate.ward2f3cad92008-10-21 23:29:23 +00004# This script runs the provided unit tests and sends the output to the
5# appropriate file.
kate.ward2f3cad92008-10-21 23:29:23 +00006
7# treat unset variables as an error
8set -u
9
10die()
11{
12 [ $# -gt 0 ] && echo "error: $@" >&2
13 exit 1
14}
15
kate.ward2f3cad92008-10-21 23:29:23 +000016BASE_DIR="`dirname $0`/.."
kate.ward2f3cad92008-10-21 23:29:23 +000017LIB_DIR="${BASE_DIR}/lib"
kate.ward2f3cad92008-10-21 23:29:23 +000018
19# load libraries
kate.warde7ed70c2011-06-10 11:45:17 +000020. ${LIB_DIR}/shflags || die 'unable to load shflags library'
21. ${LIB_DIR}/shlib || die 'unable to load shlib library'
kate.ward2f3cad92008-10-21 23:29:23 +000022. ${LIB_DIR}/versions || die 'unable to load versions library'
23
kate.warde7ed70c2011-06-10 11:45:17 +000024# redefining BASE_DIR now that we have the shlib functions
25BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"`
26BIN_DIR="${BASE_DIR}/bin"
27SRC_DIR="${BASE_DIR}/src"
kate.ward2f3cad92008-10-21 23:29:23 +000028
kate.warde7ed70c2011-06-10 11:45:17 +000029os_name=`versions_osName |sed 's/ /_/g'`
30os_version=`versions_osVersion`
31
32# load external flags
33. ${BIN_DIR}/gen_test_results.flags
34
35# define flags
kate.ward2f3cad92008-10-21 23:29:23 +000036DEFINE_boolean force false 'force overwrite' f
37DEFINE_string output_dir "`pwd`" 'output dir' d
kate.warde7ed70c2011-06-10 11:45:17 +000038DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o
kate.ward4a16b432013-01-05 12:29:36 +000039DEFINE_boolean dry_run false "supress logging to a file" n
kate.ward2f3cad92008-10-21 23:29:23 +000040
kate.wardaf8d27d2013-01-16 22:35:45 +000041main()
42{
43 # determine output filename
44 output="${FLAGS_output_dir:+${FLAGS_output_dir}/}${FLAGS_output_file}"
45 output=`shlib_relToAbsPath "${output}"`
46
47 # checks
48 [ -n "${FLAGS_suite:-}" ] || die 'suite flag missing'
49
50 if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} -a -f "${output}" ]; then
51 if [ ${FLAGS_force} -eq ${FLAGS_TRUE} ]; then
52 rm -f "${output}"
53 else
54 echo "not overwriting '${output}'" >&2
55 exit ${FLAGS_ERROR}
56 fi
kate.ward2f3cad92008-10-21 23:29:23 +000057 fi
kate.wardf4997502013-01-05 14:11:44 +000058 if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
kate.wardaf8d27d2013-01-16 22:35:45 +000059 touch "${output}" 2>/dev/null || die "unable to write to '${output}'"
kate.ward4a16b432013-01-05 12:29:36 +000060 fi
kate.wardaf8d27d2013-01-16 22:35:45 +000061
62 # run tests
63 (
64 cd "${SRC_DIR}";
65 if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
66 ./${FLAGS_suite} |tee "${output}"
67 else
68 ./${FLAGS_suite}
69 fi
70 )
71
72 if [ ! ${FLAGS_dry_run} ]; then
73 echo >&2
74 echo "output written to '${output}'" >&2
75 fi
76}
kate.ward2f3cad92008-10-21 23:29:23 +000077
kate.wardaf8d27d2013-01-16 22:35:45 +000078FLAGS "$@" || exit $?
79[ ${FLAGS_help} -eq ${FALSE} ] || exit
80eval set -- "${FLAGS_ARGV}"
81main "$@"