Skip to content

testing: examples do not always capture stdout #12348

@alexcesaro

Description

@alexcesaro

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions