Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Separate stdout and stderr in run #180

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions libexec/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@ run() {
set +e
set +E
set +T
output="$("$@" 2>&1)"

local temp_stdout=$(mktemp -t stdout.XXXXXX)
local temp_stderr=$(mktemp -t stderr.XXXXXX)

( "$@" 2> "$temp_stderr" 1> "$temp_stdout" )
status="$?"
IFS=$'\n' lines=($output)

output_stdout=$( < "$temp_stdout")
output_stderr=$( < "$temp_stderr")
output="${output_stderr}${output_stdout}"

IFS=$'\n' lines=($output) lines_stdout=($output_stdout) lines_stderr=($output_stderr)
[ -z "$e" ] || set -e
[ -z "$E" ] || set -E
[ -z "$T" ] || set -T
Expand Down
23 changes: 23 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,26 @@ fixtures bats
[ "${lines[4]}" = "not ok 4 failing" ]
[ "${lines[5]}" = "# (in test file $FIXTURE_ROOT/single_line.bats, line 9)" ]
}

@test "test output_stderr and lines_stderr are populated" {
run bats nonexistent
[ $status -eq 1 ]
[ $(expr "$output_stderr" : ".*does not exist") -ne 0 ]
[ "${lines_stdout[0]}" = "" ]

run bats
[ $status -eq 1 ]
[ $(expr "${lines_stderr[1]}" : "Usage:") -ne 0 ]
}

@test "test output_stdout and lines_stdout are populated" {
run bats -c "$FIXTURE_ROOT/output.bats"
[ $status -eq 0 ]
[ "$output_stdout" = "4" ]

run bats -v
[ $status -eq 0 ]
[ $(expr "${lines_stdout[0]}" : "Bats [0-9][0-9.]*") -ne 0 ]
[ "${lines_stderr[0]}" = "" ]

}