]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: make example independent of inlining
authorDavid Lazar <lazard@golang.org>
Tue, 18 Apr 2017 14:47:27 +0000 (10:47 -0400)
committerDavid Lazar <lazard@golang.org>
Tue, 18 Apr 2017 19:56:36 +0000 (19:56 +0000)
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 <lazard@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
src/runtime/example_test.go

index f817b595e6bba95fefbbe150ce51e1559165dffb..69619b1087c999645d727c60a2edf836a7256b33 100644 (file)
@@ -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
 }