kate.ward | f51c616 | 2008-06-17 16:38:35 +0000 | [diff] [blame] | 1 | # vim:et:ft=sh:sts=2:sw=2 |
| 2 | # |
| 3 | # Copyright 2008 Kate Ward. All Rights Reserved. |
| 4 | # Released under the LGPL (GNU Lesser General Public License) |
| 5 | # |
| 6 | # Author: kate.ward@forestent.com (Kate Ward) |
| 7 | # |
| 8 | # shFlags unit test common functions |
| 9 | |
| 10 | __th_skipping=0 |
| 11 | |
kate.ward | 1d0ecc4 | 2008-07-11 15:33:23 +0000 | [diff] [blame^] | 12 | # set shwordsplit for zsh |
| 13 | [ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit |
| 14 | |
kate.ward | 2fb41e3 | 2008-07-10 18:42:46 +0000 | [diff] [blame] | 15 | # my name |
| 16 | TH_MY_NAME=`basename "$0"` |
| 17 | |
kate.ward | f51c616 | 2008-06-17 16:38:35 +0000 | [diff] [blame] | 18 | # path to shFlags library. can be overridden by setting SHFLAGS_INC |
| 19 | TH_SHFLAGS=${SHFLAGS_INC:-./shflags} |
| 20 | |
| 21 | # path to shUnit2 library. can be overridden by setting SHUNIT_INC |
| 22 | TH_SHUNIT=${SHUNIT_INC:-../lib/shunit2} |
| 23 | |
| 24 | TH_BOOL_VALID='true t 0 false f 1' |
| 25 | TH_BOOL_INVALID='123 123.0 blah' |
| 26 | TH_FLOAT_VALID='-1234.0 -1234 -1.0 -1 0.0 0 1.0 1 1234.0 1234' |
| 27 | TH_FLOAT_INVALID='true false invalid 1.2.3 -1.2.3 0. -.5' |
| 28 | TH_INT_VALID='-1234 -1 0 1 1234' |
| 29 | TH_INT_INVALID='-1.0 0.0 1.0 invalid' |
| 30 | |
| 31 | # |
| 32 | # test helper functions |
| 33 | # |
| 34 | |
| 35 | # message functions |
| 36 | th_trace() { echo "test:TRACE $@" >&2; } |
| 37 | th_debug() { echo "test:DEBUG $@" >&2; } |
| 38 | th_info() { echo "test:INFO $@" >&2; } |
| 39 | th_warn() { echo "test:WARN $@" >&2; } |
| 40 | th_error() { echo "test:ERROR $@" >&2; } |
| 41 | th_fatal() { echo "test:FATAL $@" >&2; } |
| 42 | |
| 43 | th_showOutput() |
| 44 | { |
| 45 | _th_rtrn=$1 |
| 46 | _th_stdout=$2 |
| 47 | _th_stderr=$3 |
| 48 | |
| 49 | isSkipping |
| 50 | if [ $? -eq ${SHUNIT_FALSE} -a ${_th_rtrn} != ${FLAGS_TRUE} ]; then |
| 51 | cat "${_th_stdout}" "${_th_stderr}" >&2 |
| 52 | fi |
| 53 | |
| 54 | unset _th_rtrn _th_stdout _th_stderr |
| 55 | } |
| 56 | |
| 57 | assertErrorMsg() |
| 58 | { |
| 59 | grep -- 'flags:ERROR' "${stderrF}" >/dev/null |
| 60 | assertTrue "FLAGS ${1:+\($1\) }failure did not result in an error message" $? |
| 61 | } |