diff options
author | Jason Karns <jason@karns.name> | 2016-11-09 00:50:56 +0300 |
---|---|---|
committer | Jason Karns <jason@karns.name> | 2016-11-09 00:50:56 +0300 |
commit | 0dc0b49165b9ad57a7327ad043c97f73f4d219ea (patch) | |
tree | 7743ddba879c72c1cd5cb26cc4ccf4f660a853c2 | |
parent | ae447cd8de08f58c38370522d8b111e5f8049845 (diff) |
Allow longform --stdin option as well
-rw-r--r-- | src/assert.bash | 8 | ||||
-rwxr-xr-x | test/50-assert-15-assert_output.bats | 10 | ||||
-rwxr-xr-x | test/50-assert-16-refute_output.bats | 9 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/assert.bash b/src/assert.bash index 202a8f1..1aac74d 100644 --- a/src/assert.bash +++ b/src/assert.bash @@ -172,7 +172,7 @@ assert_failure() { # Options: # -p, --partial - partial matching # -e, --regexp - extended regular expression matching -# - - read expected output from the standard input +# -, --stdin - read expected output from the standard input # Arguments: # $1 - expected output # Returns: @@ -193,7 +193,7 @@ assert_output() { case "$1" in -p|--partial) is_mode_partial=1; shift ;; -e|--regexp) is_mode_regexp=1; shift ;; - -) use_stdin=1; shift ;; + -|--stdin) use_stdin=1; shift ;; --) shift; break ;; *) break ;; esac @@ -270,7 +270,7 @@ assert_output() { # Options: # -p, --partial - partial matching # -e, --regexp - extended regular expression matching -# - - read unexpected output from the standard input +# -, --stdin - read unexpected output from the standard input # Arguments: # $1 - unexpected output # Returns: @@ -291,7 +291,7 @@ refute_output() { case "$1" in -p|--partial) is_mode_partial=1; shift ;; -e|--regexp) is_mode_regexp=1; shift ;; - -) use_stdin=1; shift ;; + -|--stdin) use_stdin=1; shift ;; --) shift; break ;; *) break ;; esac diff --git a/test/50-assert-15-assert_output.bats b/test/50-assert-15-assert_output.bats index 7efee71..0da7d04 100755 --- a/test/50-assert-15-assert_output.bats +++ b/test/50-assert-15-assert_output.bats @@ -36,6 +36,16 @@ echo "$output" [ "${#lines[@]}" -eq 0 ] } +@test 'assert_output() --stdin : reads <expected> from STDIN' { + run echo 'a' + run assert_output --stdin <<STDIN +a +STDIN +echo "$output" + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 0 ] +} + # Output formatting @test "assert_output() <expected>: displays details in multi-line format if \`\$output' is longer than one line" { run printf 'b 0\nb 1' diff --git a/test/50-assert-16-refute_output.bats b/test/50-assert-16-refute_output.bats index a289717..05f2995 100755 --- a/test/50-assert-16-refute_output.bats +++ b/test/50-assert-16-refute_output.bats @@ -34,6 +34,15 @@ INPUT [ "${#lines[@]}" -eq 0 ] } +@test 'refute_output() --stdin : reads <unexpected> from STDIN' { + run echo '--stdin' + run refute_output --stdin <<INPUT +b +INPUT + [ "$status" -eq 0 ] + [ "${#lines[@]}" -eq 0 ] +} + # Output formatting @test 'refute_output() <unexpected>: displays details in multi-line format if necessary' { run printf 'a 0\na 1' |