Added output expectation handler

stderr
Mike Gerwitz 2014-05-09 02:04:09 -04:00
parent b4572d420b
commit 61ecb6ad82
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
2 changed files with 51 additions and 0 deletions

View File

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

View File

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