MCPcopy Index your code
hub / github.com/jetify-com/devbox / TestStackTrace

Function TestStackTrace

internal/redact/redact_test.go:228–250  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

226}
227
228func TestStackTrace(t *testing.T) {
229 err := Errorf("error")
230 stack := err.(interface{ StackTrace() []runtime.Frame }).StackTrace()
231 if len(stack) == 0 {
232 t.Fatal("got empty stack trace")
233 }
234 stackTrace := "got stack trace:\n"
235 for _, frame := range stack {
236 stackTrace += fmt.Sprintf("%v\n", frame)
237 }
238 t.Log(stackTrace)
239
240 if !strings.HasSuffix(stack[0].Function, t.Name()) {
241 t.Errorf("got stack starting with function name %q, want function ending with test name %q",
242 stack[0].Function, t.Name())
243 }
244 lastFrame := stack[len(stack)-1]
245 wantFrame := "runtime.goexit"
246 if lastFrame.Function != wantFrame {
247 t.Errorf("got stack ending with function name %q, want function name %q",
248 lastFrame.Function, wantFrame)
249 }
250}
251
252func TestMissingStackTrace(t *testing.T) {
253 var err interface{ StackTrace() []runtime.Frame } = &safeError{}

Callers

nothing calls this directly

Calls 2

ErrorfFunction · 0.85
StackTraceMethod · 0.65

Tested by

no test coverage detected