mirror of
https://github.com/stretchr/testify.git
synced 2025-09-04 19:35:26 +00:00
Refactor handling of stats in suite.Run with the goal of reducing indented blocks to improve readability. To achieve this, the SuiteInformation methods now handle being called with a nil receiver to work as noop. This allows to call them from suite.Run without nil checks blocks, so with improved readability.
51 lines
973 B
Go
51 lines
973 B
Go
package suite
|
|
|
|
import "time"
|
|
|
|
// SuiteInformation stats stores stats for the whole suite execution.
|
|
type SuiteInformation struct {
|
|
Start, End time.Time
|
|
TestStats map[string]*TestInformation
|
|
}
|
|
|
|
// TestInformation stores information about the execution of each test.
|
|
type TestInformation struct {
|
|
TestName string
|
|
Start, End time.Time
|
|
Passed bool
|
|
}
|
|
|
|
func newSuiteInformation() *SuiteInformation {
|
|
return &SuiteInformation{
|
|
TestStats: make(map[string]*TestInformation),
|
|
}
|
|
}
|
|
|
|
func (s *SuiteInformation) start(testName string) {
|
|
if s == nil {
|
|
return
|
|
}
|
|
s.TestStats[testName] = &TestInformation{
|
|
TestName: testName,
|
|
Start: time.Now(),
|
|
}
|
|
}
|
|
|
|
func (s *SuiteInformation) end(testName string, passed bool) {
|
|
if s == nil {
|
|
return
|
|
}
|
|
s.TestStats[testName].End = time.Now()
|
|
s.TestStats[testName].Passed = passed
|
|
}
|
|
|
|
func (s *SuiteInformation) Passed() bool {
|
|
for _, stats := range s.TestStats {
|
|
if !stats.Passed {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|