Skip to content

🤫 Don't require t.Helper in functions passed to synctest.Test#51

Merged
kulti merged 2 commits intokulti:masterfrom
busser:arthur/synctest-test-exception
Sep 15, 2025
Merged

🤫 Don't require t.Helper in functions passed to synctest.Test#51
kulti merged 2 commits intokulti:masterfrom
busser:arthur/synctest-test-exception

Conversation

@busser
Copy link
Copy Markdown
Contributor

@busser busser commented Aug 27, 2025

Go 1.25 made the testing/synctest package generally available. The
package introduces the synctest.Test function, to be used like this:

func TestMyFeature(t *testing.T) {
	synctest.Test(t, func(t *testing.T) {
		// Do stuff that uses goroutines
	})
}

Sadly, thelper triggers if the anonymous function passed to
synctest.Test doesn't call t.Helper(). The issue is that this
anonymous function isn't a helper, it's more like a sub-test. This
has been reported in #48.

This PR extends thelper to grant an exception to functions passed to
synctest.Test, just like functions passed to t.Run or b.Run.

This requires updating to Go 1.25, so this PR is stacked on top of #50.

@busser busser changed the title arthur/synctest test exception 🤫 Don't require t.Helper in functions passed to synctest.Test Aug 27, 2025
@busser busser force-pushed the arthur/synctest-test-exception branch from 4307dcf to b7a5fed Compare September 2, 2025 13:37
Go 1.25 made the `testing/synctest` package generally available. The
package introduces the `synctest.Test` function, to be used like this:

```go
func TestMyFeature(t *testing.T) {
	synctest.Test(t, func(t *testing.T) {
		// Do stuff that uses goroutines
	})
}
```

Sadly, `thelper` triggers if the anonymous function passed to
`synctest.Test` doesn't call `t.Helper()`. The issue is that this
anonymous function isn't a helper, it's more like a sub-test.

This PR extends `thelper` to grant an exception to functions passed to
`synctest.Test`, just like functions passed to `t.Run` or `b.Run`.

This requires updating to Go 1.25, so this PR is stacked on top of kulti#50.
@busser busser force-pushed the arthur/synctest-test-exception branch from b7a5fed to 9368dfb Compare September 2, 2025 13:38
@busser
Copy link
Copy Markdown
Contributor Author

busser commented Sep 2, 2025

Hey @kulti, this one is ready for your review :)

Copy link
Copy Markdown
Owner

@kulti kulti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delayed reply. Great job! I suppose we can merge it. The following comments are not so important. I can improve it later.

Comment thread pkg/analyzer/analyzer.go Outdated
Comment thread pkg/analyzer/testdata/src/t/s.go Outdated
@busser
Copy link
Copy Markdown
Contributor Author

busser commented Sep 15, 2025

I've updated the code. No point in you fixing it later if I can fix it now ;)

@kulti kulti merged commit 27410a1 into kulti:master Sep 15, 2025
3 of 4 checks passed
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.

2 participants