Added `match' expectation

stderr
Mike Gerwitz 2014-05-09 23:31:47 -04:00
parent d2e8d21ac5
commit c1d1b66fa9
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
2 changed files with 34 additions and 0 deletions

View File

@ -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 ]]
}

View File

@ -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