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

Add TestFuzz go function to run fuzz tests. #421

Merged
merged 2 commits into from
Jul 17, 2024
Merged

Conversation

dzmitryhil
Copy link
Contributor

@dzmitryhil dzmitryhil commented Jul 9, 2024

Description

Add TestFuzz go function to run fuzz tests.

Reviewers checklist:

  • Try to write more meaningful comments with clear actions to be taken.
  • Nit-picking should be unblocking. Focus on core issues.

Authors checklist

  • Provide a concise and meaningful description
  • Review the code yourself first, before making the PR.
  • Annotate your PR in places that require explanation.
  • Think and try to split the PR to smaller PR if it is big.

This change is Reviewable

@dzmitryhil dzmitryhil requested a review from a team as a code owner July 9, 2024 11:08
@dzmitryhil dzmitryhil requested review from masihyeganeh, miladz68 and ysv and removed request for a team July 9, 2024 11:08
Copy link
Contributor

@masihyeganeh masihyeganeh left a 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 "))
}

Copy link
Contributor Author

@dzmitryhil dzmitryhil left a 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 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 "))
}

Right, updated.

Copy link
Contributor

@masihyeganeh masihyeganeh left a 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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @miladz68 and @ysv)

Copy link
Contributor

@miladz68 miladz68 left a 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: :shipit: complete! all files reviewed, all discussions resolved (waiting on @ysv)

@dzmitryhil dzmitryhil merged commit 18d74d2 into master Jul 17, 2024
3 checks passed
@dzmitryhil dzmitryhil deleted the dzmitryhil/fuzz branch July 17, 2024 11:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants