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

refact(tests): improves handling of cleanup func #21

Merged
merged 1 commit into from
Jun 25, 2024
Merged

Conversation

supitsdu
Copy link
Owner

Handles cleanup using t.Cleanup() instead of manually calling defer after using replaceStdin.

Related review: #19 discussion

Handles cleanup using t.Cleanup() instead of manually calling defer
after using replaceStdin.
@supitsdu supitsdu added testing Issues or PRs specifically related to Go testing frameworks or practices. refactoring Issues or PRs to improving code structure, without changing its external behavior labels Jun 25, 2024
@ccoVeille
Copy link
Contributor

That's the main reason why t.Cleanup was added: avoid the callbaxk that you need to return and defer everywhere you call the method

That's why t.Cleanup supersedes defer in tests.

So when I see a defer in tests I ask to use t.Cleanup

Also, the defer and t.Cleanup registration order differs. It helps in a few cases

Here are a few articles

https://brandur.org/fragments/go-prefer-t-cleanup-with-parallel-subtests#:~:text=The%20fix%20is%20t.,with%20pauses%20caused%20by%20t.
https://stackoverflow.com/questions/61609085/what-is-useful-for-t-cleanup

@supitsdu supitsdu merged commit 0951d39 into main Jun 25, 2024
1 check passed
@supitsdu supitsdu deleted the refact/tests branch June 25, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Issues or PRs to improving code structure, without changing its external behavior testing Issues or PRs specifically related to Go testing frameworks or practices.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants