summaryrefslogtreecommitdiff
path: root/packages/assert.source.sh
diff options
context:
space:
mode:
authorPaul Buetow <pbuetow@mimecast.com>2021-05-19 10:06:02 +0100
committerPaul Buetow <pbuetow@mimecast.com>2021-05-19 10:06:02 +0100
commit995140a869c86929318d990232aff50feb9f11b2 (patch)
treeacbc1bd3de63caf2926f75bc39c993af295014d3 /packages/assert.source.sh
parent0963ac49fd15beab68726ab60c39f10b7d5be086 (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.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/packages/assert.source.sh b/packages/assert.source.sh
index c3ad0a6a..5d3a5c5d 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"
+}