Home | History | Annotate | Download | only in bin
      1 #! /bin/sh
      2 # vim:et:ft=sh:sts=2:sw=2
      3 #
      4 # This script runs the provided unit tests and sends the output to the
      5 # appropriate file.
      6 
      7 # Treat unset variables as an error.
      8 set -u
      9 
     10 die() {
     11   [ $# -gt 0 ] && echo "error: $@" >&2
     12   exit 1
     13 }
     14 
     15 BASE_DIR="`dirname $0`/.."
     16 LIB_DIR="${BASE_DIR}/lib"
     17 
     18 # Load libraries.
     19 . ${LIB_DIR}/shflags || die 'unable to load shflags library'
     20 . ${LIB_DIR}/shlib || die 'unable to load shlib library'
     21 . ${LIB_DIR}/versions || die 'unable to load versions library'
     22 
     23 # Redefining BASE_DIR now that we have the shlib functions.
     24 BASE_DIR=`shlib_relToAbsPath "${BASE_DIR}"`
     25 BIN_DIR="${BASE_DIR}/bin"
     26 SRC_DIR="${BASE_DIR}/src"
     27 
     28 os_name=`versions_osName |sed 's/ /_/g'`
     29 os_version=`versions_osVersion`
     30 
     31 # Load external flags.
     32 . ${BIN_DIR}/gen_test_results.flags
     33 
     34 # Define flags.
     35 DEFINE_boolean force false 'force overwrite' f
     36 DEFINE_string output_dir "`pwd`" 'output dir' d
     37 DEFINE_string output_file "${os_name}-${os_version}.txt" 'output file' o
     38 DEFINE_boolean dry_run false "supress logging to a file" n
     39 
     40 main() {
     41   # Determine output filename.
     42   output="${FLAGS_output_dir:+${FLAGS_output_dir}/}${FLAGS_output_file}"
     43   output=`shlib_relToAbsPath "${output}"`
     44 
     45   # Checks.
     46   [ -n "${FLAGS_suite:-}" ] || die 'suite flag missing'
     47 
     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
     55   fi
     56   if [ ${FLAGS_dry_run} -eq ${FLAGS_FALSE} ]; then
     57     touch "${output}" 2>/dev/null || die "unable to write to '${output}'"
     58   fi
     59 
     60   # Run tests.
     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   )
     69 
     70   if [ ! ${FLAGS_dry_run} ]; then
     71     echo >&2
     72     echo "output written to '${output}'" >&2
     73   fi
     74 }
     75 
     76 FLAGS "$@" || exit $?
     77 [ ${FLAGS_help} -eq ${FALSE} ] || exit
     78 eval set -- "${FLAGS_ARGV}"
     79 main "$@"
     80