History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: JRUBY-673
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Thomas E Enebo
Reporter: Daniel Berger
Votes: 0
Watchers: 2
Operations

If you were logged in you would be able to see more operations.
JRuby

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

Created: 07/Mar/07 04:38 PM   Updated: 06/May/07 09:49 PM
Component/s: Core Classes/Modules
Affects Version/s: JRuby 0.9.8
Fix Version/s: JRuby 1.0.0RC1

Time Tracking:
Not Specified

File Attachments: 1. Text File rubydir.patch (0.8 kb)

Environment: Solaris 10, Java 1.5.0_06, JRuby trunk - 7-Mar-2007

Testcase included: yes


 Description  « Hide
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



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Eric Kramer - 04/Apr/07 06:40 PM
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")

Charles Oliver Nutter - 04/Apr/07 07:25 PM
The passwd-based version is only used for expanding ~username, as far as I can tell.

Koichiro Ohba - 01/May/07 03:19 AM
I think it's OK if you use ENV["HOME"] before System.getProperty("use.home").
I attached the patch. Thanks.

Thomas E Enebo - 01/May/07 06:51 PM
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.

Charles Oliver Nutter - 06/May/07 09:49 PM
Closing for 1.0RC1