Jiri Simsa | d7616c9 | 2015-03-24 23:44:30 -0700 | [diff] [blame] | 1 | // Copyright 2015 The Vanadium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Cosmos Nicolaou | c818b80 | 2015-06-05 15:52:45 -0700 | [diff] [blame] | 5 | package testutil_test |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 6 | |
| 7 | import ( |
| 8 | "testing" |
Cosmos Nicolaou | c818b80 | 2015-06-05 15:52:45 -0700 | [diff] [blame] | 9 | |
| 10 | "v.io/x/ref/test/testutil" |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | func TestCallAndRecover(t *testing.T) { |
| 14 | tests := []struct { |
| 15 | f func() |
| 16 | expect interface{} |
| 17 | }{ |
| 18 | {func() {}, nil}, |
| 19 | {func() { panic(nil) }, nil}, |
| 20 | {func() { panic(123) }, 123}, |
| 21 | {func() { panic("abc") }, "abc"}, |
| 22 | } |
| 23 | for _, test := range tests { |
Cosmos Nicolaou | c818b80 | 2015-06-05 15:52:45 -0700 | [diff] [blame] | 24 | got := testutil.CallAndRecover(test.f) |
Jiri Simsa | 5293dcb | 2014-05-10 09:56:38 -0700 | [diff] [blame] | 25 | if got != test.expect { |
| 26 | t.Errorf(`CallAndRecover got "%v", want "%v"`, got, test.expect) |
| 27 | } |
| 28 | } |
| 29 | } |