-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.go
95 lines (80 loc) · 1.61 KB
/
spec.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
package elicit
import (
"fmt"
"testing"
)
type spec struct {
context *Context
path string
name string
scenarios []*scenario
tables []stringTable
result result
}
type result int
const (
// Note: These are ordered by precedence
passed result = iota
skipped
pending
failed
panicked
numResultTypes
)
func (r result) shouldLog() bool {
return r > skipped
}
func (r result) String() string {
switch r {
case pending:
return "Pending"
case skipped:
return "Skipped"
case failed:
return "Failed"
case panicked:
return "Panicked"
case passed:
return "Passed"
default:
panic(fmt.Errorf("unknown result: %d", r))
}
}
func (s *spec) run(specT *testing.T) {
for _, scenario := range s.scenarios {
var hookErr error
if hookErr = s.context.beforeScenario.run("before scenario"); hookErr != nil {
scenario.result = panicked
}
specT.Run(scenario.name, func(scenarioT *testing.T) {
if hookErr != nil {
scenarioT.FailNow()
}
s.runScenario(scenarioT, scenario)
})
if scenario.result > s.result {
s.result = scenario.result
}
}
switch s.result {
case panicked, failed:
specT.Fail()
case skipped, pending:
specT.SkipNow()
}
}
func (s *spec) runScenario(scenarioT *testing.T, scenario *scenario) {
// Ensure the after scenario hooks are run regardless of the result
defer func() {
if hookErr := s.context.afterScenario.run("after scenario"); hookErr != nil {
scenario.result = panicked
scenarioT.FailNow()
}
}()
scenario.run(scenarioT)
}
func (s *spec) skipAllScenarios() {
for _, scenario := range s.scenarios {
scenario.result = skipped
}
}