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

Closed
alexcesaro opened this issue Aug 26, 2015 · 3 comments
Closed

testing: examples do not always capture stdout #12348

alexcesaro opened this issue Aug 26, 2015 · 3 comments

Comments

@alexcesaro
Copy link
Contributor

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() {
    f.WriteString("a")
    // Output:
    // a
}
$ go test
a--- FAIL: Example (0.00s)
got:

want:
a
FAIL
exit status 1
@minux
Copy link
Member

minux commented Aug 26, 2015 via email

@gopherbot
Copy link

CL https://golang.org/cl/13927 mentions this issue.

@ianlancetaylor
Copy link
Contributor

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.
Projects
None yet
Development

No branches or pull requests

4 participants