Bug #15324
closedDir.home test doesn't match actual Ruby or system behaviour
Description
This test currently asserts that Dir.home(user)
should return ENV['HOME'] if user is the current user.
We don't think this is correct - Dir.home(user)
uses the expanded value of ~user
, which explictly uses the login database, and explicitly not any current value of HOME
.
See the documentation on tilde expansion here:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_01
"[if there is an explict user name after the tilde then] the tilde-prefix shall be replaced by a pathname of the initial working directory associated with the login name obtained using the getpwnam() function as defined in the System Interfaces volume of POSIX.1-2017 [as opposed to reading HOME]"
getpwnam
is what File.expand_path
does.
To see the problem, run MRI's test with HOME
set to something else (again, see the link above to see that setting HOME
is explicitly allowed).
$ HOME=/nothing make test-all
...
1) Failure:
TestDir#test_home [/Users/chrisseaton/Documents/mri-test-upstream/ruby/test/ruby/test_dir.rb:378]:
<"/nothing"> expected but was
<"/Users/chrisseaton">.
...
We've encountered this test failure for real, so it isn't hypothetical.
The patch corrects the test to match actual Ruby behaviour.
Files