Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bats-core/bats-assert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Karns <jason@karns.name>2016-06-17 23:03:27 +0300
committerJason Karns <jason@karns.name>2016-06-18 15:40:27 +0300
commit3f24698f70055e86dc65d32857ec3338bfbc0287 (patch)
treeb7225c8a3b0cfa1aae18f1810dddf912bba420df
parent204d3b73b2a94c912ea0e5354b995c2623e813a1 (diff)
refute_output without args asserts output is empty
-rw-r--r--src/assert.bash13
-rwxr-xr-xtest/50-assert-16-refute_output.bats19
2 files changed, 31 insertions, 1 deletions
diff --git a/src/assert.bash b/src/assert.bash
index b680fad..e1ffc4b 100644
--- a/src/assert.bash
+++ b/src/assert.bash
@@ -293,9 +293,14 @@ assert_output() {
refute_output() {
local -i is_mode_partial=0
local -i is_mode_regexp=0
+ local -i is_mode_empty=0
local -i use_stdin=0
# Handle options.
+ if (( $# == 0 )); then
+ is_mode_empty=1
+ fi
+
while (( $# > 0 )); do
case "$1" in
-p|--partial) is_mode_partial=1; shift ;;
@@ -329,7 +334,13 @@ refute_output() {
fi
# Matching.
- if (( is_mode_regexp )); then
+ if (( is_mode_empty )); then
+ if [ -n "$output" ]; then
+ echo 'expected no output, but output was non-empty' \
+ | batslib_decorate 'unexpected output' \
+ | fail
+ fi
+ elif (( is_mode_regexp )); then
if [[ $output =~ $unexpected ]] || (( $? == 0 )); then
batslib_print_kv_single_or_multi 6 \
'regexp' "$unexpected" \
diff --git a/test/50-assert-16-refute_output.bats b/test/50-assert-16-refute_output.bats
index a289717..7983750 100755
--- a/test/50-assert-16-refute_output.bats
+++ b/test/50-assert-16-refute_output.bats
@@ -25,6 +25,25 @@ load test_helper
[ "${lines[2]}" == '--' ]
}
+@test 'refute_output(): succeeds if output is empty' {
+ run echo ''
+ run refute_output
+echo "$output"
+ [ "$status" -eq 0 ]
+ [ "${#lines[@]}" -eq 0 ]
+}
+
+@test 'refute_output(): fails if output is non-empty' {
+ run echo 'a'
+ run refute_output
+echo "$output"
+ [ "$status" -eq 1 ]
+ [ "${#lines[@]}" -eq 3 ]
+ [ "${lines[0]}" == '-- unexpected output --' ]
+ [ "${lines[1]}" == 'expected no output, but output was non-empty' ]
+ [ "${lines[2]}" == '--' ]
+}
+
@test 'refute_output() - : reads <unexpected> from STDIN' {
run echo '-'
run refute_output - <<INPUT