Skip to content

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

@gertcuykens

Description

@gertcuykens

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions