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
Labels
Documentation help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@dsymonds
Copy link
Contributor

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
Contributor Author

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 the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 8, 2020
@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

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
Labels
Documentation help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants