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

Preserve empty output lines in $lines #93

Open
wants to merge 4 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
7 changes: 4 additions & 3 deletions libexec/bats-exec-test
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ run() {
set +T
output="$("$@" 2>&1)"
status="$?"
oldIFS=$IFS
IFS=$'\n' lines=($output)
lines=()
while IFS= read -r LINE; do
lines+=( "$LINE" )
done < <(echo "$output")
[ -z "$e" ] || set -e
[ -z "$E" ] || set -E
[ -z "$T" ] || set -T
IFS=$oldIFS
}

setup() {
Expand Down
17 changes: 13 additions & 4 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ fixtures bats
@test "summary passing tests" {
run filter_control_sequences bats -p $FIXTURE_ROOT/passing.bats
[ $status -eq 0 ]
[ "${lines[1]}" = "1 test, 0 failures" ]
[ "${lines[2]}" = "1 test, 0 failures" ]
}

@test "summary passing and skipping tests" {
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_and_skipping.bats
[ $status -eq 0 ]
[ "${lines[2]}" = "2 tests, 0 failures, 1 skipped" ]
[ "${lines[3]}" = "2 tests, 0 failures, 1 skipped" ]
}

@test "summary passing and failing tests" {
run filter_control_sequences bats -p $FIXTURE_ROOT/failing_and_passing.bats
[ $status -eq 0 ]
[ "${lines[4]}" = "2 tests, 1 failure" ]
[ "${lines[5]}" = "2 tests, 1 failure" ]
}

@test "summary passing, failing and skipping tests" {
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_failing_and_skipping.bats
[ $status -eq 0 ]
[ "${lines[5]}" = "3 tests, 1 failure, 1 skipped" ]
[ "${lines[6]}" = "3 tests, 1 failure, 1 skipped" ]
}

@test "one failing test" {
Expand Down Expand Up @@ -262,3 +262,12 @@ fixtures bats
[ $status -eq 0 ]
[ "${lines[1]}" = "ok 1 loop_func" ]
}

@test "empty lines in output are preserved" {
run echo -ne "line0\n\nline2"

[ "${#lines[@]}" -eq 3 ]
[ "${lines[0]}" = "line0" ]
[ "${lines[1]}" = "" ]
[ "${lines[2]}" = "line2" ]
}