Dir.home test doesn't match actual Ruby or system behaviour
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
See the documentation on tilde expansion here:
"[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
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.