588
// failTest fails the test while dumping the stack, allowing us to know where in the code
589
// the failure arose.
590
>
func (tl *TestLogger) failTest(level Level, msg string, tags ...tag.Tag) {
testlogger.go
591
>
tl.state.t.Helper()
592
>
tl.recordFailure(level, msg, tags)
593
>
// skip captureStack, failTest, and the log.Logger function that called failTest
594
>
tl.state.t.Fatalf("%s\n%s", failureMessage(level, msg, tags), captureStack(3))
595
>
}
596
597
// captureStack returns a formatted stack trace, skipping the first `skip` frames
598
// (including the captureStack frame itself).
600
>
pcs := make([]uintptr, 128) // 128 is likely larger than we'll ever need.
601
>
frameCount := runtime.Callers(skip, pcs)
602
>
603
>
// runtime.Callers truncates the recorded stacktrace to fit the provided slice.
604
>
// Just keep doubling in size until we have enough space.
605
>
for frameCount == len(pcs) {
606
pcs = make([]uintptr, len(pcs)*2)
607
frameCount = runtime.Callers(skip, pcs)
608
}
609
610
>
stackFrames := runtime.CallersFrames(pcs[:frameCount])
testlogger.go
611
>
var stackTrace strings.Builder
612
>
for {
613
>
frame, more := stackFrames.Next()
614
>
fmt.Fprintf(&stackTrace, "%s:%d %s\n", frame.File, frame.Line, frame.Function)
615
>
if !more {
616
>
break
617
}
618
}
620
}
621