-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
86 lines (77 loc) · 1.71 KB
/
main.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package main
import (
"bufio"
"encoding/json"
"fmt"
"os"
"sort"
"time"
"github.com/gookit/color"
)
type TestLine struct {
Time time.Time `json:"Time"`
Action string `json:"Action"`
Package string `json:"Package"`
Test string `json:"Test"`
Output string `json:"Output,omitempty"`
Elapsed float32 `json:"Elapsed,omitempty"`
}
func main() {
// read from stdin line by line
fileScanner := bufio.NewScanner(os.Stdin)
red := color.FgRed.Render
green := color.FgGreen.Render
gray := color.FgGray.Render
result := map[string][]TestLine{}
for fileScanner.Scan() {
line := TestLine{}
jsonline := fileScanner.Text()
//fmt.Println(string(jsonline))
err := json.Unmarshal([]byte(jsonline), &line)
if err != nil {
panic(err)
}
if line.Test != "" {
result[line.Test] = append(result[line.Test], line)
}
}
keys := make([]string, 0, len(result))
for key := range result {
keys = append(keys, key)
}
sort.SliceStable(keys, func(i, j int) bool {
return findState(result[keys[i]]) > findState(result[keys[j]])
})
for _, v := range keys {
test := result[v]
showOutput := false
for _, line := range test {
if line.Action == "pass" {
fmt.Println(green("✔"), green(line.Test))
}
if line.Action == "fail" {
fmt.Println(red("✖"), red(line.Test))
showOutput = true
}
if line.Action == "skip" {
fmt.Println(line.Action, gray("-"), gray(line.Test))
}
if showOutput {
if line.Action == "output" {
fmt.Printf("\t%v", line.Output)
}
}
}
}
}
func findState(lines []TestLine) string {
for _, line := range lines {
if line.Action == "fail" {
return "fail"
}
if line.Action == "pass" {
return "pass"
}
}
return "skip"
}