| // Copyright 2020 The Go Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style |
| // license that can be found in the LICENSE file. |
| |
| package zx_test |
| |
| import ( |
| "testing" |
| ) |
| |
| func testPanicRecoverInner(t *testing.T, causePanic func()) { |
| defer func() { |
| if e := recover(); e == nil { |
| t.Error("failed to recover from panic") |
| } |
| }() |
| causePanic() |
| } |
| |
| func testPanicRecover(t *testing.T, causePanic func()) { |
| for i := 0; i < 10; i++ { |
| testPanicRecoverInner(t, causePanic) |
| } |
| } |
| |
| // NB: There's a similar test in the runtime package, but those don't run on |
| // Fuchsia yet. |
| func TestPanicRecoverMemoryAccess(t *testing.T) { |
| testPanicRecover(t, func() { |
| var x *int |
| *x = 0xF0BA |
| }) |
| } |