diff options
| author | Paul Buetow <pbuetow@mimecast.com> | 2021-05-19 10:06:02 +0100 |
|---|---|---|
| committer | Paul Buetow <git@mx.buetow.org> | 2021-05-21 05:11:05 +0100 |
| commit | 641a95de7bdd64963666cca6b96387ab5d9245e2 (patch) | |
| tree | 633a546aff999286dd4c6073726ed6a037fed58b /packages/assert.source.sh | |
| parent | 05c68a1ed420243e484003df9bb281b79303c604 (diff) | |
some refactoring and also ensured that it works on macOS (given Bash 5 is installed)
Diffstat (limited to 'packages/assert.source.sh')
| -rw-r--r-- | packages/assert.source.sh | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/assert.source.sh b/packages/assert.source.sh index c3ad0a6..5d3a5c5 100644 --- a/packages/assert.source.sh +++ b/packages/assert.source.sh @@ -30,3 +30,18 @@ assert::not_empty () { log VERBOSE "Result in $callee as expected not empty" } + +# Unit test for whether a given string matches a regex. +assert::matches () { + local -r name="$1"; shift + local -r content="$1"; shift + local -r regex="$1"; shift + local -r callee=${FUNCNAME[1]} + + if ! $GREP -q -E "$regex" <<< "$content"; then + log ERROR "In $callee expected '$name' to match '$regex'" + exit 2 + fi + + log VERBOSE "Matching in $callee as expected" +} |
