kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 1 | #! /bin/sh |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 2 | # vim:et:ft=sh:sts=2:sw=2 |
| 3 | # |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 4 | # This script runs the provided unit tests and sends the output to the |
| 5 | # appropriate file. |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 6 | |
| 7 | # treat unset variables as an error |
| 8 | set -u |
| 9 | |
| 10 | die() |
| 11 | { |
| 12 | [ $# -gt 0 ] && echo "error: $@" >&2 |
| 13 | exit 1 |
| 14 | } |
| 15 | |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 16 | BASE_DIR="`dirname $0`/.." |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 17 | LIB_DIR="${BASE_DIR}/lib" |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 18 | |
| 19 | # load libraries |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 20 | . ${LIB_DIR}/shflags || die 'unable to load shflags library' |
| 21 | . ${LIB_DIR}/shlib || die 'unable to load shlib library' |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 22 | . ${LIB_DIR}/versions || die 'unable to load versions library' |
| 23 | |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 24 | # redefining BASE_DIR now that we have the shlib functions |
| 25 | BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"` |
| 26 | BIN_DIR="${BASE_DIR}/bin" |
| 27 | SRC_DIR="${BASE_DIR}/src" |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 28 | |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 29 | os_name=`versions_osName |sed 's/ /_/g'` |
| 30 | os_version=`versions_osVersion` |
| 31 | |
| 32 | # load external flags |
| 33 | . ${BIN_DIR}/gen_test_results.flags |
| 34 | |
| 35 | # define flags |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 36 | DEFINE_boolean force false 'force overwrite' f |
| 37 | DEFINE_string output_dir "`pwd`" 'output dir' d |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 38 | DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o |
kate.ward | 4a16b43 | 2013-01-05 12:29:36 +0000 | [diff] [blame] | 39 | DEFINE_boolean dry_run false "supress logging to a file" n |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 40 | |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 41 | main() |
| 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.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 57 | fi |
kate.ward | f499750 | 2013-01-05 14:11:44 +0000 | [diff] [blame] | 58 | if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 59 | touch "${output}" 2>/dev/null || die "unable to write to '${output}'" |
kate.ward | 4a16b43 | 2013-01-05 12:29:36 +0000 | [diff] [blame] | 60 | fi |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 61 | |
| 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.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 77 | |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 78 | FLAGS "$@" || exit $? |
| 79 | [ ${FLAGS_help} -eq ${FALSE} ] || exit |
| 80 | eval set -- "${FLAGS_ARGV}" |
| 81 | main "$@" |