This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdots.go
57 lines (52 loc) · 1.64 KB
/
dots.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*
Package dots implements a simple Cucumber formatter that prints
a single ANSI-coloured character for each step.
*/
package dots
import (
"fmt"
"github.com/cucumber/cucumber-messages-go/v5"
"github.com/fatih/color"
gio "github.com/gogo/protobuf/io"
"io"
)
func ProcessMessages(stdin io.Reader, stdout io.Writer) {
// We always want colors, regardless of the terminal.
// The reason being that language wrappers (Ruby, Java etc)
// want to capture colours regardless.
color.NoColor = false
r := gio.NewDelimitedReader(stdin, 4096)
for {
wrapper := &messages.Envelope{}
err := r.ReadMsg(wrapper)
if err == io.EOF {
break
}
switch m := wrapper.Message.(type) {
case *messages.Envelope_TestHookFinished:
switch m.TestHookFinished.TestResult.Status {
case messages.TestResult_FAILED:
color.New(color.FgRed).Fprint(stdout, "H")
}
case *messages.Envelope_TestStepFinished:
switch m.TestStepFinished.TestResult.Status {
// Keep the same order as in messages.proto - for readability's sake
case messages.TestResult_PASSED:
color.New(color.FgGreen).Fprint(stdout, ".")
case messages.TestResult_SKIPPED:
color.New(color.FgCyan).Fprint(stdout, "-")
case messages.TestResult_PENDING:
color.New(color.FgYellow).Fprint(stdout, "P")
case messages.TestResult_UNDEFINED:
color.New(color.FgYellow).Fprint(stdout, "U")
case messages.TestResult_AMBIGUOUS:
color.New(color.FgMagenta).Fprint(stdout, "A")
case messages.TestResult_FAILED:
color.New(color.FgRed).Fprint(stdout, "F")
case messages.TestResult_UNKNOWN:
color.New(color.FgBlue).Fprint(stdout, "?")
}
}
}
fmt.Fprint(stdout, "\n")
}