Created
March 26, 2019 09:19
-
-
Save myitcv/3b3cd4447d1e2c38c6a80b1f91970273 to your computer and use it in GitHub Desktop.
testing.Helper failure in panic case
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "testing" | |
func Test(t *testing.T) { | |
blah(t, func() {}) | |
blah2(t, func() { panic("oh dear") }) | |
} | |
func blah(t *testing.T, f func()) { | |
t.Helper() | |
defer func() { | |
t.Helper() | |
err := recover() | |
if err == nil { | |
t.Errorf("expected panic") | |
} | |
}() | |
f() | |
} | |
func blah2(t *testing.T, f func()) { | |
t.Helper() | |
defer func() { | |
t.Helper() | |
err := recover() | |
if _, ok := err.(S); !ok { | |
t.Errorf("expected S, got %T", err) | |
} | |
}() | |
f() | |
} | |
type S struct{} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment