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 -fuzz gives a confusing error when types mismatch #48635

Open
mvdan opened this issue Sep 26, 2021 · 2 comments
Open

cmd/go: test -fuzz gives a confusing error when types mismatch #48635

mvdan opened this issue Sep 26, 2021 · 2 comments

Comments

@mvdan
Copy link
Member

@mvdan mvdan commented Sep 26, 2021

I wrote a fuzz func like:

f.Fuzz(func(t *testing.T, src string, parserOpts uint8, printerOpts uint16) {

Then I used f.Add as follows:

f.Add("{ (foo; bar); baz; }", 0, 0)

I got a fairly confusing error:

fuzz_test.go:66: mismatched types in corpus entry: [echo foo 0 0], want [string uint8 uint16]

Intuitively, I thought my code was right, because the untyped constant 0 can be assigned to uint8 and uint16 just fine. It took me a minute to realise that, when passing 0 as an argument, it assumes the int type.

I think the following error message would be much easier to understand:

fuzz_test.go:66: mismatched types in corpus entry: [string int int], want [string uint8 uint16]

or, if you want to include the values:

fuzz_test.go:66: mismatched types in corpus entry: [string("echo foo") int(0) int(0)], want [string uint8 uint16]
@mvdan
Copy link
Member Author

@mvdan mvdan commented Sep 26, 2021

Another reason the current error is confusing is that [echo foo 0 0] looks like four arguments, when it's actually three - due to the lack of quoting.

@mvdan mvdan added the fuzz label Sep 28, 2021
@mvdan
Copy link
Member Author

@mvdan mvdan commented Sep 28, 2021

(forgot to cc @katiehockman @jayconrod on this one, doing so quietly during the quiet week...)

@mknyszek mknyszek added this to the Go1.18 milestone Oct 4, 2021
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