From 7ec4a44762e63b75120ecc5154a00828c8f31b01 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 25 Jul 2013 04:06:50 +0000 Subject: file.c: split rb_home_dir * dir.c (dir_s_home): use rb_home_dir_of and rb_default_home_dir. * file.c (rb_home_dir_of): split from rb_home_dir() for the home directry of the given user, and the user name is a VALUE, not a bare pointer. should raise if the user does not exist. * file.c (rb_default_home_dir): split from rb_home_dir() for the home directry of the current user. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42160 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_dir.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb index d8e94727cd..91fbf35c45 100644 --- a/test/ruby/test_dir.rb +++ b/test/ruby/test_dir.rb @@ -217,4 +217,26 @@ class TestDir < Test::Unit::TestCase bug8597 = '[ruby-core:55764] [Bug #8597]' assert_empty(Dir.glob(File.join(@root, "<")), bug8597) end + + def test_home + env_home = ENV["HOME"] + env_logdir = ENV["LOGDIR"] + ENV.delete("HOME") + ENV.delete("LOGDIR") + + assert_raise(ArgumentError) { Dir.home } + assert_raise(ArgumentError) { Dir.home("") } + ENV["HOME"] = @nodir + assert_nothing_raised(ArgumentError) { + assert_equal(@nodir, Dir.home) + assert_equal(@nodir, Dir.home("")) + } + %W[no:such:user \u{7559 5b88}:\u{756a}].each do |user| + assert_raise_with_message(ArgumentError, /#{user}/) {Dir.home(user)} + end + ensure + ENV["HOME"] = env_home + ENV["LOGDIR"] = env_logdir + end + end -- cgit v1.2.3