Skip to content

Commit 2cb8dce

Browse files
committed
testing: SkipNow, FailNow must be called from test goroutine
Impossible for us to check (without sleazily reaching into the runtime) but at least document it. Fixes #3800. R=golang-dev, bradfitz, dave CC=golang-dev https://golang.org/cl/7268043
1 parent 6d175e2 commit 2cb8dce

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

Diff for: src/pkg/testing/testing.go

+18-11
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ func (c *common) Failed() bool {
212212

213213
// FailNow marks the function as having failed and stops its execution.
214214
// Execution will continue at the next test or benchmark.
215+
// FailNow must be called from the goroutine running the
216+
// test or benchmark function, not from other goroutines
217+
// created during the test. Calling FailNow does not stop
218+
// those other goroutines.
215219
func (c *common) FailNow() {
216220
c.Fail()
217221

@@ -244,33 +248,33 @@ func (c *common) log(s string) {
244248
c.output = append(c.output, decorate(s)...)
245249
}
246250

247-
// Log formats its arguments using default formatting, analogous to Println(),
251+
// Log formats its arguments using default formatting, analogous to Println,
248252
// and records the text in the error log.
249253
func (c *common) Log(args ...interface{}) { c.log(fmt.Sprintln(args...)) }
250254

251-
// Logf formats its arguments according to the format, analogous to Printf(),
255+
// Logf formats its arguments according to the format, analogous to Printf,
252256
// and records the text in the error log.
253257
func (c *common) Logf(format string, args ...interface{}) { c.log(fmt.Sprintf(format, args...)) }
254258

255-
// Error is equivalent to Log() followed by Fail().
259+
// Error is equivalent to Log followed by Fail.
256260
func (c *common) Error(args ...interface{}) {
257261
c.log(fmt.Sprintln(args...))
258262
c.Fail()
259263
}
260264

261-
// Errorf is equivalent to Logf() followed by Fail().
265+
// Errorf is equivalent to Logf followed by Fail.
262266
func (c *common) Errorf(format string, args ...interface{}) {
263267
c.log(fmt.Sprintf(format, args...))
264268
c.Fail()
265269
}
266270

267-
// Fatal is equivalent to Log() followed by FailNow().
271+
// Fatal is equivalent to Log followed by FailNow.
268272
func (c *common) Fatal(args ...interface{}) {
269273
c.log(fmt.Sprintln(args...))
270274
c.FailNow()
271275
}
272276

273-
// Fatalf is equivalent to Logf() followed by FailNow().
277+
// Fatalf is equivalent to Logf followed by FailNow.
274278
func (c *common) Fatalf(format string, args ...interface{}) {
275279
c.log(fmt.Sprintf(format, args...))
276280
c.FailNow()
@@ -345,20 +349,23 @@ func (t *T) report() {
345349
}
346350
}
347351

348-
// Skip is equivalent to Log() followed by SkipNow().
352+
// Skip is equivalent to Log followed by SkipNow.
349353
func (t *T) Skip(args ...interface{}) {
350354
t.log(fmt.Sprintln(args...))
351355
t.SkipNow()
352356
}
353357

354-
// Skipf is equivalent to Logf() followed by SkipNow().
358+
// Skipf is equivalent to Logf followed by SkipNow.
355359
func (t *T) Skipf(format string, args ...interface{}) {
356360
t.log(fmt.Sprintf(format, args...))
357361
t.SkipNow()
358362
}
359363

360-
// SkipNow marks the function as having been skipped and stops its execution.
361-
// Execution will continue at the next test or benchmark. See also, t.FailNow.
364+
// SkipNow marks the test as having been skipped and stops its execution.
365+
// Execution will continue at the next test or benchmark. See also FailNow.
366+
// SkipNow must be called from the goroutine running the test, not from
367+
// other goroutines created during the test. Calling SkipNow does not stop
368+
// those other goroutines.
362369
func (t *T) SkipNow() {
363370
t.skip()
364371
runtime.Goexit()
@@ -370,7 +377,7 @@ func (t *T) skip() {
370377
t.skipped = true
371378
}
372379

373-
// Skipped reports whether the function was skipped.
380+
// Skipped reports whether the test was skipped.
374381
func (t *T) Skipped() bool {
375382
t.mu.RLock()
376383
defer t.mu.RUnlock()

0 commit comments

Comments
 (0)