-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: testing: t.TempDir() should return actual path on macOS #56259
Comments
I dispute your use of the term “actual” in this proposal. In the presence of symlinks and hard-links, there may be more than one valid name for any given path — possibly even more than one valid name not involving symlinks! — and they are all in some sense “actual”. In my experience, the approach that is the least prone to bugs is to always preserve the version of the path explicitly given in environment variables (such as |
FWIW, prior to the introduction of We initially had it working the way that We then encountered a similar situation to that discussed in the opening comment here: we had a test whose expected result included a file path and it was difficult for the test code to actually calculate what path it was "expecting" because something downstream was calculating a derived path and resolving the symlinks while doing so. So we changed our helper to itself call However, we later had a test that wanted to make exactly the opposite assumption, and had no way to undo the Our ultimate conclusion was to make the helper behave equivalently to how Based on that experience, I would recommend against making the exact change proposed here. It may be possible to reduce the boilerplate required in tests that do want a fully-evaluated path -- e.g. with a function which calls I will say that it is unfortunate that this quirk only typically applies on macOS systems. More than once we've had developers write tests on other platforms (including me, on Linux) which fail when run on macOS because of not considering this quirk. But each time that's happened it's only been a brief annoyance, since the boilerplate to deal with it is typically the same in each case, and it trips me up maybe once per year at most. |
@apparentlymart Thanks for the note. It's very helpful. |
This proposal has been added to the active column of the proposals project |
Thanks for the comment @apparentlymart. It sounds like we should not make this change, because (1) programs that want to match $TMPDIR can do that today by just using the result, but they can't do it at all if we apply EvalSymlinks. |
Based on the discussion above, this proposal seems like a likely decline. |
Oh, I see I never replied to earlier comments; yes, @apparentlymart brought up some good points, and I agree that changing would fix some cases, but not others. The common thing is, just that symlinks are a pain, and unfortunately something we'll have to live with (and macOS implicitly using them for these just rubbing that in). I'll close this proposal, but really appreciate all participating on this discussion, and the maintainers for considering it. |
No change in consensus, so declined. |
On macOS, temp-directories are symlinked to
/private/var
, which may cause unexpected results when testing code that handles symlinks.Taking the following example:
Running the test shows that the "using original tmpDir" test fails;
While this may be "expected", and it's possible to work around this, it's cumbersome (and easy to overlook) to have to resolve the actual path for
t.TempDir()
for tests that may expect the path returned to be the actual path.Proposal
Make
t.TempDir()
resolve and return the actual path.The text was updated successfully, but these errors were encountered: