aboutsummaryrefslogtreecommitdiff
path: root/src/testing/example.go
diff options
context:
space:
mode:
authorChangkun Ou <hi@changkun.us>2020-08-31 20:54:17 +0200
committerEmmanuel Odeke <emm.odeke@gmail.com>2020-09-01 20:13:34 +0000
commitafa150c2ea1b121c7727c12ab3615fcc173d0d15 (patch)
treeb4dd1c2d1db7852a05fb1e1b6a7f8f17c1ca50fc /src/testing/example.go
parentac55d58fca4312fe4f84fa3a4761800803bc25e0 (diff)
downloadgo-afa150c2ea1b121c7727c12ab3615fcc173d0d15.tar.xz
testing: fail Example tests that invoke runtime.Goexit
Previously, if an example test invoked runtime.Goexit, it would pass yet hang until a timeout, while regular tests that invoke runtime.Goexit do fail. This change removes that inconsistent behavior and makes such example tests fail, and panic with an indication of having invoked runtime.Goexit. Fixes #41084 Change-Id: I0ffa152204f2b1580f4d5d6961ba1ce6b13fc022 Reviewed-on: https://go-review.googlesource.com/c/go/+/251857 Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com> Reviewed-by: Bryan C. Mills <bcmills@google.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/testing/example.go')
-rw-r--r--src/testing/example.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/testing/example.go b/src/testing/example.go
index adc91d5faf..0217c5d242 100644
--- a/src/testing/example.go
+++ b/src/testing/example.go
@@ -62,9 +62,10 @@ func sortLines(output string) string {
// If stdout doesn't match the expected output or if recovered is non-nil, it'll print the cause of failure to stdout.
// If the test is chatty/verbose, it'll print a success message to stdout.
// If recovered is non-nil, it'll panic with that value.
-func (eg *InternalExample) processRunResult(stdout string, timeSpent time.Duration, recovered interface{}) (passed bool) {
+// If the test panicked with nil, or invoked runtime.Goexit, it'll be
+// made to fail and panic with errNilPanicOrGoexit
+func (eg *InternalExample) processRunResult(stdout string, timeSpent time.Duration, finished bool, recovered interface{}) (passed bool) {
passed = true
-
dstr := fmtDuration(timeSpent)
var fail string
got := strings.TrimSpace(stdout)
@@ -78,16 +79,20 @@ func (eg *InternalExample) processRunResult(stdout string, timeSpent time.Durati
fail = fmt.Sprintf("got:\n%s\nwant:\n%s\n", got, want)
}
}
- if fail != "" || recovered != nil {
+ if fail != "" || !finished || recovered != nil {
fmt.Printf("--- FAIL: %s (%s)\n%s", eg.Name, dstr, fail)
passed = false
} else if *chatty {
fmt.Printf("--- PASS: %s (%s)\n", eg.Name, dstr)
}
+
if recovered != nil {
// Propagate the previously recovered result, by panicking.
panic(recovered)
}
+ if !finished && recovered == nil {
+ panic(errNilPanicOrGoexit)
+ }
return
}