diff --git a/src/expect-core b/src/expect-core index cf4fe10..b8b0dbc 100644 --- a/src/expect-core +++ b/src/expect-core @@ -37,6 +37,7 @@ _bail_clause() _expect--succeed() { test "$1" -eq 0; } _expect--fail() { test "$1" -ne 0; } + _expect--output() { local -r cmp="$2" @@ -54,3 +55,10 @@ _expect--output() diff <( echo $nl "$cmp" ) - &>/dev/null } + +_expect--match() +{ + local -r pat="$2" + [[ "$(cat)" =~ $pat ]] +} + diff --git a/test/test-expect-core b/test/test-expect-core index 9cdbde9..437e70d 100644 --- a/test/test-expect-core +++ b/test/test-expect-core @@ -79,3 +79,29 @@ describe output end end + +describe match + it will default to asserting against stdout + expect _expect--match 0 "foo" <<< "foo" + to succeed + end + + it ignores exit code + expect _expect--match 1 "foo" <<< "foo" + to succeed + end + + it will perform partial match + expect _expect--match 0 "foo" <<< "contains foo" + to succeed + end + + it will match against a pattern + expect _expect--match 0 "^foo.*baz" <<< "foo bar baz" + to succeed + + expect _expect--match 0 "^foo.*baz" <<< "bar foo bar baz" + to fail + end +end +