github.com/v2pro/plz@v0.0.0-20221028024117-e5f9aec5b631/test/must/panic.go (about)

     1  package must
     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.Fatal("check failed")
    15  		return
    16  	}
    17  	defer func() {
    18  		recovered = recover()
    19  		if assert.NotNil(t, recovered) {
    20  			return
    21  		}
    22  		t.Fatal(test.ExtractFailedLines(file, line))
    23  	}()
    24  	f()
    25  	return nil
    26  }