summaryrefslogtreecommitdiff
path: root/test/recover.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2014-10-22 08:06:15 -0700
committerIan Lance Taylor <iant@golang.org>2014-10-22 08:06:15 -0700
commit87b95ba6c803d8477c306cbf184e69b13d7a5f05 (patch)
treebe8e02f1bc5f4c6d2d550f861df7f1f181818614 /test/recover.go
parent3eb09c52821e12f9e7acf06b34087985a3e9f7ab (diff)
downloadgo-87b95ba6c803d8477c306cbf184e69b13d7a5f05.tar.gz
test: add more cases to recover.go
test16 used to fail with gccgo. The withoutRecoverRecursive test would have failed in some possible implementations. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://codereview.appspot.com/151630043
Diffstat (limited to 'test/recover.go')
-rw-r--r--test/recover.go44
1 files changed, 41 insertions, 3 deletions
diff --git a/test/recover.go b/test/recover.go
index 6287d6507..f92c15c1d 100644
--- a/test/recover.go
+++ b/test/recover.go
@@ -63,6 +63,7 @@ func main() {
test14reflect1()
test14reflect2()
test15()
+ test16()
}
}
@@ -114,10 +115,23 @@ func withoutRecover() {
mustNotRecover() // because it's a sub-call
}
+func withoutRecoverRecursive(n int) {
+ if n == 0 {
+ withoutRecoverRecursive(1)
+ } else {
+ v := recover()
+ if v != nil {
+ println("spurious recover (recursive)", v)
+ die()
+ }
+ }
+}
+
func test1() {
- defer mustNotRecover() // because mustRecover will squelch it
- defer mustRecover(1) // because of panic below
- defer withoutRecover() // should be no-op, leaving for mustRecover to find
+ defer mustNotRecover() // because mustRecover will squelch it
+ defer mustRecover(1) // because of panic below
+ defer withoutRecover() // should be no-op, leaving for mustRecover to find
+ defer withoutRecoverRecursive(0) // ditto
panic(1)
}
@@ -547,3 +561,27 @@ func test15() {
defer f()
panic(15)
}
+
+func reflectFunc2(args []reflect.Value) (results []reflect.Value) {
+ // This will call reflectFunc3
+ args[0].Interface().(func())()
+ return nil
+}
+
+func reflectFunc3(args []reflect.Value) (results []reflect.Value) {
+ if v := recover(); v != nil {
+ println("spurious recover", v)
+ die()
+ }
+ return nil
+}
+
+func test16() {
+ defer mustRecover(16)
+
+ f2 := reflect.MakeFunc(reflect.TypeOf((func(func()))(nil)), reflectFunc2).Interface().(func(func()))
+ f3 := reflect.MakeFunc(reflect.TypeOf((func())(nil)), reflectFunc3).Interface().(func())
+ defer f2(f3)
+
+ panic(16)
+}