summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-26 03:01:41 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-10-26 03:01:41 +0000
commit0e6dcc7ab24e6e5b8ee3b9a532c0318eb5155e2e (patch)
tree10e9d00b89f6bb5b0d275ee4dbd6e35fe886b2ef /test
parentc5b7d11e59cf8953d18ed6aba2c4df2b1eb29fd4 (diff)
merge revision(s) 32826,34732: [Backport #6681]
* file.c (rb_enc_path_next, rb_enc_path_skip_prefix) (rb_enc_path_last_separator, rb_enc_path_end) (ruby_enc_find_basename, ruby_enc_find_extname): encoding-aware path handling functions. * file.c (rb_home_dir, file_expand_path, rb_realpath_internal) (rb_file_s_basename, rb_file_dirname, rb_file_s_extname) (rb_file_join): should respect the encodings of arguments than file system encoding. [ruby-dev:45145] [Bug #5919] * dir.c (check_dirname, ruby_glob0): ditto. * ext/pathname/pathname.c (path_sub_ext): ditto. * util.c, include/ruby/util.h (ruby_add_suffix): remove the function. [Bug #5153] [ruby-core:38736] * io.c (argf_next_argv): remove the call of above function. * ext/-test-/add_suffix, test/-ext-/test_add_suffix.rb: remove the test extension module because this is only for testsing ruby_add_suffix(). * LEGAL: remove the mention about a part of util.c, because now we removed the part. * io.c (argf_next_argv): now the new filename is not guranteed to use, so should check the return value of rename(2). * test/ruby/test_argf.rb (TestArgf#test_inplace_rename_impossible): now we expect same result with other platforms on no_safe_rename platforms (=Windows). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@37330 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/-ext-/test_add_suffix.rb47
-rw-r--r--test/pathname/test_pathname.rb8
-rw-r--r--test/ruby/test_argf.rb15
-rw-r--r--test/ruby/test_file_exhaustive.rb27
4 files changed, 30 insertions, 67 deletions
diff --git a/test/-ext-/test_add_suffix.rb b/test/-ext-/test_add_suffix.rb
deleted file mode 100644
index 0520baef8c..0000000000
--- a/test/-ext-/test_add_suffix.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-require 'test/unit'
-require_relative '../ruby/envutil'
-require "-test-/add_suffix/bug"
-
-class Test_AddSuffix < Test::Unit::TestCase
- Dir = "/dev/null/".freeze
- Style_1 = (Dir+"foo").freeze
-
- def test_style_0
- assert_equal("a.x.y", Bug.add_suffix("a.x", ".y"))
- end
-
- def test_style_1
- assert_equal(Style_1+".y", Bug.add_suffix(Style_1+".c", ".y"))
- suffix = ".bak".freeze
- assert_equal(Style_1+suffix, Bug.add_suffix(Style_1.dup, suffix))
- assert_equal(Style_1+suffix, Bug.add_suffix(Style_1+".bar", suffix))
- assert_equal(Style_1+".$$$", Bug.add_suffix(Style_1+suffix, suffix))
- assert_equal(Style_1+suffix, Bug.add_suffix(Style_1+".$$$", suffix))
- assert_equal(Style_1+".~~~", Bug.add_suffix(Style_1+".$$$", ".$$$"))
- assert_equal(Dir+"makefile"+suffix, Bug.add_suffix(Dir+"makefile", suffix))
- end
-
- def test_style_2
- suffix = "~"
- assert_equal(Style_1+"~", Bug.add_suffix(Style_1.dup, suffix))
- assert_equal(Style_1+".c~", Bug.add_suffix(Style_1+".c", suffix))
- assert_equal(Style_1+".c~~", Bug.add_suffix(Style_1+".c~", suffix))
- assert_equal(Style_1+"~.c~~", Bug.add_suffix(Style_1+".c~~", suffix))
- assert_equal(Style_1+"~~.c~~", Bug.add_suffix(Style_1+"~.c~~", suffix))
- assert_equal(Style_1+"~~~~~.cc~", Bug.add_suffix(Style_1+"~~~~~.ccc", suffix))
- assert_equal(Style_1+"~~~~~.$$$", Bug.add_suffix(Style_1+"~~~~~.c~~", suffix))
- assert_equal(Dir+"foo~.pas", Bug.add_suffix(Dir+"foo.pas", suffix))
- assert_equal(Dir+"makefile.~", Bug.add_suffix(Dir+"makefile", suffix))
- assert_equal(Dir+"longname.fi~", Bug.add_suffix(Dir+"longname.fil", suffix))
- assert_equal(Dir+"longnam~.fi~", Bug.add_suffix(Dir+"longname.fi~", suffix))
- assert_equal(Dir+"longnam~.$$$", Bug.add_suffix(Dir+"longnam~.fi~", suffix))
- end
-
- def test_style_3
- base = "a"*1000
- suffix = "-"+"b"*1000
- assert_equal(base+".~~~", Bug.add_suffix(base, suffix))
- assert_equal(base+".~~~", Bug.add_suffix(base+".$$$", suffix))
- assert_equal(base+".$$$", Bug.add_suffix(base+".~~~", suffix))
- end
-end
diff --git a/test/pathname/test_pathname.rb b/test/pathname/test_pathname.rb
index 8a8c0d9844..61d288d68d 100644
--- a/test/pathname/test_pathname.rb
+++ b/test/pathname/test_pathname.rb
@@ -1,5 +1,3 @@
-#!/usr/bin/env ruby
-
require 'test/unit'
require 'pathname'
@@ -185,10 +183,8 @@ class TestPathname < Test::Unit::TestCase
if DOSISH
defassert(:del_trailing_separator, "a", "a\\")
- require 'Win32API'
- if Win32API.new('kernel32', 'GetACP', nil, 'L').call == 932
- defassert(:del_trailing_separator, "\225\\", "\225\\\\") # SJIS
- end
+ defassert(:del_trailing_separator, "\225\\".force_encoding("cp932"), "\225\\\\".force_encoding("cp932"))
+ defassert(:del_trailing_separator, "\225".force_encoding("cp437"), "\225\\\\".force_encoding("cp437"))
end
def test_plus
diff --git a/test/ruby/test_argf.rb b/test/ruby/test_argf.rb
index bf6996f0de..2f1ddf5391 100644
--- a/test/ruby/test_argf.rb
+++ b/test/ruby/test_argf.rb
@@ -201,21 +201,14 @@ class TestArgf < Test::Unit::TestCase
t = make_tempfile
assert_in_out_err(["-", t.path], <<-INPUT) do |r, e|
- ARGF.inplace_mode = '/\\\\'
+ ARGF.inplace_mode = '/\\\\:'
while line = ARGF.gets
puts line.chomp + '.new'
end
INPUT
- if no_safe_rename
- assert_equal([], e)
- assert_equal([], r)
- assert_equal("foo.new\nbar.new\nbaz.new\n", File.read(t.path))
- File.unlink(t.path + ".~~~") rescue nil
- else
- assert_match(/Can't rename .* to .*: .*. skipping file/, e.first) #'
- assert_equal([], r)
- assert_equal("foo\nbar\nbaz\n", File.read(t.path))
- end
+ assert_match(/Can't rename .* to .*: .*. skipping file/, e.first) #'
+ assert_equal([], r)
+ assert_equal("foo\nbar\nbaz\n", File.read(t.path))
end
end
diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb
index 02a4730ba2..44b454a773 100644
--- a/test/ruby/test_file_exhaustive.rb
+++ b/test/ruby/test_file_exhaustive.rb
@@ -403,10 +403,10 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_match(/\Ac:\//i, File.expand_path('c:foo', 'd:/bar'))
assert_match(%r'\Ac:/bar/foo\z'i, File.expand_path('c:foo', 'c:/bar'))
end
- if drive = Dir.pwd[%r'\A(?:[a-z]:|//[^/]+/[^/]+)'i]
+ if DRIVE
assert_match(%r"\Az:/foo\z"i, File.expand_path('/foo', "z:/bar"))
assert_match(%r"\A//host/share/foo\z"i, File.expand_path('/foo', "//host/share/bar"))
- assert_match(%r"\A#{drive}/foo\z"i, File.expand_path('/foo'))
+ assert_match(%r"\A#{DRIVE}/foo\z"i, File.expand_path('/foo'))
else
assert_equal("/foo", File.expand_path('/foo'))
end
@@ -477,7 +477,6 @@ class TestFileExhaustive < Test::Unit::TestCase
ENV["HOMEPATH"] = home_path
ENV["USERPROFILE"] = user_profile
end
- assert_incompatible_encoding {|d| File.expand_path(d)}
end
def test_expand_path_remove_trailing_alternative_data
@@ -683,16 +682,31 @@ class TestFileExhaustive < Test::Unit::TestCase
assert_equal(basename, File.basename(@file + ".", ".*"))
assert_equal(basename, File.basename(@file + "::$DATA", ".*"))
end
+ if File::ALT_SEPARATOR == '\\'
+ a = "foo/\225\\\\"
+ [%W"cp437 \225", %W"cp932 \225\\"].each do |cp, expected|
+ assert_equal(expected.force_encoding(cp), File.basename(a.dup.force_encoding(cp)), cp)
+ end
+ end
assert_incompatible_encoding {|d| File.basename(d)}
assert_incompatible_encoding {|d| File.basename(d, ".*")}
assert_raise(Encoding::CompatibilityError) {File.basename("foo.ext", ".*".encode("utf-16le"))}
+
+ s = "foo\x93_a".force_encoding("cp932")
+ assert_equal(s, File.basename(s, "_a"))
end
def test_dirname
assert(@file.start_with?(File.dirname(@file)))
assert_equal(".", File.dirname(""))
assert_incompatible_encoding {|d| File.dirname(d)}
+ if File::ALT_SEPARATOR == '\\'
+ a = "\225\\\\foo"
+ [%W"cp437 \225", %W"cp932 \225\\"].each do |cp, expected|
+ assert_equal(expected.force_encoding(cp), File.dirname(a.dup.force_encoding(cp)), cp)
+ end
+ end
end
def test_extname
@@ -736,6 +750,13 @@ class TestFileExhaustive < Test::Unit::TestCase
def o.to_path; "foo"; end
assert_equal(s, File.join(o, "bar", "baz"))
assert_equal(s, File.join("foo" + File::SEPARATOR, "bar", File::SEPARATOR + "baz"))
+ if File::ALT_SEPARATOR == '\\'
+ a = "\225\\"
+ b = "foo"
+ [%W"cp437 \225\\foo", %W"cp932 \225\\/foo"].each do |cp, expected|
+ assert_equal(expected.force_encoding(cp), File.join(a.dup.force_encoding(cp), b.dup.force_encoding(cp)), cp)
+ end
+ end
end
def test_truncate