From db4863c05e4d4bcbd40caf459d29e2eee81f847b Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Sat, 9 Nov 2024 21:44:24 +0800 Subject: [PATCH] runtime: make Frames example produce documented output Fixes #70057 Change-Id: I286822f844fcb95fa8b55bfc30fe472d0ba11de0 --- src/runtime/example_test.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/runtime/example_test.go b/src/runtime/example_test.go index dcb8f7798e..eae9dbd7bf 100644 --- a/src/runtime/example_test.go +++ b/src/runtime/example_test.go @@ -32,15 +32,14 @@ func ExampleFrames() { for { frame, more := frames.Next() - // Process this frame. - // - // To keep this example's output stable - // even if there are changes in the testing package, - // stop unwinding when we leave package runtime. - if !strings.Contains(frame.File, "runtime/") { + // Canonicalize function name and skip callers of this function + // for predictable example output. + // You probably don't need this in your own code. + function := strings.ReplaceAll(frame.Function, "main.main", "runtime_test.ExampleFrames") + fmt.Printf("- more:%v | %s\n", more, function) + if function == "runtime_test.ExampleFrames" { break } - fmt.Printf("- more:%v | %s\n", more, frame.Function) // Check whether there are more frames to process after this one. if !more {