From 5a8c2fec1264366602d8c60bc3e495251a96e8be Mon Sep 17 00:00:00 2001 From: "Tom \"Ravi\" Hale" Date: Mon, 27 Aug 2018 18:21:03 +0700 Subject: [PATCH] assert(Not)?Includes: check for failure of _includes Call _includes and then check its return value. shunit2 uses the exit code to test, not a string of 0 or 1 as was done previously. --- test/support/test_helper.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/test/support/test_helper.sh b/test/support/test_helper.sh index d5a9854..de8cd1b 100644 --- a/test/support/test_helper.sh +++ b/test/support/test_helper.sh @@ -50,16 +50,22 @@ function token_quote { # Asserts #----------------------------------------------------------------------------- +# Return 0 (shell's true) if "$1" contains string "$2" _includes() { if [ -n "$3" ]; then regex="$3"; else regex=''; fi - if echo "$1" | grep -q$regex "$2"; then echo 0; else echo 1; fi + echo "$1" | grep -q"$regex" "$2" # exit status of quiet grep is returned } # assert $1 contains $2 assertIncludes() { - assertTrue "'$1' should have contained '$2'" $(_includes "$@") + _includes "$@" + local grep_exit=$? + assertTrue "'$1' should have contained '$2'" '[[ $grep_exit == 0 ]]' } + # assert $1 does not contain $2 assertNotIncludes() { - assertFalse "'$1' should not have contained '$2'" $(_includes "$@") + _includes "$@" + local grep_return=$? + assertTrue "'$1' should not have contained '$2'" '[[ ! $grep_exit = 0 ]]' }