Skip to content

Commit

Permalink
Resolve the current user home even when $HOME is not set
Browse files Browse the repository at this point in the history
* Fixes oracle/truffleruby#2784
* Use getpwuid_r(getuid()) for simplicity and reliability.
  • Loading branch information
eregon authored and seven1m committed Sep 2, 2023
1 parent 21f8bba commit a79ecf2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/dir/home_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
Dir.home.should_not.frozen?
end

it "returns a string with the filesystem encoding" do
Dir.home.encoding.should == Encoding.find("filesystem")
end

platform_is_not :windows do
it "works even if HOME is unset" do
ENV.delete('HOME')
Dir.home.should.start_with?('/')
Dir.home.encoding.should == Encoding.find("filesystem")
end
end

platform_is :windows do
ruby_version_is "3.0" do
it "returns the home directory with forward slashs and as UTF-8" do
Expand Down Expand Up @@ -65,6 +77,10 @@
it "returns a non-frozen string" do
Dir.home(ENV['USER']).should_not.frozen?
end

it "returns a string with the filesystem encoding" do
Dir.home(ENV['USER']).encoding.should == Encoding.find("filesystem")
end
end

it "raises an ArgumentError if the named user doesn't exist" do
Expand Down

0 comments on commit a79ecf2

Please sign in to comment.