blob: 1ecddc71e2d348ac977c550685c9145aa37c3d7c [file] [log] [blame]
kate.wardf51c6162008-06-17 16:38:35 +00001# 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.ward1d0ecc42008-07-11 15:33:23 +000012# set shwordsplit for zsh
13[ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit
14
kate.ward2fb41e32008-07-10 18:42:46 +000015# my name
16TH_MY_NAME=`basename "$0"`
17
kate.wardf51c6162008-06-17 16:38:35 +000018# path to shFlags library. can be overridden by setting SHFLAGS_INC
19TH_SHFLAGS=${SHFLAGS_INC:-./shflags}
20
21# path to shUnit2 library. can be overridden by setting SHUNIT_INC
22TH_SHUNIT=${SHUNIT_INC:-../lib/shunit2}
23
24TH_BOOL_VALID='true t 0 false f 1'
25TH_BOOL_INVALID='123 123.0 blah'
26TH_FLOAT_VALID='-1234.0 -1234 -1.0 -1 0.0 0 1.0 1 1234.0 1234'
27TH_FLOAT_INVALID='true false invalid 1.2.3 -1.2.3 0. -.5'
28TH_INT_VALID='-1234 -1 0 1 1234'
29TH_INT_INVALID='-1.0 0.0 1.0 invalid'
30
31#
32# test helper functions
33#
34
35# message functions
36th_trace() { echo "test:TRACE $@" >&2; }
37th_debug() { echo "test:DEBUG $@" >&2; }
38th_info() { echo "test:INFO $@" >&2; }
39th_warn() { echo "test:WARN $@" >&2; }
40th_error() { echo "test:ERROR $@" >&2; }
41th_fatal() { echo "test:FATAL $@" >&2; }
42
43th_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
57assertErrorMsg()
58{
59 grep -- 'flags:ERROR' "${stderrF}" >/dev/null
60 assertTrue "FLAGS ${1:+\($1\) }failure did not result in an error message" $?
61}