/
ginkgo.go
91 lines (76 loc) · 1.92 KB
/
ginkgo.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
package ginkgo
import (
"fmt"
"io"
"strings"
"github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/config"
"github.com/onsi/ginkgo/types"
)
func testsForSuite(cfg config.GinkgoConfigType) ([]*testCase, error) {
iter := ginkgo.GlobalSuite().Iterator(cfg)
var tests []*testCase
for {
spec, err := iter.Next()
if err != nil {
if err.Error() == "no more specs to run" {
break
}
return nil, err
}
tests = append(tests, newTestCase(spec))
}
return tests, nil
}
type ginkgoSpec interface {
Run(io.Writer)
ConcatenatedString() string
Skip()
Skipped() bool
Failed() bool
Passed() bool
Summary(suiteID string) *types.SpecSummary
}
type MinimalReporter struct {
name string
location types.CodeLocation
spec *types.SpecSummary
setup *types.SetupSummary
}
func NewMinimalReporter(name string, location types.CodeLocation) *MinimalReporter {
return &MinimalReporter{
name: name,
location: location,
}
}
func (r *MinimalReporter) Fail() {
}
func (r *MinimalReporter) Summary() (*types.SpecSummary, *types.SetupSummary) {
return r.spec, r.setup
}
func (r *MinimalReporter) SpecSuiteWillBegin(config config.GinkgoConfigType, summary *types.SuiteSummary) {
}
func (r *MinimalReporter) BeforeSuiteDidRun(setup *types.SetupSummary) {
r.setup = setup
}
func (r *MinimalReporter) SpecWillRun(spec *types.SpecSummary) {
}
func (r *MinimalReporter) SpecDidComplete(spec *types.SpecSummary) {
if spec.ComponentCodeLocations[len(spec.ComponentCodeLocations)-1] != r.location {
return
}
if specName(spec) != r.name {
return
}
if r.spec != nil {
panic(fmt.Sprintf("spec was set twice: %q and %q", specName(r.spec), specName(spec)))
}
r.spec = spec
}
func (r *MinimalReporter) AfterSuiteDidRun(setupSummary *types.SetupSummary) {
}
func (r *MinimalReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
}
func specName(spec *types.SpecSummary) string {
return strings.Join(spec.ComponentTexts[1:], " ")
}