This repository has been archived by the owner on Jun 14, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testnode.go
107 lines (88 loc) · 1.95 KB
/
testnode.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package main
import "strings"
type TestState int
const (
Unknown TestState = iota + 1
Passed
Failed
)
type testNode struct {
State TestState
Output []string
ChildrenByName map[string]*testNode
}
func newTestNode() *testNode {
return &testNode{
State: Unknown,
ChildrenByName: make(map[string]*testNode),
}
}
func (n *testNode) AppendOutput(output string) {
trimmed := strings.TrimSpace(output)
if trimmed == "FAIL" {
return
}
if strings.HasPrefix(trimmed, "exit status ") {
return
}
if strings.HasPrefix(trimmed, "coverage: ") && strings.HasSuffix(trimmed, " of statements") {
return
}
if strings.HasPrefix(trimmed, "FAIL\t") {
return
}
if strings.HasPrefix(trimmed, "PASS") {
return
}
if strings.HasPrefix(trimmed, "=== RUN ") {
return
}
if strings.HasPrefix(trimmed, "--- FAIL: ") {
return
}
if strings.HasPrefix(trimmed, "--- PASS: ") {
return
}
if strings.HasPrefix(trimmed, "? ") && strings.HasSuffix(trimmed, "\t[no test files]") {
return
}
n.Output = append(n.Output, trimmed)
}
func (n *testNode) Get(name string) *testNode {
next, rest := pathStep(name)
if next == "" {
return n
}
return n.childForNextPathStep(next).Get(rest)
}
func (n *testNode) MarkFailed(name string) {
n.State = Failed
next, rest := pathStep(name)
if next == "" {
return
}
n.childForNextPathStep(next).MarkFailed(rest)
}
func (n *testNode) MarkPassed(name string) {
next, rest := pathStep(name)
if next == "" {
n.State = Passed
return
}
n.childForNextPathStep(next).MarkPassed(rest)
}
func (n *testNode) childForNextPathStep(next string) *testNode {
child, ok := n.ChildrenByName[next]
if !ok {
child = newTestNode()
n.ChildrenByName[next] = child
}
return child
}
func pathStep(nodeName string) (next, rest string) {
separatorIndex := strings.IndexRune(nodeName, '/')
if separatorIndex < 0 {
return nodeName, ""
}
return nodeName[:separatorIndex], nodeName[separatorIndex+1:]
}