diff --git a/libexec/bats-format-tap-stream b/libexec/bats-format-tap-stream index defb56b..0f91e55 100755 --- a/libexec/bats-format-tap-stream +++ b/libexec/bats-format-tap-stream @@ -4,12 +4,20 @@ set -e # Just stream the TAP output (sans extended syntax) if tput is missing command -v tput >/dev/null || exec grep -v "^begin " -IFS= read -r header # 1..n -count="${header:3}" -index=0 -failures=0 -name="" -count_column_width=$(( ${#count} * 2 + 2 )) +header_pattern='[0-9]+\.\.[0-9]+' +IFS= read -r header + +if [[ "$header" =~ $header_pattern ]]; then + count="${header:3}" + index=0 + failures=0 + name="" + count_column_width=$(( ${#count} * 2 + 2 )) +else + # If the first line isn't a TAP plan, print it and pass the rest through + printf "%s\n" "$header" + exec cat +fi update_screen_width() { screen_width="$(tput cols)" diff --git a/test/bats.bats b/test/bats.bats index b408839..1f16239 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -150,3 +150,10 @@ fixtures bats [ "$tap_output" != "$pretty_output" ] } + +@test "pretty formatter bails on invalid tap" { + run bats --tap "$FIXTURE_ROOT/invalid_tap.bats" + [ $status -eq 1 ] + [ "${lines[0]}" = "This isn't TAP!" ] + [ "${lines[1]}" = "Good day to you" ] +} diff --git a/test/fixtures/bats/invalid_tap.bats b/test/fixtures/bats/invalid_tap.bats new file mode 100644 index 0000000..3ae2c2f --- /dev/null +++ b/test/fixtures/bats/invalid_tap.bats @@ -0,0 +1,7 @@ +echo "This isn't TAP!" +echo "Good day to you" +exit 1 + +@test "truth" { + true +}