diff options
author | Josh Bleecher Snyder <josharian@gmail.com> | 2014-09-16 14:22:33 -0700 |
---|---|---|
committer | Josh Bleecher Snyder <josharian@gmail.com> | 2014-09-16 14:22:33 -0700 |
commit | b8bda7526a56e959b2aade18c392fb6e4d39e7b5 (patch) | |
tree | 297c6739143a168f2ce8160b0e5b728b28e0a388 /src | |
parent | 000836fa382e6a9806a176c6021f9b9c56277c8c (diff) | |
download | go-b8bda7526a56e959b2aade18c392fb6e4d39e7b5.tar.gz |
sync: simplify TestOncePanic
Follow-up to CL 137350043.
LGTM=r
R=r
CC=golang-codereviews
https://codereview.appspot.com/141620043
Diffstat (limited to 'src')
-rw-r--r-- | src/sync/once_test.go | 30 |
1 files changed, 12 insertions, 18 deletions
diff --git a/src/sync/once_test.go b/src/sync/once_test.go index 10beefde3..1eec8d18e 100644 --- a/src/sync/once_test.go +++ b/src/sync/once_test.go @@ -40,26 +40,20 @@ func TestOnce(t *testing.T) { } func TestOncePanic(t *testing.T) { - once := new(Once) - for i := 0; i < 2; i++ { - func() { - defer func() { - r := recover() - if r == nil && i == 0 { - t.Fatalf("Once.Do() has not panic'ed on first iteration") - } - if r != nil && i == 1 { - t.Fatalf("Once.Do() has panic'ed on second iteration") - } - }() - once.Do(func() { - panic("failed") - }) + var once Once + func() { + defer func() { + if r := recover(); r == nil { + t.Fatalf("Once.Do did not panic") + } }() - } - once.Do(func() {}) + once.Do(func() { + panic("failed") + }) + }() + once.Do(func() { - t.Fatalf("Once called twice") + t.Fatalf("Once.Do called twice") }) } |