Run runs f as a subtest of t called name. It waits until the subtest is finished and returns whether the subtest succeeded.
(name string, f func(t *T))
| 498 | // Run runs f as a subtest of t called name. It waits until the subtest is finished |
| 499 | // and returns whether the subtest succeeded. |
| 500 | func (t *T) Run(name string, f func(t *T)) bool { |
| 501 | t.hasSub = true |
| 502 | testName, ok, _ := t.context.match.fullName(&t.common, name) |
| 503 | if !ok { |
| 504 | return true |
| 505 | } |
| 506 | |
| 507 | // Create a subtest. |
| 508 | ctx, cancelCtx := context.WithCancel(context.Background()) |
| 509 | sub := T{ |
| 510 | common: common{ |
| 511 | output: &logger{logToStdout: flagVerbose}, |
| 512 | name: testName, |
| 513 | parent: &t.common, |
| 514 | level: t.level + 1, |
| 515 | ctx: ctx, |
| 516 | cancelCtx: cancelCtx, |
| 517 | }, |
| 518 | context: t.context, |
| 519 | } |
| 520 | if t.level > 0 { |
| 521 | sub.indent = sub.indent + " " |
| 522 | } |
| 523 | if flagVerbose { |
| 524 | fmt.Fprintf(t.output, "=== RUN %s\n", sub.name) |
| 525 | } |
| 526 | |
| 527 | tRunner(&sub, f) |
| 528 | return !sub.failed |
| 529 | } |
| 530 | |
| 531 | // Deadline reports the time at which the test binary will have |
| 532 | // exceeded the timeout specified by the -timeout flag. |