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

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

want:
a
FAIL
exit status 1
@minux

This comment has been minimized.

Copy link
Member

@minux minux commented Aug 26, 2015

@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Aug 26, 2015

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

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

@ianlancetaylor ianlancetaylor 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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.