Skip to content

Commit 733366a

Browse files
nikita-dubrovskiidustymabe
authored andcommitted
mantle/kola: add colors to highlight tests results
Removed the "Warn" parts from the cherry pick to make it compile because we didn't backport the warn:true stuff here. (cherry picked from commit a191716)
1 parent 37016ce commit 733366a

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

mantle/harness/harness.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ func (t *H) report() {
609609

610610
status := t.status()
611611
if status == testresult.Fail || t.suite.opts.Verbose {
612-
t.flushToParent(format, status, t.name, dstr)
612+
t.flushToParent(format, status.Display(), t.name, dstr)
613613
}
614614

615615
// TODO: store multiple buffers for subtests without indentation

mantle/harness/harness_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func TestContextCancel(t *testing.T) {
7676
}
7777

7878
func TestSubTests(t *testing.T) {
79+
// When TERM is set, we add colors to highlight tests results: '--- FAIL' will be in red '--- \033[31mFAIL\033[0m'
80+
// Let's unset it here for simplicity
81+
os.Unsetenv("TERM")
7982
realTest := t
8083
testCases := []struct {
8184
desc string

mantle/harness/testresult/status.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,31 @@
1414

1515
package testresult
1616

17+
import "os"
18+
1719
const (
1820
Fail TestResult = "FAIL"
1921
Skip TestResult = "SKIP"
2022
Pass TestResult = "PASS"
2123
)
2224

2325
type TestResult string
26+
27+
func (s TestResult) Display() string {
28+
if term, has_term := os.LookupEnv("TERM"); !has_term || term == "" {
29+
return string(s)
30+
}
31+
32+
red := "\033[31m"
33+
blue := "\033[34m"
34+
green := "\033[32m"
35+
reset := "\033[0m"
36+
37+
if s == Fail {
38+
return red + string(s) + reset
39+
} else if s == Skip {
40+
return blue + string(s) + reset
41+
} else {
42+
return green + string(s) + reset
43+
}
44+
}

0 commit comments

Comments
 (0)