Skip to content

Commit 52439eb

Browse files
Merge pull request #1263 from darettau/fix-summary-color
fix: color summary by outcome, not just failure count
2 parents 5d99e45 + 7f8f547 commit 52439eb

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

‎docs/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The format is based on [Keep a Changelog][kac] and this project adheres to
2626
* `bats_encode_test_name()` used the locale-dependent `[[:alnum:]]` character class, causing test names with non-ASCII characters to be silently skipped under some locales (#1236)
2727
* normalize BATS_ROOT from PowerShell on Windows (#1257)
2828
* normalize BATS_LIB_PATH from PowerShell on Windows (#1258)
29+
* pretty formatter colored the summary green when tests timed out or did not run (#538, #1263)
2930

3031
### Changed
3132

‎libexec/bats-core/bats-format-pretty‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ log() {
144144
}
145145

146146
summary() {
147-
if [ "$failures" -eq 0 ]; then
148-
set_color 2 bold
149-
else
147+
not_run=$((count - passed - failures - skipped - timed_out))
148+
149+
if ((failures > 0 || timed_out > 0 || not_run > 0)); then
150150
set_color 1 bold
151+
else
152+
set_color 2 bold
151153
fi
152154

153155
buffer '\n%d test' "$count"
@@ -168,7 +170,6 @@ summary() {
168170
buffer ', %d timed out' "$timed_out"
169171
fi
170172

171-
not_run=$((count - passed - failures - skipped - timed_out))
172173
if [[ "$not_run" -gt 0 ]]; then
173174
buffer ', %d not run' "$not_run"
174175
fi

‎test/pretty-formatter.bats‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,31 @@ HERE
9595
[[ "${lines[2]}" == *$'\x1b[0m\x1b[33;22m timeout text'* ]]
9696
[[ "${lines[4]}" == *$'1 test, 0 failures, 1 timed out'* ]]
9797
}
98+
99+
@test "pretty formatter summary is colorized red when tests did not run" {
100+
run bats-format-pretty <<HERE
101+
1..3
102+
suite /test/path
103+
begin 1 test1
104+
ok 1 test1
105+
begin 2 test2
106+
ok 2 test2
107+
HERE
108+
109+
[ "${lines[3]}" == $'\033[0m\033[31;1m' ] # TODO: avoid checking for the leading reset too
110+
[ "${lines[4]}" == '3 tests, 0 failures, 1 not run' ]
111+
[ "${lines[5]}" == $'\033[0m' ]
112+
}
113+
114+
@test "pretty formatter summary is colorized red on timeout" {
115+
run bats-format-pretty <<HERE
116+
1..1
117+
suite /test/path
118+
begin 1 test1
119+
not ok 1 test1 # timeout after 1s
120+
HERE
121+
122+
[ "${lines[2]}" == $'\033[0m\033[31;1m' ] # TODO: avoid checking for the leading reset too
123+
[ "${lines[3]}" == '1 test, 0 failures, 1 timed out' ]
124+
[ "${lines[4]}" == $'\033[0m' ]
125+
}

0 commit comments

Comments
 (0)