Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testing: examples do not always capture stdout #12348

alexcesaro opened this issue Aug 26, 2015 · 3 comments


None yet
4 participants
Copy link

commented Aug 26, 2015

Examples do not capture stdout when os.Stdout is assigned to a variable outside the example body:

// foo_test.go
package foo

import "os"

var f = os.Stdout

func Example() {
    // Output:
    // a
$ go test
a--- FAIL: Example (0.00s)

exit status 1

This comment has been minimized.

Copy link

commented Aug 26, 2015


This comment has been minimized.

Copy link

commented Aug 26, 2015

CL mentions this issue.


This comment has been minimized.

Copy link

commented Aug 27, 2015

It doesn't work, so, don't do that. Examples are a convenience feature for documentation, not something that has to work no matter what the program does.

@golang golang locked and limited conversation to collaborators Sep 4, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.