Skip to content

Commit

Permalink
result modifier and satisfy matcher should not consume stdin data
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Jun 20, 2020
1 parent f446ac2 commit 933488e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/core/matchers/satisfy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ shellspec_matcher_satisfy() {
unset "$1" ||:
fi
fi
"$@"
shellspec_puts "${SHELLSPEC_SUBJECT:-}" | "$@" >&4
) 2>"$SHELLSPEC_SATISFY_STDERR_FILE" &&:

set -- "$?"
Expand Down
7 changes: 5 additions & 2 deletions lib/core/modifiers/result.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ shellspec_modifier_result() {

shellspec_modifier_result_invoke() {
set -- "${SHELLSPEC_STDOUT:-}" "${SHELLSPEC_STDERR:-}" "${SHELLSPEC_STATUS:-}"
( "$SHELLSPEC_SUBJECT" "$@" ) \
>"$SHELLSPEC_RESULT_STDOUT_FILE" 2>"$SHELLSPEC_RESULT_STDERR_FILE" &&:
if [ -e "$SHELLSPEC_STDOUT_FILE" ]; then
( "$SHELLSPEC_SUBJECT" "$@" < "$SHELLSPEC_STDOUT_FILE" ) &&:
else
( "$SHELLSPEC_SUBJECT" "$@" < /dev/null ) &&:
fi >"$SHELLSPEC_RESULT_STDOUT_FILE" 2>"$SHELLSPEC_RESULT_STDERR_FILE" &&:
set -- "$?"
[ -s "$SHELLSPEC_RESULT_STDERR_FILE" ] || return "$1"
shellspec_output RESULT_WARN "$1" "$SHELLSPEC_RESULT_STDERR_FILE"
Expand Down
4 changes: 2 additions & 2 deletions lib/core/outputs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ shellspec_output_SYNTAX_ERROR_PARAM_TYPE() {

shellspec_output_RESULT_WARN() {
shellspec_readfile SHELLSPEC_RESULT_ERROR "$2"
set -- "Unexpected error output to stderr (exit status: $1)${SHELLSPEC_LF}" \
set -- "Unexpected output to stderr in result modifier (exit status: $1)${SHELLSPEC_LF}" \
"$SHELLSPEC_RESULT_ERROR${SHELLSPEC_LF}"
shellspec_output_statement "tag:warn" "note:WARNING" \
"fail:${SHELLSPEC_WARNING_AS_FAILURE:+y}" \
Expand All @@ -205,7 +205,7 @@ shellspec_output_RESULT_WARN() {

shellspec_output_SATISFY_WARN() {
shellspec_readfile SHELLSPEC_SATISFY_WARN "$2"
set -- "Unexpected error output to stderr (exit status: $1)${SHELLSPEC_LF}" \
set -- "Unexpected output to stderr in satisfy matcher (exit status: $1)${SHELLSPEC_LF}" \
"$SHELLSPEC_SATISFY_WARN${SHELLSPEC_LF}"
shellspec_output_statement "tag:warn" "note:WARNING" \
"fail:${SHELLSPEC_WARNING_AS_FAILURE:+y}" \
Expand Down
11 changes: 9 additions & 2 deletions spec/core/modifiers/result_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@ Describe "core/modifiers/result.sh"

Example 'example'
The result of 'foo()' should equal ok
The result of 'foo()' should be successful
The result of 'bar()' should not be successful
#The result of 'foo()' should be successful
#The result of 'bar()' should not be successful
End

It "read stdout data from stdin"
read_from_stdin() { cat; }
When call echo stdout
The result of 'read_from_stdin()' should eq "stdout"
End

Describe 'example with stdout, stderr and status'
Expand All @@ -30,6 +36,7 @@ Describe "core/modifiers/result.sh"
It 'gets stdout and stderr when subject is function that returns success'
subject() { %- "success_with_output"; }
success_with_output() { echo stdout; true; }
BeforeRun "SHELLSPEC_STDOUT_FILE=/dev/no-such-a-file"
When run shellspec_modifier_result _modifier_
The stdout should include stdout
End
Expand Down

0 comments on commit 933488e

Please sign in to comment.