Repository navigation
testing: surprising interaction of subtests with TempDir #46624
Description
Activity
Perhaps
t.TempDirshouldn't name its directory after the name of the test, or else perhaps it should use a limited set of allowed symbols rather than trying to remove a few disallowed ones (like/).I think it might still useful for the directory to somewhat resemble the name of the test. But I agree that trying to remove disallowed symbols is error-prone and might still break on certain platforms. Using a limited set of symbols (e.g. alphanumeric characters plus a few safe ones) sounds good to me.
Reacted by Bryan C. Mills- addedNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.
on Jun 7, 2021 Yes, let's just drop unusual characters, or replace them with
-or something.Change https://golang.org/cl/326010 mentions this issue:
testing: drop unusual characters from TempDir directory name- addedNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.
on Jun 16, 2021 - removedNeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.Feedback is required from experts, contributors, and/or the community before a change can be made.
on Jun 16, 2021 @gopherbot Please open backport to 1.16.
Backport issue(s) opened: #50645 (for 1.16).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.
(The fix is already in 1.17.)
Reacted by Dmitri ShuralyovChange https://golang.org/cl/378914 mentions this issue:
[release-branch.go1.16] testing: drop unusual characters from TempDir directory name- added a commit that references this issue
on Jan 26, 2022 - locked and limited conversation to collaborators
on Jan 16, 2023 - added a commit that references this issue
on Apr 29, 2024
What version of Go are you using (
go version)?I tested with Go 1.16.4 and tip (e1fa260).
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env)?linux/amd64
What did you do?
Here's a demo (playground):
What did you expect to see?
It'd be nice if this just worked.
What did you see instead?
When naming some subtest, you probably aren't considering that the name is going to become part of the path of any
t.TempDir(). This can have some surprising interactions, such as this case where the name includes[], making any glob pattern inside the tempdir invalid.I suspect there are other lurking surprises. For example, if you use a
*inside the test name, that is passed on toos.MkdirTempas-is where it has a special meaning (it indicates where the random number should be inserted). Not broken, but also not intended. Or your subtest name can include characters such as!"#$&'(),;<=>?[]^{|}and backtick which may require shell quoting.Perhaps
t.TempDirshouldn't name its directory after the name of the test, or else perhaps it should use a limited set of allowed symbols rather than trying to remove a few disallowed ones (like/).(This is a continuation of the issues uncovered in #38465 -- cc @bradfitz @tklauser)