Added `match' expectation
parent
d2e8d21ac5
commit
c1d1b66fa9
|
@ -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 ]]
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue