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

testing: prevent (*testing.F) methods from being called inside (*testing.F).Fuzz fn #48988

Closed
katiehockman opened this issue Oct 14, 2021 · 1 comment
Labels
fuzz Issues related to native fuzzing support NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@katiehockman
Copy link
Contributor

katiehockman commented Oct 14, 2021

From #48884

func FuzzFoo(f *testing.F) {
	f.Logf("parent f.Logf")
	f.Fuzz(func(t *testing.T, n uint8) {
		f.Logf("child f.Logf %d", n) // I'm allowed to use f.Logf here? f.Fatalf panics.
		t.Logf("child t.Logf %d", n)
		if n%3 == 0 {
			t.Fatal("boom")
		}
	})
}

@mvdan:

child f.Logf is allowed and ends up being printed along with parent f.Logf. It is not allowed to call f.Fatalf from inside the fuzz function taking a *testing.T, so I think we should similarly disallow calling any testing.TB methods on the parent *testing.F, such as Logf. I actually used f.Logf instead of t.Logf by mistake, and was very confused why my log lines ended up in the wrong position in the resulting failure output.

Let's disallow calls like f.Logf inside the f.Fuzz function, and encourage t.Logf and the like instead.

/cc @golang/fuzzing

@katiehockman katiehockman added NeedsFix The path to resolution is known, but the work has not been done. fuzz Issues related to native fuzzing support labels Oct 14, 2021
@katiehockman katiehockman added this to the Go1.18 milestone Oct 14, 2021
@katiehockman katiehockman self-assigned this Oct 14, 2021
@gopherbot
Copy link

gopherbot commented Oct 15, 2021

Change https://golang.org/cl/356151 mentions this issue: testing: don't allow f.Log/Logf inside f.Fuzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fuzz Issues related to native fuzzing support NeedsFix The path to resolution is known, but the work has not been done.
Projects
Status: No status
Development

No branches or pull requests

2 participants