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

testing: document rules for using TB #41269

Open
dsymonds opened this issue Sep 8, 2020 · 2 comments
Open

testing: document rules for using TB #41269

dsymonds opened this issue Sep 8, 2020 · 2 comments

Comments

@dsymonds
Copy link
Member

@dsymonds dsymonds commented Sep 8, 2020

There's rules about what a TestFoo may do with the *testing.T it is given. Some are documented (e.g. https://golang.org/pkg/testing/#T puts restrictions on invoking Fatalf and friends), but some are not (e.g. Logf and probably most other methods should not be called after TestFoo returns). Same applies to *testing.B and any future such values/types.

I came across this while trying to diagnose a problem that seems to be due to #40908, but realised I couldn't find the rules written down anywhere.

@dsymonds
Copy link
Member Author

@dsymonds dsymonds commented Sep 8, 2020

Related to #40343, though that one claims that the docs allude to it; however, I can't find the quoted snippet.

@andybons andybons added this to the Unplanned milestone Sep 8, 2020
@ianlancetaylor ianlancetaylor modified the milestones: Unplanned, Backlog Sep 8, 2020
@rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented Sep 10, 2020

Personally, I think most of those rules should be relaxed. We could document that Fatalf just calls runtime.Goexit (and document that it won't actually abort the entire test). We could allow Logf to run after the test has ended (and document that the logged value won't appear if it has).

Having extra rules on the testing infrastructure makes it harder to diagnose the real problems, in my view, and sometimes non-conformance is accidental (for example if a goroutine that's calling Logf happens not to have been shut down properly before the test has completed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.