Skip to content

Instantly share code, notes, and snippets.

@myitcv
Created March 26, 2019 09:19
Show Gist options
  • Save myitcv/3b3cd4447d1e2c38c6a80b1f91970273 to your computer and use it in GitHub Desktop.
Save myitcv/3b3cd4447d1e2c38c6a80b1f91970273 to your computer and use it in GitHub Desktop.
testing.Helper failure in panic case
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