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

cmd/go: test Example with wrong type results in unclear error message #35284

Open
gertcuykens opened this issue Oct 31, 2019 · 4 comments

Comments

@gertcuykens
Copy link
Contributor

@gertcuykens gertcuykens commented Oct 31, 2019

GO111MODULE="on"
create a new module

module github.com/t/crypto
go 1.14

Although I think modules have nothing to do with it

Create a test file that contains a Example, and deliberately give it the wrong function definition like so

func ExampleCipherBlock(b []byte) {
  fmt.Println("hello")
  // Output:
}
% go test -v
# github.com/t/crypto.test
/var/folders/dv/8tlwvjr91zjdyq4rk14lkkfm0000gn/T/go-build917091680/b001/_testmain.go:30:30: cannot use crypto.ExampleCipherBlock (type func([]byte)) as type func() in field value
FAIL    github.com/t/crypto [build failed]

Now do the same but make a other error like so

k
func ExampleCipherBlock() {
  fmt.Println("hello")
  // Output:
}
% go test -v
# github.com/t/crypto
block_test.go:10:1: expected declaration, found k
FAIL    github.com/t/crypto [setup failed]
gert@mac crypto % 

Second one is the kind of error messages I expect, the first one completely messes up vscode because there is no way vscode can figure out where to point to.

@jayconrod jayconrod changed the title cmd/go: ExampleTest(b []byte) results in completely different error message cmd/go: test Example with wrong type results in unclear error message Nov 1, 2019
@jayconrod jayconrod added this to the Backlog milestone Nov 1, 2019
@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Nov 1, 2019

In cmd/go/internal/load/test.go, we extract TestMain, Test, and Benchmark functions and check their signatures with checkTestFunc. We should do the same with examples but we extract those with go/doc.Examples and don't check the signatures.

The error should look like;

block_test.go:10:1: wrong signature for ExampleCipherBlock, must be: func ExampleCipherBlock()`
@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Nov 1, 2019

@mohamednizar

This comment has been minimized.

Copy link

@mohamednizar mohamednizar commented Nov 2, 2019

@jayconrod , I whish to contribute to this issue. How can start work on this ? I have started working on this.

@jayconrod

This comment has been minimized.

Copy link
Contributor

@jayconrod jayconrod commented Nov 5, 2019

Hey @mohamednizar, if you're interested in working on this, please follow the instructions in https://golang.org/doc/contribute.html for submitting a Gerrit CL or GitHub PR.

Any fix should include a small regression test in cmd/go/testdata/script. See the README there for information on writing tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.