{"action":"created","issue":{"url":"https://api.github.com/repos/golang/go/issues/12348","labels_url":"https://api.github.com/repos/golang/go/issues/12348/labels{/name}","comments_url":"https://api.github.com/repos/golang/go/issues/12348/comments","events_url":"https://api.github.com/repos/golang/go/issues/12348/events","html_url":"https://github.com/golang/go/issues/12348","id":103359402,"number":12348,"title":"testing: examples do not always capture stdout","user":{"login":"alexcesaro","id":832479,"avatar_url":"https://avatars.githubusercontent.com/u/832479?v=3","gravatar_id":"","url":"https://api.github.com/users/alexcesaro","html_url":"https://github.com/alexcesaro","followers_url":"https://api.github.com/users/alexcesaro/followers","following_url":"https://api.github.com/users/alexcesaro/following{/other_user}","gists_url":"https://api.github.com/users/alexcesaro/gists{/gist_id}","starred_url":"https://api.github.com/users/alexcesaro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexcesaro/subscriptions","organizations_url":"https://api.github.com/users/alexcesaro/orgs","repos_url":"https://api.github.com/users/alexcesaro/repos","events_url":"https://api.github.com/users/alexcesaro/events{/privacy}","received_events_url":"https://api.github.com/users/alexcesaro/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-08-26T20:41:19Z","updated_at":"2015-08-26T21:42:02Z","closed_at":null,"body":"Examples do not capture stdout when os.Stdout is assigned to a variable outside the example body:\r\n\r\n```go\r\n// foo_test.go\r\npackage foo\r\n\r\nimport \"os\"\r\n\r\nvar f = os.Stdout\r\n\r\nfunc Example() {\r\n\tf.WriteString(\"a\")\r\n\t// Output:\r\n\t// a\r\n}\r\n```\r\n\r\n```\r\n$ go test\r\na--- FAIL: Example (0.00s)\r\ngot:\r\n\r\nwant:\r\na\r\nFAIL\r\nexit status 1\r\n```"},"comment":{"url":"https://api.github.com/repos/golang/go/issues/comments/135178664","html_url":"https://github.com/golang/go/issues/12348#issuecomment-135178664","issue_url":"https://api.github.com/repos/golang/go/issues/12348","id":135178664,"user":{"login":"minux","id":135652,"avatar_url":"https://avatars.githubusercontent.com/u/135652?v=3","gravatar_id":"","url":"https://api.github.com/users/minux","html_url":"https://github.com/minux","followers_url":"https://api.github.com/users/minux/followers","following_url":"https://api.github.com/users/minux/following{/other_user}","gists_url":"https://api.github.com/users/minux/gists{/gist_id}","starred_url":"https://api.github.com/users/minux/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/minux/subscriptions","organizations_url":"https://api.github.com/users/minux/orgs","repos_url":"https://api.github.com/users/minux/repos","events_url":"https://api.github.com/users/minux/events{/privacy}","received_events_url":"https://api.github.com/users/minux/received_events","type":"User","site_admin":false},"created_at":"2015-08-26T21:42:02Z","updated_at":"2015-08-26T21:42:02Z","body":"I think this is reasonable limitation, f is assigned before the\ntesting package can replace it. If the example author does\nthis, then it's probably intentional to bypass the output\ncapture.\n"}}