From 7821be59519b65182e4399425b6e6d908252c11b Mon Sep 17 00:00:00 2001 From: David Lazar Date: Tue, 18 Apr 2017 10:47:27 -0400 Subject: [PATCH] runtime: make example independent of inlining Otherwise, with -l=4, runtime.Callers gets inlined and the example prints too many frames. Now the example passes with -l=4. Change-Id: I9e420af9371724ac3ec89efafd76a658cf82bb4a Reviewed-on: https://go-review.googlesource.com/40876 Run-TryBot: David Lazar TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Austin Clements --- src/runtime/example_test.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/runtime/example_test.go b/src/runtime/example_test.go index f817b595e6..69619b1087 100644 --- a/src/runtime/example_test.go +++ b/src/runtime/example_test.go @@ -19,10 +19,9 @@ func ExampleFrames() { frames := runtime.CallersFrames(pc[:n]) var frame runtime.Frame - more := true - for more { + for i, more := 0, true; more && i < 5; i++ { frame, more = frames.Next() - fmt.Printf("- more:%v | %s\n", more, frame.Function) + fmt.Printf("- %s\n", frame.Function) } } @@ -31,9 +30,9 @@ func ExampleFrames() { a() // Output: - // - more:true | runtime.Callers - // - more:true | runtime_test.ExampleFrames.func1 - // - more:true | runtime_test.ExampleFrames.func2 - // - more:true | runtime_test.ExampleFrames.func3 - // - more:false | runtime_test.ExampleFrames + // - runtime.Callers + // - runtime_test.ExampleFrames.func1 + // - runtime_test.ExampleFrames.func2 + // - runtime_test.ExampleFrames.func3 + // - runtime_test.ExampleFrames } -- 2.48.1