Skip to content

Commit c58bc90

Browse files
authored
Merge pull request #1764 from stretchr/dolmen/suite-refactor-stats-for-readability
suite.Run: refactor handling of stats for improved readability
2 parents 39b912b + 87101a6 commit c58bc90

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

suite/stats.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,30 @@ type TestInformation struct {
1616
}
1717

1818
func newSuiteInformation() *SuiteInformation {
19-
testStats := make(map[string]*TestInformation)
20-
2119
return &SuiteInformation{
22-
TestStats: testStats,
20+
TestStats: make(map[string]*TestInformation),
2321
}
2422
}
2523

26-
func (s SuiteInformation) start(testName string) {
24+
func (s *SuiteInformation) start(testName string) {
25+
if s == nil {
26+
return
27+
}
2728
s.TestStats[testName] = &TestInformation{
2829
TestName: testName,
2930
Start: time.Now(),
3031
}
3132
}
3233

33-
func (s SuiteInformation) end(testName string, passed bool) {
34+
func (s *SuiteInformation) end(testName string, passed bool) {
35+
if s == nil {
36+
return
37+
}
3438
s.TestStats[testName].End = time.Now()
3539
s.TestStats[testName].Passed = passed
3640
}
3741

38-
func (s SuiteInformation) Passed() bool {
42+
func (s *SuiteInformation) Passed() bool {
3943
for _, stats := range s.TestStats {
4044
if !stats.Passed {
4145
return false

suite/suite.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ func Run(t *testing.T, suite TestingSuite) {
161161

162162
r := recover()
163163

164-
if stats != nil {
165-
passed := !t.Failed() && r == nil
166-
stats.end(method.Name, passed)
167-
}
164+
stats.end(method.Name, !t.Failed() && r == nil)
168165

169166
if afterTestSuite, ok := suite.(AfterTest); ok {
170167
afterTestSuite.AfterTest(suiteName, method.Name)
@@ -185,9 +182,7 @@ func Run(t *testing.T, suite TestingSuite) {
185182
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
186183
}
187184

188-
if stats != nil {
189-
stats.start(method.Name)
190-
}
185+
stats.start(method.Name)
191186

192187
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
193188
},

0 commit comments

Comments
 (0)