Added `silent' expectation handler

stderr
Mike Gerwitz 2014-05-13 00:20:24 -04:00
parent bfc9971020
commit eb3e09b404
2 changed files with 51 additions and 0 deletions

View File

@ -131,3 +131,20 @@ _expect--match()
[[ "$(cat)" =~ $pat ]] [[ "$(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
}

View File

@ -121,3 +121,37 @@ describe match
end end
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