blob: 516fe06275262ebde61820d04fbf76cc7e21a41e [file] [log] [blame]
Jiri Simsad7616c92015-03-24 23:44:30 -07001// 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 Nicolaouc818b802015-06-05 15:52:45 -07005package testutil_test
Jiri Simsa5293dcb2014-05-10 09:56:38 -07006
7import (
8 "testing"
Cosmos Nicolaouc818b802015-06-05 15:52:45 -07009
10 "v.io/x/ref/test/testutil"
Jiri Simsa5293dcb2014-05-10 09:56:38 -070011)
12
13func 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 Nicolaouc818b802015-06-05 15:52:45 -070024 got := testutil.CallAndRecover(test.f)
Jiri Simsa5293dcb2014-05-10 09:56:38 -070025 if got != test.expect {
26 t.Errorf(`CallAndRecover got "%v", want "%v"`, got, test.expect)
27 }
28 }
29}