summaryrefslogtreecommitdiff
path: root/packages/assert.source.sh
diff options
context:
space:
mode:
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"
+}