forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
problems.go
68 lines (59 loc) · 1.52 KB
/
problems.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
package reporting
import "fmt"
type problem struct {
out *Printer
errors []*AssertionResult
failures []*AssertionResult
}
func (self *problem) BeginStory(story *StoryReport) {}
func (self *problem) Enter(scope *ScopeReport) {}
func (self *problem) Report(report *AssertionResult) {
if report.Error != nil {
self.errors = append(self.errors, report)
} else if report.Failure != "" {
self.failures = append(self.failures, report)
}
}
func (self *problem) Exit() {}
func (self *problem) EndStory() {
self.show(self.showErrors, redColor)
self.show(self.showFailures, yellowColor)
self.prepareForNextStory()
}
func (self *problem) show(display func(), color string) {
fmt.Print(color)
display()
fmt.Print(resetColor)
self.out.Dedent()
}
func (self *problem) showErrors() {
for i, e := range self.errors {
if i == 0 {
self.out.Println("\nErrors:\n")
self.out.Indent()
}
self.out.Println(errorTemplate, e.File, e.Line, e.Error, e.StackTrace)
}
}
func (self *problem) showFailures() {
for i, f := range self.failures {
if i == 0 {
self.out.Println("\nFailures:\n")
self.out.Indent()
}
self.out.Println(failureTemplate, f.File, f.Line, f.Failure)
}
}
func (self *problem) Write(content []byte) (written int, err error) {
return len(content), nil // no-op
}
func NewProblemReporter(out *Printer) *problem {
self := new(problem)
self.out = out
self.prepareForNextStory()
return self
}
func (self *problem) prepareForNextStory() {
self.errors = []*AssertionResult{}
self.failures = []*AssertionResult{}
}