mirror of
https://github.com/stretchr/testify.git
synced 2025-04-05 00:19:47 +00:00
Have testing.RunTests run the tests we find with their setup methods.
This commit is contained in:
parent
aff4bd8fb5
commit
5739ba4d16
@ -1,9 +1,9 @@
|
|||||||
package suite
|
package suite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Suite is a basic testing suite with methods for storing and
|
// Suite is a basic testing suite with methods for storing and
|
||||||
@ -32,19 +32,33 @@ func Run(t *testing.T, suite TestingSuite) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
methodFinder := reflect.TypeOf(suite)
|
methodFinder := reflect.TypeOf(suite)
|
||||||
|
tests := []testing.InternalTest{}
|
||||||
for index := 0; index < methodFinder.NumMethod(); index++ {
|
for index := 0; index < methodFinder.NumMethod(); index++ {
|
||||||
method := methodFinder.Method(index)
|
method := methodFinder.Method(index)
|
||||||
if ok, _ := regexp.MatchString("^Test", method.Name); ok {
|
if ok, _ := regexp.MatchString("^Test", method.Name); ok {
|
||||||
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
test := testing.InternalTest{
|
||||||
setupTestSuite.SetupTest()
|
Name: method.Name,
|
||||||
}
|
F: func(t *testing.T) {
|
||||||
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
suite.SetT(t)
|
||||||
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
|
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
||||||
tearDownTestSuite.TearDownTest()
|
setupTestSuite.SetupTest()
|
||||||
|
}
|
||||||
|
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
||||||
|
if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
|
||||||
|
tearDownTestSuite.TearDownTest()
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
tests = append(tests, test)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !testing.RunTests(func(pat, str string) (bool, error) {
|
||||||
|
return true, nil
|
||||||
|
}, tests) {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
|
||||||
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
||||||
tearDownAllSuite.TearDownSuite()
|
tearDownAllSuite.TearDownSuite()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user