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

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 commented May 1, 2020

This is fixed now on tip: https://tip.golang.org/pkg/errors/#example_As

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

@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 commented May 3, 2020

c4961dc#diff-23c81667acc0871b0276b715d353197f

@rhcarvalho
Copy link
Contributor Author

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

@golang golang locked and limited conversation to collaborators May 14, 2021
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

3 participants