From 2566b669897c1e74a2c65da266eb3b9de2062a18 Mon Sep 17 00:00:00 2001 From: Boyan Date: Thu, 23 Apr 2020 21:42:41 +1000 Subject: [PATCH] Resolve conflicts --- suite/suite.go | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/suite/suite.go b/suite/suite.go index b666133..8bbc7c2 100644 --- a/suite/suite.go +++ b/suite/suite.go @@ -82,22 +82,24 @@ func (suite *Suite) Run(name string, subtest func()) bool { // Run takes a testing suite and runs all of the tests attached // to it. func Run(t *testing.T, suite TestingSuite) { - testsSync := &sync.WaitGroup{} - suite.SetT(t) defer failOnPanic(t) - suiteSetupDone := false + testsSync := &sync.WaitGroup{} + suite.SetT(t) + + var suiteSetupDone bool var stats *SuiteInformation - if _, ok := suite.(WithStats); ok { stats = newSuiteInformation() } - methodFinder := reflect.TypeOf(suite) tests := []testing.InternalTest{} - for index := 0; index < methodFinder.NumMethod(); index++ { - method := methodFinder.Method(index) + methodFinder := reflect.TypeOf(suite) + + for i := 0; i < methodFinder.NumMethod(); i++ { + method := methodFinder.Method(i) + ok, err := methodFilter(method.Name) if err != nil { fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err) @@ -111,6 +113,10 @@ func Run(t *testing.T, suite TestingSuite) { suiteName := methodFinder.Elem().Name() if !suiteSetupDone { + if stats != nil { + stats.Start = time.Now() + } + defer func() { if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok { testsSync.Wait() @@ -122,6 +128,7 @@ func Run(t *testing.T, suite TestingSuite) { suiteWithStats.HandleStats(suiteName, stats) } }() + if setupAllSuite, ok := suite.(SetupAllSuite); ok { setupAllSuite.SetupSuite() } @@ -151,6 +158,7 @@ func Run(t *testing.T, suite TestingSuite) { suite.SetT(parentT) }() + if setupTestSuite, ok := suite.(SetupTestSuite); ok { setupTestSuite.SetupTest() } @@ -158,6 +166,10 @@ func Run(t *testing.T, suite TestingSuite) { beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name) } + if stats != nil { + stats.start(method.Name) + } + method.Func.Call([]reflect.Value{reflect.ValueOf(suite)}) }, } @@ -167,6 +179,15 @@ func Run(t *testing.T, suite TestingSuite) { runTests(t, tests) } +// Filtering method according to set regular expression +// specified command-line argument -m +func methodFilter(name string) (bool, error) { + if ok, _ := regexp.MatchString("^Test", name); !ok { + return false, nil + } + return regexp.MatchString(*matchMethod, name) +} + func runTests(t testing.TB, tests []testing.InternalTest) { if len(tests) == 0 { t.Log("warning: no tests to run") @@ -186,15 +207,6 @@ func runTests(t testing.TB, tests []testing.InternalTest) { } } -// Filtering method according to set regular expression -// specified command-line argument -m -func methodFilter(name string) (bool, error) { - if ok, _ := regexp.MatchString("^Test", name); !ok { - return false, nil - } - return regexp.MatchString(*matchMethod, name) -} - type runner interface { Run(name string, f func(t *testing.T)) bool }