-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add TestFuzz go function to run fuzz tests. #421
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dzmitryhil, @miladz68, and @ysv)
build/golang/go.go
line 668 at r1 (raw file):
line := scanner.Text() if strings.HasPrefix(line, fuzzFuncPrefix) { lines := strings.Split(strings.TrimLeft(line, funcPrefix), "(")
Here, strings.TrimLeft
does not do what you want. It will trim each characters defined in funcPrefix
instead of trimming the whole thing, so of a function is defined as func fcfccnnabc()
it will extract abc
as test name.
You can test it yourself:
const (
funcPrefix = "func "
fuzzFuncPrefix = funcPrefix + "Fuzz"
)
func TestPrefix(t *testing.T) {
line := "func fcfccnnabc("
if strings.HasPrefix(line, fuzzFuncPrefix) {
lines := strings.Split(strings.TrimLeft(line, funcPrefix), "(")
if len(lines) != 2 {
t.Fatalf("invalid fuzz test %s", line)
}
t.Logf("test name: %s", lines[0])
}
t.Log(strings.TrimLeft("func fabc", "func "))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @masihyeganeh, @miladz68, and @ysv)
build/golang/go.go
line 668 at r1 (raw file):
Previously, masihyeganeh (Masih Yeganeh) wrote…
Here,
strings.TrimLeft
does not do what you want. It will trim each characters defined infuncPrefix
instead of trimming the whole thing, so of a function is defined asfunc fcfccnnabc()
it will extractabc
as test name.You can test it yourself:
const ( funcPrefix = "func " fuzzFuncPrefix = funcPrefix + "Fuzz" ) func TestPrefix(t *testing.T) { line := "func fcfccnnabc(" if strings.HasPrefix(line, fuzzFuncPrefix) { lines := strings.Split(strings.TrimLeft(line, funcPrefix), "(") if len(lines) != 2 { t.Fatalf("invalid fuzz test %s", line) } t.Logf("test name: %s", lines[0]) } t.Log(strings.TrimLeft("func fabc", "func ")) }
Right, updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @miladz68 and @ysv)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @ysv)
Description
Add TestFuzz go function to run fuzz tests.
Reviewers checklist:
Authors checklist
This change is