-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (82 loc) · 1.54 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
87
88
89
90
91
92
package main
import (
"fmt"
"io"
"os"
"regexp"
"sort"
"strings"
)
var resultRE = regexp.MustCompile(`^\s*--- (FAIL|SKIP|PASS): (Test\S+)`)
var blockRE = regexp.MustCompile(`^=== [A-Z]+\s+(Test\S+)`)
func main() {
var b []byte
if len(os.Args) > 1 {
file, err := os.Open(os.Args[1])
if err != nil {
panic(err)
}
b, err = io.ReadAll(file)
if err != nil {
panic(err)
}
} else {
var err error
b, err = io.ReadAll(os.Stdin)
if err != nil {
panic(err)
}
}
input := strings.Split(string(b), "\n")
type status struct {
isLeaf bool
status string
}
tests := make(map[string]*status)
for _, line := range input {
if m := resultRE.FindStringSubmatch(line); m != nil {
tests[m[2]] = &status{
isLeaf: true,
status: m[1],
}
if p := parent(m[2]); p != "" {
tests[p].isLeaf = false
}
}
}
var failed []string
for test, status := range tests {
if status.isLeaf && status.status == "FAIL" {
failed = append(failed, test)
}
}
if len(failed) == 0 {
fmt.Println("all passed")
return
}
sort.Strings(failed)
for _, test := range failed {
fmt.Println("###", test)
display := make(map[string]struct{})
for t := test; t != ""; t = parent(t) {
display[t] = struct{}{}
}
var printing bool
for _, line := range input {
if m := blockRE.FindStringSubmatch(line); m != nil {
_, ok := display[m[1]]
printing = ok
}
if printing {
fmt.Println(line)
}
}
}
}
func parent(s string) string {
i := strings.LastIndex(s, "/")
if i == -1 {
return ""
}
return s[0:i]
}