Added output expectation handler
parent
b4572d420b
commit
61ecb6ad82
|
@ -26,3 +26,20 @@ __INC_EXPECT_CORE=1
|
|||
_expect--succeed() { test "$1" -eq 0; }
|
||||
_expect--fail() { test "$1" -ne 0; }
|
||||
|
||||
_expect--output()
|
||||
{
|
||||
local -r cmp="$2"
|
||||
shift 2
|
||||
local -r clause="$*"
|
||||
|
||||
local nl=
|
||||
if [ -n "$clause" ]; then
|
||||
[ "$clause" == 'without newline' ] \
|
||||
&& nl=-n \
|
||||
|| _bail "unrecognized output clause: $clause"
|
||||
fi
|
||||
|
||||
# we will eventually be interested in this output
|
||||
diff <( echo $nl "$cmp" ) - &>/dev/null
|
||||
}
|
||||
|
||||
|
|
|
@ -45,3 +45,37 @@ describe fail
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
describe output
|
||||
it will default to asserting against stdout
|
||||
expect _expect--output 0 "test string" <<< "test string"
|
||||
to succeed
|
||||
end
|
||||
|
||||
it ignores exit code
|
||||
expect _expect--output 1 "foo" <<< "foo"
|
||||
to succeed
|
||||
end
|
||||
|
||||
it fails on output mismatch
|
||||
expect _expect--output 0 "foo" <<< "bar"
|
||||
to fail
|
||||
end
|
||||
|
||||
# as is good practice for Unix utilities
|
||||
it expects trailing newline by default
|
||||
expect _expect--output 0 "foo" < <( echo -n foo )
|
||||
to fail
|
||||
end
|
||||
|
||||
it can disable trailing newline check with "'without newline'" clause
|
||||
expect _expect--output 0 "foo" without newline < <( echo -n foo )
|
||||
to succeed
|
||||
end
|
||||
|
||||
it errors on any unrecognized clause
|
||||
expect _expect--output 0 "foo" fluffy bunnies <<< "foo"
|
||||
to fail
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue