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.go76
1 files changed, 41 insertions, 35 deletions
diff --git a/vendor/github.com/stretchr/testify/suite/suite.go b/vendor/github.com/stretchr/testify/suite/suite.go
index 5cea8f8c..d708d7d7 100644
--- a/vendor/github.com/stretchr/testify/suite/suite.go
+++ b/vendor/github.com/stretchr/testify/suite/suite.go
@@ -6,6 +6,7 @@ import (
"os"
"reflect"
"regexp"
+ "runtime/debug"
"testing"
"github.com/stretchr/testify/assert"
@@ -58,7 +59,7 @@ func (suite *Suite) Assert() *assert.Assertions {
func failOnPanic(t *testing.T) {
r := recover()
if r != nil {
- t.Errorf("test panicked: %v", r)
+ t.Errorf("test panicked: %v\n%s", r, debug.Stack())
t.FailNow()
}
}
@@ -82,15 +83,8 @@ func Run(t *testing.T, suite TestingSuite) {
suite.SetT(t)
defer failOnPanic(t)
- if setupAllSuite, ok := suite.(SetupAllSuite); ok {
- setupAllSuite.SetupSuite()
- }
- defer func() {
- if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
- tearDownAllSuite.TearDownSuite()
- }
- }()
-
+ suiteSetupDone := false
+
methodFinder := reflect.TypeOf(suite)
tests := []testing.InternalTest{}
for index := 0; index < methodFinder.NumMethod(); index++ {
@@ -100,34 +94,46 @@ func Run(t *testing.T, suite TestingSuite) {
fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
os.Exit(1)
}
- if ok {
- test := testing.InternalTest{
- Name: method.Name,
- F: func(t *testing.T) {
- parentT := suite.T()
- suite.SetT(t)
- defer failOnPanic(t)
-
- if setupTestSuite, ok := suite.(SetupTestSuite); ok {
- setupTestSuite.SetupTest()
+ if !ok {
+ continue
+ }
+ if !suiteSetupDone {
+ if setupAllSuite, ok := suite.(SetupAllSuite); ok {
+ setupAllSuite.SetupSuite()
+ }
+ defer func() {
+ if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
+ tearDownAllSuite.TearDownSuite()
+ }
+ }()
+ suiteSetupDone = true
+ }
+ test := testing.InternalTest{
+ Name: method.Name,
+ F: func(t *testing.T) {
+ parentT := suite.T()
+ suite.SetT(t)
+ defer failOnPanic(t)
+
+ 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 beforeTestSuite, ok := suite.(BeforeTest); ok {
- beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
+ if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
+ tearDownTestSuite.TearDownTest()
}
- defer func() {
- if afterTestSuite, ok := suite.(AfterTest); ok {
- afterTestSuite.AfterTest(methodFinder.Elem().Name(), method.Name)
- }
- if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
- tearDownTestSuite.TearDownTest()
- }
- suite.SetT(parentT)
- }()
- method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
- },
- }
- tests = append(tests, test)
+ suite.SetT(parentT)
+ }()
+ method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
+ },
}
+ tests = append(tests, test)
}
runTests(t, tests)
}