MCPcopy
hub / github.com/stretchr/testify / Run

Function Run

suite/suite.go:126–226  ·  view source on GitHub ↗

Run takes a testing suite and runs all of the tests attached to it.

(t *testing.T, suite TestingSuite)

Source from the content-addressed store, hash-verified

124// Run takes a testing suite and runs all of the tests attached
125// to it.
126func Run(t *testing.T, suite TestingSuite) {
127 defer recoverAndFailOnPanic(t)
128
129 suite.SetT(t)
130 suite.SetS(suite)
131
132 var stats *SuiteInformation
133 if _, ok := suite.(WithStats); ok {
134 stats = newSuiteInformation()
135 }
136
137 var tests []test
138 methodFinder := reflect.TypeOf(suite)
139 suiteName := methodFinder.Elem().Name()
140
141 var matchMethodRE *regexp.Regexp
142 if *matchMethod != "" {
143 var err error
144 matchMethodRE, err = regexp.Compile(*matchMethod)
145 if err != nil {
146 fmt.Fprintf(os.Stderr, "testify: invalid regexp for -m: %s\n", err)
147 os.Exit(1)
148 }
149 }
150
151 for i := 0; i < methodFinder.NumMethod(); i++ {
152 method := methodFinder.Method(i)
153
154 if !strings.HasPrefix(method.Name, "Test") {
155 continue
156 }
157 // Apply -testify.m filter
158 if matchMethodRE != nil && !matchMethodRE.MatchString(method.Name) {
159 continue
160 }
161
162 test := test{
163 name: method.Name,
164 run: func(t *testing.T) {
165 parentT := suite.T()
166 suite.SetT(t)
167 defer recoverAndFailOnPanic(t)
168 defer func() {
169 t.Helper()
170
171 r := recover()
172
173 stats.end(method.Name, !t.Failed() && r == nil)
174
175 if afterTestSuite, ok := suite.(AfterTest); ok {
176 afterTestSuite.AfterTest(suiteName, method.Name)
177 }
178
179 if tearDownTestSuite, ok := suite.(TearDownTestSuite); ok {
180 tearDownTestSuite.TearDownTest()
181 }
182
183 suite.SetT(parentT)

Callers 9

TestSuiteRequireTwiceFunction · 0.85
TestSuiteRecoverPanicFunction · 0.85
TestRunSuiteFunction · 0.85
TestSkippingSuiteSetupFunction · 0.85
TestSuiteLoggingFunction · 0.85
TestSuiteCallOrderFunction · 0.85
TestSuiteWithStatsFunction · 0.85
TestFailfastSuiteFunction · 0.85
TestSubtestPanicFunction · 0.85

Calls 15

endMethod · 0.95
startMethod · 0.95
recoverAndFailOnPanicFunction · 0.85
newSuiteInformationFunction · 0.85
failOnPanicFunction · 0.85
runTestsFunction · 0.85
FailedMethod · 0.80
SetTMethod · 0.65
SetSMethod · 0.65
NameMethod · 0.65
TMethod · 0.65
HelperMethod · 0.65

Tested by 9

TestSuiteRequireTwiceFunction · 0.68
TestSuiteRecoverPanicFunction · 0.68
TestRunSuiteFunction · 0.68
TestSkippingSuiteSetupFunction · 0.68
TestSuiteLoggingFunction · 0.68
TestSuiteCallOrderFunction · 0.68
TestSuiteWithStatsFunction · 0.68
TestFailfastSuiteFunction · 0.68
TestSubtestPanicFunction · 0.68