Added `silent' expectation handler
parent
1dcc0cd8d0
commit
a59a09007b
|
@ -131,3 +131,20 @@ _expect--match()
|
|||
[[ "$(cat)" =~ $pat ]]
|
||||
}
|
||||
|
||||
|
||||
##
|
||||
# Expects that both stdin and stderr (if available) are empty
|
||||
_expect--silent()
|
||||
{
|
||||
local -r stderr="${3:-/dev/null}"
|
||||
shift "$2"
|
||||
|
||||
# we accept no arguments
|
||||
test $# -eq 0 || _bail_clause silent "$*"
|
||||
|
||||
# quick read using builtins; if we find any single byte, then we know that
|
||||
# it is non-empty
|
||||
read -N1 || read -N1 <"$stderr" || return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
|
|
|
@ -121,3 +121,37 @@ describe match
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
describe silent
|
||||
it succeeds when both stdout and stderr are empty
|
||||
# omitting stderr arg
|
||||
expect _expect--silent 0 2 < <(:)
|
||||
to succeed
|
||||
|
||||
# empty stderr
|
||||
expect _expect--silent 0 3 <(:) < <(:)
|
||||
to succeed
|
||||
end
|
||||
|
||||
it fails when stdout is empty but stderr is not
|
||||
expect _expect--silent 0 3 <( echo ) < <(:)
|
||||
to fail
|
||||
end
|
||||
|
||||
it fails when stderr is empty but stdout is not
|
||||
# omitting stderr arg
|
||||
expect _expect--silent 0 2 <<< ""
|
||||
to fail
|
||||
|
||||
# empty stderr
|
||||
expect _expect--silent 0 3 <(:) <<< ""
|
||||
to fail
|
||||
end
|
||||
|
||||
# no arguments within context of the DSL, that is
|
||||
it accepts no arguments
|
||||
expect _expect--silent 0 2 foo < <(:)
|
||||
to fail
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue