diff options
author | Bob Badour <bbadour@google.com> | 2020-05-19 18:25:11 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-19 18:25:11 +0000 |
commit | 3dac286b93162f3ea66f52c2f4dd094c87fd755b (patch) | |
tree | da581028905318f358769fc7bb6f8aa7373e2fb7 /src/shflags_test_helpers | |
parent | ec20e4bbae1bf42b11e9ad1639bdd3b9768b9be9 (diff) | |
parent | 2e0d635a8717e638eab0cd04e2596a90299c5c5c (diff) | |
download | shflags-3dac286b93162f3ea66f52c2f4dd094c87fd755b.tar.gz |
Merge remote-tracking branch 'aosp/upstream-master' into mymerge am: 2e0d635a87android-r-beta-3android-r-beta-2
Change-Id: I4dcd750b88f1b92613edadbd1ae463ff2f76ed66
Diffstat (limited to 'src/shflags_test_helpers')
-rw-r--r-- | src/shflags_test_helpers | 116 |
1 files changed, 0 insertions, 116 deletions
diff --git a/src/shflags_test_helpers b/src/shflags_test_helpers deleted file mode 100644 index d00f31e..0000000 --- a/src/shflags_test_helpers +++ /dev/null @@ -1,116 +0,0 @@ -# vim:et:ft=sh:sts=2:sw=2 -# -# shFlags unit test common functions - -__th_skipping=0 - -# treat unset variables as an error -set -u - -# set shwordsplit for zsh -[ -n "${ZSH_VERSION:-}" ] && setopt shwordsplit - -# my name -TH_MY_NAME=`basename "$0"` - -# path to shFlags library. can be overridden by setting SHFLAGS_INC -TH_SHFLAGS=${SHFLAGS_INC:-./shflags} - -# path to shUnit2 library. can be overridden by setting SHUNIT_INC -TH_SHUNIT=${SHUNIT_INC:-../lib/shunit2} - -TH_BOOL_VALID='true t 0 false f 1' -TH_BOOL_INVALID='123 123.0 invalid' -TH_FLOAT_VALID='-1234.0 -1.0 -.123 0.0 0. .123 1.0 1234.0' -TH_FLOAT_INVALID='true false 1.2.3 -1.2.3 ""' -TH_INT_VALID='-1234 -1 0 1 1234' -TH_INT_INVALID='true false -1.0 -.123 0.0 .123 1.0 ""' - -# -# test helper functions -# - -# message functions -th_trace() { echo "test:TRACE $@" >&2; } -th_debug() { echo "test:DEBUG $@" >&2; } -th_info() { echo "test:INFO $@" >&2; } -th_warn() { echo "test:WARN $@" >&2; } -th_error() { echo "test:ERROR $@" >&2; } -th_fatal() { echo "test:FATAL $@" >&2; } - -th_oneTimeSetUp() -{ - # load shFlags - [ -n "${ZSH_VERSION:-}" ] && FLAGS_PARENT=$0 - . ${TH_SHFLAGS} - - # these files will be cleaned up automatically by shUnit2 - tmpDir=${SHUNIT_TMPDIR} - stdoutF="${tmpDir}/stdout" - stderrF="${tmpDir}/stderr" - returnF="${tmpDir}/return" - expectedF="${tmpDir}/expected" -} - -th_showOutput() -{ - _th_rtrn=$1 - _th_stdout=$2 - _th_stderr=$3 - - isSkipping - if [ $? -eq ${SHUNIT_FALSE} -a ${_th_rtrn} != ${FLAGS_TRUE} ]; then - if [ -n "${_th_stdout}" -a -s "${_th_stdout}" ]; then - echo '>>> STDOUT' >&2 - cat "${_th_stdout}" >&2 - fi - if [ -n "${_th_stderr}" -a -s "${_th_stderr}" ]; then - echo '>>> STDERR' >&2 - cat "${_th_stderr}" >&2 - fi - if [ -n "${_th_stdout}" -o -n "${_th_stderr}" ]; then - echo '<<< end output' >&2 - fi - fi - - unset _th_rtrn _th_stdout _th_stderr -} - -# Some shells, zsh on Solaris in particular, return immediately from a sub-shell -# when a non-zero return value is encountered. To properly catch these values, -# they are either written to disk, or recognized as an error the file is empty. -th_clearReturn() { cp /dev/null "${returnF}"; } -th_queryReturn() -{ - if [ -s "${returnF}" ]; then - th_return=`cat "${returnF}"` - else - th_return=${SHUNIT_ERROR} - fi -} - -_th_assertMsg() -{ - _th_alert_type_=$1 - _th_alert_msg_=$2 - _th_msg_=$3 - - case ${_th_alert_type_} in - WARN) _th_alert_str_='a warning' ;; - ERROR) _th_alert_str_='an error' ;; - FATAL) _th_alert_str_='a fatal' ;; - esac - [ -z "${_th_alert_msg_}" ] && _th_alert_msg_='.*' - [ -n "${_th_msg_}" ] && _th_msg_="(${_th_msg_}) " - - grep -- "^flags:${_th_alert_type_} ${_th_alert_msg_}" "${stderrF}" \ - >/dev/null - assertTrue \ - "FLAGS ${_th_msg_}failure did not generate ${_th_alert_str_} message" $? - - unset _th_alert_type_ _th_alert_msg_ _th_alert_str_ _th_msg_ -} - -assertWarnMsg() { _th_assertMsg 'WARN' "${1:-}" "${2:-}"; } -assertErrorMsg() { _th_assertMsg 'ERROR' "${1:-}" "${2:-}"; } -assertFatalMsg() { _th_assertMsg 'FATAL' "${1:-}" "${2:-}"; } |