mirror of https://github.com/stretchr/testify.git
Resolve conflicts
parent
f238e4b70a
commit
2566b66989
|
@ -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
|
// Run takes a testing suite and runs all of the tests attached
|
||||||
// to it.
|
// to it.
|
||||||
func Run(t *testing.T, suite TestingSuite) {
|
func Run(t *testing.T, suite TestingSuite) {
|
||||||
testsSync := &sync.WaitGroup{}
|
|
||||||
suite.SetT(t)
|
|
||||||
defer failOnPanic(t)
|
defer failOnPanic(t)
|
||||||
|
|
||||||
suiteSetupDone := false
|
testsSync := &sync.WaitGroup{}
|
||||||
|
suite.SetT(t)
|
||||||
|
|
||||||
|
var suiteSetupDone bool
|
||||||
|
|
||||||
var stats *SuiteInformation
|
var stats *SuiteInformation
|
||||||
|
|
||||||
if _, ok := suite.(WithStats); ok {
|
if _, ok := suite.(WithStats); ok {
|
||||||
stats = newSuiteInformation()
|
stats = newSuiteInformation()
|
||||||
}
|
}
|
||||||
|
|
||||||
methodFinder := reflect.TypeOf(suite)
|
|
||||||
tests := []testing.InternalTest{}
|
tests := []testing.InternalTest{}
|
||||||
for index := 0; index < methodFinder.NumMethod(); index++ {
|
methodFinder := reflect.TypeOf(suite)
|
||||||
method := methodFinder.Method(index)
|
|
||||||
|
for i := 0; i < methodFinder.NumMethod(); i++ {
|
||||||
|
method := methodFinder.Method(i)
|
||||||
|
|
||||||
ok, err := methodFilter(method.Name)
|
ok, err := methodFilter(method.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
|
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()
|
suiteName := methodFinder.Elem().Name()
|
||||||
|
|
||||||
if !suiteSetupDone {
|
if !suiteSetupDone {
|
||||||
|
if stats != nil {
|
||||||
|
stats.Start = time.Now()
|
||||||
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
if tearDownAllSuite, ok := suite.(TearDownAllSuite); ok {
|
||||||
testsSync.Wait()
|
testsSync.Wait()
|
||||||
|
@ -122,6 +128,7 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
suiteWithStats.HandleStats(suiteName, stats)
|
suiteWithStats.HandleStats(suiteName, stats)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
|
if setupAllSuite, ok := suite.(SetupAllSuite); ok {
|
||||||
setupAllSuite.SetupSuite()
|
setupAllSuite.SetupSuite()
|
||||||
}
|
}
|
||||||
|
@ -151,6 +158,7 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
|
|
||||||
suite.SetT(parentT)
|
suite.SetT(parentT)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
if setupTestSuite, ok := suite.(SetupTestSuite); ok {
|
||||||
setupTestSuite.SetupTest()
|
setupTestSuite.SetupTest()
|
||||||
}
|
}
|
||||||
|
@ -158,6 +166,10 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
|
beforeTestSuite.BeforeTest(methodFinder.Elem().Name(), method.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if stats != nil {
|
||||||
|
stats.start(method.Name)
|
||||||
|
}
|
||||||
|
|
||||||
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
method.Func.Call([]reflect.Value{reflect.ValueOf(suite)})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -167,6 +179,15 @@ func Run(t *testing.T, suite TestingSuite) {
|
||||||
runTests(t, tests)
|
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) {
|
func runTests(t testing.TB, tests []testing.InternalTest) {
|
||||||
if len(tests) == 0 {
|
if len(tests) == 0 {
|
||||||
t.Log("warning: no tests to run")
|
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 {
|
type runner interface {
|
||||||
Run(name string, f func(t *testing.T)) bool
|
Run(name string, f func(t *testing.T)) bool
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue