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 | f1abe0d06bc94399c4abee041624efa36742fc1e (patch) | |
| tree | 3198379ab137f80ccac185caedad1eff41876d6b /src/sync | |
| parent | b22dc6385d66ac2e74afb9a5d503394fc7273d81 (diff) | |
| download | go-f1abe0d06bc94399c4abee041624efa36742fc1e.tar.xz | |
sync: simplify TestOncePanic
Follow-up to CL 137350043.
LGTM=r
R=r
CC=golang-codereviews
https://golang.org/cl/141620043
Diffstat (limited to 'src/sync')
| -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 10beefde35..1eec8d18ea 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") }) } |
