github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/test/should/panic.go (about) 1 package should 2 3 import ( 4 "github.com/v2pro/plz/test" 5 "github.com/v2pro/plz/test/testify/assert" 6 "runtime" 7 ) 8 9 func Panic(f func()) (recovered interface{}) { 10 t := test.CurrentT() 11 test.Helper() 12 _, file, line, ok := runtime.Caller(1) 13 if !ok { 14 t.Error("check failed") 15 return 16 } 17 defer func() { 18 recovered = recover() 19 if assert.NotNil(t, recovered) { 20 return 21 } 22 t.Error(test.ExtractFailedLines(file, line)) 23 }() 24 f() 25 return nil 26 }