diff options
author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-28 09:35:21 +0000 |
---|---|---|
committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-28 09:35:21 +0000 |
commit | 809615987141a9faab189b3b9b74b0f9bd8a2508 (patch) | |
tree | a447d39285f92e78cec74c8f201190873c79e8b1 /test | |
parent | ea764677c84d7407f213293ca07f0b926b9548d3 (diff) |
merge revision(s) 39697,39701,39716,39740,39751: [Backport #8070]
* win32/file.c (rb_file_expand_path_internal): Expand home directory when
used as second parameter (dir_string). [ruby-core:53168] [Bug #8034]
* test/ruby/test_file_exhaustive.rb: add test to verify.
* win32/file.c (get_user_from_path): add internal function that retrieves
username from supplied path (refactored).
* win32/file.c (rb_file_expand_path_internal): refactor expansion of user
home to use get_user_from_path and cover dir_string corner cases.
[ruby-core:53168] [Bug #8034]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@39982 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_file_exhaustive.rb | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index d80c430bce..df7140f24a 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -413,10 +413,12 @@ class TestFileExhaustive < Test::Unit::TestCase end end + UnknownUserHome = "~foo_bar_baz_unknown_user_wahaha".freeze + def test_expand_path_home assert_kind_of(String, File.expand_path("~")) if ENV["HOME"] - assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha") } - assert_raise(ArgumentError) { File.expand_path("~foo_bar_baz_unknown_user_wahaha", "/") } + assert_raise(ArgumentError) { File.expand_path(UnknownUserHome) } + assert_raise(ArgumentError) { File.expand_path(UnknownUserHome, "/") } begin bug3630 = '[ruby-core:31537]' home = ENV["HOME"] @@ -440,6 +442,21 @@ class TestFileExhaustive < Test::Unit::TestCase end end + def test_expand_path_home_dir_string + home = ENV["HOME"] + new_home = "#{DRIVE}/UserHome" + ENV["HOME"] = new_home + bug8034 = "[ruby-core:53168]" + + assert_equal File.join(new_home, "foo"), File.expand_path("foo", "~"), bug8034 + assert_equal File.join(new_home, "bar", "foo"), File.expand_path("foo", "~/bar"), bug8034 + + assert_raise(ArgumentError) { File.expand_path(".", UnknownUserHome) } + assert_nothing_raised(ArgumentError) { File.expand_path("#{DRIVE}/", UnknownUserHome) } + ensure + ENV["HOME"] = home + end + def test_expand_path_remove_trailing_alternative_data assert_equal File.join(@rootdir, "aaa"), File.expand_path("#{@rootdir}/aaa::$DATA") assert_equal File.join(@rootdir, "aa:a"), File.expand_path("#{@rootdir}/aa:a:$DATA") |