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 | |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 7 | # Treat unset variables as an error. |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 8 | set -u |
| 9 | |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 10 | die() { |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 11 | [ $# -gt 0 ] && echo "error: $@" >&2 |
| 12 | exit 1 |
| 13 | } |
| 14 | |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 15 | BASE_DIR="`dirname $0`/.." |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 16 | LIB_DIR="${BASE_DIR}/lib" |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 17 | |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 18 | # Load libraries. |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 19 | . ${LIB_DIR}/shflags || die 'unable to load shflags library' |
| 20 | . ${LIB_DIR}/shlib || die 'unable to load shlib library' |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 21 | . ${LIB_DIR}/versions || die 'unable to load versions library' |
| 22 | |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 23 | # Redefining BASE_DIR now that we have the shlib functions. |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 24 | BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"` |
| 25 | BIN_DIR="${BASE_DIR}/bin" |
| 26 | SRC_DIR="${BASE_DIR}/src" |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 27 | |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 28 | os_name=`versions_osName |sed 's/ /_/g'` |
| 29 | os_version=`versions_osVersion` |
| 30 | |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 31 | # Load external flags. |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 32 | . ${BIN_DIR}/gen_test_results.flags |
| 33 | |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 34 | # Define flags. |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 35 | DEFINE_boolean force false 'force overwrite' f |
| 36 | DEFINE_string output_dir "`pwd`" 'output dir' d |
kate.ward | e7ed70c | 2011-06-10 11:45:17 +0000 | [diff] [blame] | 37 | DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o |
kate.ward | 4a16b43 | 2013-01-05 12:29:36 +0000 | [diff] [blame] | 38 | DEFINE_boolean dry_run false "supress logging to a file" n |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 39 | |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 40 | main() { |
| 41 | # Determine output filename. |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 42 | output="${FLAGS_output_dir:+${FLAGS_output_dir}/}${FLAGS_output_file}" |
| 43 | output=`shlib_relToAbsPath "${output}"` |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 44 | |
| 45 | # Checks. |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 46 | [ -n "${FLAGS_suite:-}" ] || die 'suite flag missing' |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 47 | |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 48 | if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} -a -f "${output}" ]; then |
| 49 | if [ ${FLAGS_force} -eq ${FLAGS_TRUE} ]; then |
| 50 | rm -f "${output}" |
| 51 | else |
| 52 | echo "not overwriting '${output}'" >&2 |
| 53 | exit ${FLAGS_ERROR} |
| 54 | fi |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 55 | fi |
kate.ward | f499750 | 2013-01-05 14:11:44 +0000 | [diff] [blame] | 56 | if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 57 | touch "${output}" 2>/dev/null || die "unable to write to '${output}'" |
kate.ward | 4a16b43 | 2013-01-05 12:29:36 +0000 | [diff] [blame] | 58 | fi |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 59 | |
| 60 | # Run tests. |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 61 | ( |
| 62 | cd "${SRC_DIR}"; |
| 63 | if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then |
| 64 | ./${FLAGS_suite} |tee "${output}" |
| 65 | else |
| 66 | ./${FLAGS_suite} |
| 67 | fi |
| 68 | ) |
Kate Ward | a397c1c | 2016-01-10 19:40:24 +0100 | [diff] [blame^] | 69 | |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 70 | if [ ! ${FLAGS_dry_run} ]; then |
| 71 | echo >&2 |
| 72 | echo "output written to '${output}'" >&2 |
| 73 | fi |
| 74 | } |
kate.ward | 2f3cad9 | 2008-10-21 23:29:23 +0000 | [diff] [blame] | 75 | |
kate.ward | af8d27d | 2013-01-16 22:35:45 +0000 | [diff] [blame] | 76 | FLAGS "$@" || exit $? |
| 77 | [ ${FLAGS_help} -eq ${FALSE} ] || exit |
| 78 | eval set -- "${FLAGS_ARGV}" |
| 79 | main "$@" |