summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/stretchr/testify/suite/suite.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/stretchr/testify/suite/suite.go')
-rw-r--r--vendor/github.com/stretchr/testify/suite/suite.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/vendor/github.com/stretchr/testify/suite/suite.go b/vendor/github.com/stretchr/testify/suite/suite.go
index db7413000..e20afbc21 100644
--- a/vendor/github.com/stretchr/testify/suite/suite.go
+++ b/vendor/github.com/stretchr/testify/suite/suite.go
@@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/require"
)
+var allTestsFilter = func(_, _ string) (bool, error) { return true, nil }
var matchMethod = flag.String("testify.m", "", "regular expression to select tests of the testify suite to run")
// Suite is a basic testing suite with methods for storing and
@@ -86,7 +87,13 @@ func Run(t *testing.T, suite TestingSuite) {
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
setupTestSuite.SetupTest()
}
+ if beforeTestSuite, ok := suite.(BeforeTest); ok {
+ beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
+ }
defer func() {
+ if afterTestSuite, ok := suite.(AfterTest); ok {
+ afterTestSuite.AfterTest(methodFinder.Elem().Name(), method.Name)
+ }
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
tearDownTestSuite.TearDownTest()
}
@@ -98,10 +105,20 @@ func Run(t *testing.T, suite TestingSuite) {
tests = append(tests, test)
}
}
+ runTests(t, tests)
+}
+
+func runTests(t testing.TB, tests []testing.InternalTest) {
+ r, ok := t.(runner)
+ if !ok { // backwards compatibility with Go 1.6 and below
+ if !testing.RunTests(allTestsFilter, tests) {
+ t.Fail()
+ }
+ return
+ }
- if !testing.RunTests(func(_, _ string) (bool, error) { return true, nil },
- tests) {
- t.Fail()
+ for _, test := range tests {
+ r.Run(test.Name, test.F)
}
}
@@ -113,3 +130,7 @@ func methodFilter(name string) (bool, error) {
}
return regexp.MatchString(*matchMethod, name)
}
+
+type runner interface {
+ Run(name string, f func(t *testing.T)) bool
+}