JRuby

Dir.chdir with no arguments does not honor ENV['HOME']

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 0.9.8
  • Fix Version/s: JRuby 1.0.0RC1
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Environment:
    Solaris 10, Java 1.5.0_06, JRuby trunk - 7-Mar-2007
  • Testcase included:
    yes
  • Number of attachments :
    1

Description

Dir.chdir with no arguments is supposed to default to $HOME but JRuby is not doing that:

require "test/unit"

class TC_Dir_Chdir_Class < Test::Unit::TestCase
def setup
@pwd = Dir.pwd
@old_home = ENV["HOME"] || ENV["LOGDIR"]
ENV["HOME"] = @pwd
end

def test_chdir_basic
assert_respond_to(Dir, :chdir)
assert_nothing_raised{ Dir.chdir }
assert_nothing_raised{ Dir.chdir(@pwd) }
assert_nothing_raised{ Dir.chdir(@pwd){} }
end

def test_chdir
assert_equal(0, Dir.chdir(@pwd))
assert_nothing_raised{ Dir.chdir }
assert_equal(@pwd, Dir.pwd)
end

def test_chdir_block
assert_nothing_raised{ Dir.chdir{ @old_home } }
assert_equal(@pwd, Dir.pwd)
end

def test_chdir_expected_errors
assert_raises(ArgumentError){ Dir.chdir(@pwd, @pwd) }
assert_raises(TypeError){ Dir.chdir(1) }

ENV["HOME"] = "bogus"
assert_raises(Errno::ENOENT){ Dir.chdir }
end

def teardown
system("chdir #{@pwd}")
ENV["HOME"] = @old_home
@pwd = nil
end
end

You'll see something like this:

1) Failure:
test_chdir(TC_Dir_Chdir_Class) [test/core/Dir/class/tc_chdir.rb:25]:
<"/export/home/djberge/workspace/ruby_test"> expected but was
<"/export/home/djberge">.

2) Failure:
test_chdir_expected_errors(TC_Dir_Chdir_Class) [test/core/Dir/class/tc_chdir.rb:38]:
<Errno::ENOENT> exception expected but none was thrown.

Regards,

Dan

Activity

Hide
Eric Kramer added a comment -

Shouldn't the code in RubyDir#getHomeDirectoryPath use the following code (instead of platform-specific parsing of the /etc/passwd file?)
System.getProperty("user.home")

Show
Eric Kramer added a comment - Shouldn't the code in RubyDir#getHomeDirectoryPath use the following code (instead of platform-specific parsing of the /etc/passwd file?) System.getProperty("user.home")
Hide
Charles Oliver Nutter added a comment -

The passwd-based version is only used for expanding ~username, as far as I can tell.

Show
Charles Oliver Nutter added a comment - The passwd-based version is only used for expanding ~username, as far as I can tell.
Hide
Koichiro Ohba added a comment -

I think it's OK if you use ENV["HOME"] before System.getProperty("use.home").
I attached the patch. Thanks.

Show
Koichiro Ohba added a comment - I think it's OK if you use ENV["HOME"] before System.getProperty("use.home"). I attached the patch. Thanks.
Hide
Thomas E Enebo added a comment -

Applied patch by Koichiro Ohba (Thanks for the fix!). Fixed in commit 3604. I tweaked this patch a little since it was reading from ENV_JAVA when it needs to read from both ENV_JAVA (system properties) and ENV (environment variables). This also corrected a previous problem where LOGDIR env was not getting read.

Show
Thomas E Enebo added a comment - Applied patch by Koichiro Ohba (Thanks for the fix!). Fixed in commit 3604. I tweaked this patch a little since it was reading from ENV_JAVA when it needs to read from both ENV_JAVA (system properties) and ENV (environment variables). This also corrected a previous problem where LOGDIR env was not getting read.
Hide
Charles Oliver Nutter added a comment -

Closing for 1.0RC1

Show
Charles Oliver Nutter added a comment - Closing for 1.0RC1

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: