github.com/bytom/bytom@v1.1.2-0.20221014091027-bbcba3df6075/testutil/expect.go (about) 1 package testutil 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 "strings" 8 "testing" 9 10 "github.com/bytom/bytom/errors" 11 ) 12 13 var wd, _ = os.Getwd() 14 15 func FatalErr(t testing.TB, err error) { 16 args := []interface{}{err} 17 for _, frame := range errors.Stack(err) { 18 file := frame.File 19 if rel, err := filepath.Rel(wd, file); err == nil && !strings.HasPrefix(rel, "../") { 20 file = rel 21 } 22 funcname := frame.Func[strings.IndexByte(frame.Func, '.')+1:] 23 s := fmt.Sprintf("\n%s:%d: %s", file, frame.Line, funcname) 24 args = append(args, s) 25 } 26 t.Fatal(args...) 27 }