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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

The testable example "ExampleObjectPool" is not testing output #3763

Open
ameowlia opened this issue Sep 21, 2021 · 1 comment 路 May be fixed by #3928
Open

The testable example "ExampleObjectPool" is not testing output #3763

ameowlia opened this issue Sep 21, 2021 · 1 comment 路 May be fixed by #3928
Assignees

Comments

@ameowlia
Copy link

馃憢 Hello,

I am investigating the golang issue: golang/go#48362, where testable examples are causing false positives when the output comment block is not the last comment block example.

I ran a parser against the top golang repos, including this repo, and I found this bug with your ExampleObjectPool testable example.

The output comment block should be moved to the end like so:

func ExampleObjectPool() {
	opts := pool.NewObjectPoolOptions()
	p := pool.NewObjectPool(opts)
	p.Init(func() interface{} {
		// The Pool's Allocator should generally only return pointer
		// types, since a pointer can be put into the return interface
		// value without an allocation.
		return new(exampleObject)
	})

	// Get an exampleObject from the pool.
	o := p.Get().(*exampleObject)

	fmt.Printf("Retrieved struct should have default values: %+v", o)

	// Use the exampleObject.
	_ = o

	// Reset the exampleObject and return it to the pool.
	o.reset()
	p.Put(o)

	// Output: Retrieved struct should have default values: &{a:0 b:0 c:0}
}

I am happy to PR this in, but it will take a few days for me to get approval from my employer before I can submit it.

@gibbscullen
Copy link
Collaborator

@ameowlia sounds good! Let us know when you have something for us to review.

@ameowlia ameowlia linked a pull request Nov 18, 2021 that will close this issue
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 a pull request may close this issue.

2 participants