1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-12-25 14:09:43 +01:00

Skip pretty formatting if the first line isn't a TAP plan

Closes #21
This commit is contained in:
Sam Stephenson 2013-10-28 14:46:30 -05:00
parent d2c5b9ef71
commit 25505bd143
3 changed files with 28 additions and 6 deletions

View File

@ -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)"

View File

@ -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" ]
}

7
test/fixtures/bats/invalid_tap.bats vendored Normal file
View File

@ -0,0 +1,7 @@
echo "This isn't TAP!"
echo "Good day to you"
exit 1
@test "truth" {
true
}