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

go/doc: example should not include test functions #37900

Closed
rhcarvalho opened this issue Mar 17, 2020 · 4 comments
Closed

go/doc: example should not include test functions #37900

rhcarvalho opened this issue Mar 17, 2020 · 4 comments

Comments

@rhcarvalho
Copy link
Contributor

@rhcarvalho rhcarvalho commented Mar 17, 2020

What version of Go are you using (go version)?

$ go version
go1.14

Does this issue reproduce with the latest release?

Yes and tip as well.

What operating system and processor architecture are you using (go env)?

Not revelant.

What did you do?

Visited https://golang.org/pkg/errors/#example_As.

Then visited https://godoc.org/errors#example-As and https://pkg.go.dev/errors/?tab=doc#example-As to compare, same problem.

What did you expect to see?

As per documented in https://golang.org/pkg/testing/#hdr-Examples (emphasis mine):

The entire test file is presented as the example when it contains a single example function, at least one other function, type, variable, or constant declaration, and no test or benchmark functions.

I expected to see the example for using errors.As, a rather small snippet containing:

   if _, err := os.Open("non-existing"); err != nil {
        var pathError *os.PathError
        if errors.As(err, &pathError) {
            fmt.Println("Failed at path:", pathError.Path)
        } else {
            fmt.Println(err)
        }
    }

As defined in https://golang.org/src/errors/wrap_test.go?s=4623:4893#L241.

What did you see instead?

A large amount of code containing tests defined in https://golang.org/src/errors/wrap_test.go, with the actual example code transformed into a func main at the very bottom.

image

image

@agnivade
Copy link
Contributor

@agnivade agnivade commented May 1, 2020

@agnivade agnivade closed this May 1, 2020
@rhcarvalho
Copy link
Contributor Author

@rhcarvalho rhcarvalho commented May 1, 2020

@agnivade thanks for the update. By any chance, do you know what commit fixed it? Just curious to know what the problem was.

@agnivade
Copy link
Contributor

@agnivade agnivade commented May 3, 2020

@rhcarvalho
Copy link
Contributor Author

@rhcarvalho rhcarvalho commented May 14, 2020

FTR, this was reported at a later date and fixed in #38409. Happy to see it was backported to go1.14.3!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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