Skip to content

Commit

Permalink
added assertContains() fn
Browse files Browse the repository at this point in the history
  • Loading branch information
mle86 committed Jun 13, 2016
1 parent 0e1ee58 commit d522894
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.2, 2016-06-13
- added assertContains() fn

v1.1, 2016-05-28
- added add_cleanup() helper fn
- support multiple prepare_subshell() calls per test
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Starting 00-test-compile...
Success: 00-test-compile
```


# Package structure

Test scripts only need to source the *init.sh* file to be operational.
Expand Down Expand Up @@ -83,6 +84,10 @@ exiting with a return status of 99.
* `assertEq valueActual valueExpected [errorMessage]`
This assertion compares two strings and tests them for equality.

* `assertContains valueActual valueExpectedPart [errorMessage]`
This assertion compares two strings,
expecting the second to be contained somewhere in the first.

* `assertEmpty valueActual [errorMessage]`
This assertion tests a string, expecting it to be empty.

Expand Down
16 changes: 16 additions & 0 deletions assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ assertEq () {
fi
}

# assertContains valueActual valueExpectedPart [errorMessage]
# This assertion compares two strings,
# expecting the second to be contained somewhere in the first.
assertContains () {
local valueActual="$1"
local valueExpectedPart="$2"
local errorMessage="${3:-"Substring assertion failed!"}"
case "$valueActual" in
*"$valueExpectedPart"*) true ;; # ok
*)
err "$errorMessage"
err "(Expected '$valueExpectedPart' is not contained in '$valueActual')"
abort ;;
esac
}

# assertEmpty valueActual [errorMessage]
# This assertion tests a string, expecting it to be empty.
assertEmpty () {
Expand Down

0 comments on commit d522894

Please sign in to comment.