1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test_dir_m17n.rb: assert_separately

* test/ruby/test_dir_m17n.rb: prefer assert_separately over
  assert_ruby_status for more descriptive messages.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40867 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-05-20 18:10:34 +00:00
parent 80db7cc4fe
commit a7092270da

View file

@ -13,28 +13,32 @@ class TestDir_M17N < Test::Unit::TestCase
def create_and_check_raw_file_name(code, encoding) def create_and_check_raw_file_name(code, encoding)
with_tmpdir { |dir| with_tmpdir { |dir|
create_file_program = %Q[ assert_separately(["-E#{encoding}"], <<-EOS, :chdir=>dir)
filename = #{code}.chr('UTF-8').force_encoding("#{encoding}") filename = #{code}.chr('UTF-8').force_encoding("#{encoding}")
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) assert_include(ents, filename)
] EOS
assert_ruby_status(["-E#{encoding}"], create_file_program, nil, :chdir=>dir)
test_file_program = %Q[ assert_separately(%w[-EASCII-8BIT], <<-EOS, :chdir=>dir)
filename = #{code}.chr('UTF-8').force_encoding("ASCII-8BIT") filename = #{code}.chr('UTF-8').force_encoding("ASCII-8BIT")
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
expected_filename = #{code}.chr('UTF-8').encode(Encoding.find("filesystem")) rescue expected_filename = "?" expected_filename = #{code}.chr('UTF-8').encode(Encoding.find("filesystem")) rescue expected_filename = "?"
expected_filename = expected_filename.force_encoding("ASCII-8BIT") expected_filename = expected_filename.force_encoding("ASCII-8BIT")
result = ents.include?(filename) || (/mswin|mingw/ =~ RUBY_PLATFORM && ents.include?(expected_filename)) if /mswin|mingw/ =~ RUBY_PLATFORM
if !result && /mswin|mingw/ =~ RUBY_PLATFORM case
exit Dir.entries(".", {:encoding => Encoding.find("filesystem")}).include?(expected_filename) when ents.include?(filename)
when ents.include?(expected_filename)
filename = expected_filename
else
ents = Dir.entries(".", {:encoding => Encoding.find("filesystem")})
filename = expected_filename
end
end end
exit result assert_include(ents, filename)
] EOS
assert_ruby_status(%w[-EASCII-8BIT], test_file_program, nil, :chdir=>dir)
} }
end end
@ -42,69 +46,67 @@ class TestDir_M17N < Test::Unit::TestCase
def test_filename_extutf8 def test_filename_extutf8
with_tmpdir {|d| with_tmpdir {|d|
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
filename = "\u3042" filename = "\u3042"
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) assert_include(ents, filename)
EOS EOS
} }
end end
def test_filename_extutf8_invalid def test_filename_extutf8_invalid
with_tmpdir {|d| with_tmpdir {|d|
assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d)
filename = "\xff".force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8 filename = "\xff".force_encoding("ASCII-8BIT") # invalid byte sequence as UTF-8
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%FF")) filename = "%FF" if /darwin/ =~ RUBY_PLATFORM && ents.include?("%FF")
assert_include(ents, filename)
EOS EOS
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8 filename = "\xff".force_encoding("UTF-8") # invalid byte sequence as UTF-8
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%FF")) filename = "%FF" if /darwin/ =~ RUBY_PLATFORM && ents.include?("%FF")
assert_include(ents, filename)
EOS EOS
} }
end unless /mswin|mingw/ =~ RUBY_PLATFORM end unless /mswin|mingw/ =~ RUBY_PLATFORM
def test_filename_as_bytes_extutf8 def test_filename_as_bytes_extutf8
with_tmpdir {|d| with_tmpdir {|d|
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
filename = "\xc2\xa1".force_encoding("utf-8") filename = "\xc2\xa1".force_encoding("utf-8")
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) assert_include(ents, filename)
EOS EOS
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
if /mswin|mingw/ =~ RUBY_PLATFORM if /mswin|mingw/ =~ RUBY_PLATFORM
filename = "\x8f\xa2\xc2".force_encoding("euc-jp") filename = "\x8f\xa2\xc2".force_encoding("euc-jp")
else else
filename = "\xc2\xa1".force_encoding("euc-jp") filename = "\xc2\xa1".force_encoding("euc-jp")
end end
begin assert_nothing_raised(Errno::ENOENT) do
open(filename) {} open(filename) {}
exit true
rescue Errno::ENOENT
exit false
end end
EOS EOS
# no meaning test on windows # no meaning test on windows
unless /mswin|mingw/ =~ RUBY_PLATFORM unless /mswin|mingw/ =~ RUBY_PLATFORM
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) assert_separately(%W[-EUTF-8], <<-'EOS', :chdir=>d)
filename1 = "\xc2\xa1".force_encoding("utf-8") filename1 = "\xc2\xa1".force_encoding("utf-8")
filename2 = "\xc2\xa1".force_encoding("euc-jp") filename2 = "\xc2\xa1".force_encoding("euc-jp")
filename3 = filename1.encode("euc-jp") filename3 = filename1.encode("euc-jp")
filename4 = filename2.encode("utf-8") filename4 = filename2.encode("utf-8")
s1 = File.stat(filename1) rescue nil assert_file.stat(filename1)
s2 = File.stat(filename2) rescue nil assert_file.stat(filename2)
s3 = File.stat(filename3) rescue nil assert_file.not_exist?(filename3)
s4 = File.stat(filename4) rescue nil assert_file.not_exist?(filename4)
exit((s1 && s2 && !s3 && !s4) ? true : false)
EOS EOS
end end
} }
@ -114,26 +116,23 @@ class TestDir_M17N < Test::Unit::TestCase
def test_filename_extutf8_inteucjp_representable def test_filename_extutf8_inteucjp_representable
with_tmpdir {|d| with_tmpdir {|d|
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
filename = "\u3042" filename = "\u3042"
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) assert_include(ents, filename)
EOS EOS
assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp") filename = "\xA4\xA2".force_encoding("euc-jp")
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) assert_include(ents, filename)
EOS EOS
assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp") filename = "\xA4\xA2".force_encoding("euc-jp")
begin assert_nothing_raised(Errno::ENOENT) do
open(filename) {} open(filename) {}
exit true
rescue Errno::ENOENT
exit false
end end
EOS EOS
} }
@ -141,30 +140,31 @@ class TestDir_M17N < Test::Unit::TestCase
def test_filename_extutf8_inteucjp_unrepresentable def test_filename_extutf8_inteucjp_unrepresentable
with_tmpdir {|d| with_tmpdir {|d|
assert_ruby_status(%w[-EUTF-8], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8], <<-'EOS', :chdir=>d)
filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP
filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP
File.open(filename1, "w") {} File.open(filename1, "w") {}
File.open(filename2, "w") {} File.open(filename2, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename1) && ents.include?(filename2) assert_include(ents, filename1)
assert_include(ents, filename2)
EOS EOS
assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP
filename2 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP filename2 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename1) && ents.include?(filename2) assert_include(ents, filename1)
assert_include(ents, filename2)
EOS EOS
assert_ruby_status(%w[-EUTF-8:EUC-JP], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EUTF-8:EUC-JP], <<-'EOS', :chdir=>d)
filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP filename1 = "\u2661" # WHITE HEART SUIT which is not representable in EUC-JP
filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP filename2 = "\u3042" # HIRAGANA LETTER A which is representable in EUC-JP
filename3 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP filename3 = "\xA4\xA2".force_encoding("euc-jp") # HIRAGANA LETTER A in EUC-JP
s1 = File.stat(filename1) rescue nil assert_file.stat(filename1)
s2 = File.stat(filename2) rescue nil assert_file.stat(filename2)
s3 = File.stat(filename3) rescue nil assert_file.stat(filename3)
exit((s1 && s2 && s3) ? true : false)
EOS EOS
} }
end end
@ -173,39 +173,51 @@ class TestDir_M17N < Test::Unit::TestCase
def test_filename_bytes_euc_jp def test_filename_bytes_euc_jp
with_tmpdir {|d| with_tmpdir {|d|
assert_ruby_status(%w[-EEUC-JP], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp") filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
ents.each {|e| e.force_encoding("ASCII-8BIT") } ents.each {|e| e.force_encoding("ASCII-8BIT") }
exit ents.include?(filename.force_encoding("ASCII-8BIT")) || if /darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("ASCII-8BIT"))
(/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("ASCII-8BIT"))) filename = "%A4%A2"
end
assert_include(ents, filename.force_encoding("ASCII-8BIT"))
EOS EOS
} }
end end
def test_filename_euc_jp def test_filename_euc_jp
with_tmpdir {|d| with_tmpdir {|d|
assert_ruby_status(%w[-EEUC-JP], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp") filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("euc-jp"))) if /darwin/ =~ RUBY_PLATFORM && ents.include?(eucjp_filename = "%A4%A2".force_encoding("euc-jp"))
filename = eucjp_filename
end
assert_include(ents, filename)
EOS EOS
assert_ruby_status(%w[-EASCII-8BIT], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EASCII-8BIT], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding('ASCII-8BIT') filename = "\xA4\xA2".force_encoding('ASCII-8BIT')
win_expected_filename = filename.encode(Encoding.find("filesystem"), "euc-jp") rescue "?" win_expected_filename = filename.encode(Encoding.find("filesystem"), "euc-jp") rescue "?"
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
result = ents.include?(filename) || unless ents.include?(filename)
(/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("ASCII-8BIT"))) || case RUBY_PLATFORM
(/mswin|mingw/ =~ RUBY_PLATFORM && ents.include?(win_expected_filename.force_encoding("ASCII-8BIT"))) when /darwin/
if !result && /mswin|mingw/ =~ RUBY_PLATFORM if ents.include?(asc_filename = "%A4%A2".force_encoding("ASCII-8BIT"))
exit Dir.entries(".", {:encoding => Encoding.find("filesystem")}).include?(win_expected_filename) filename = asc_filename
end
when /mswin|mingw/
if ents.include?(win_expected_filename.dup.force_encoding("ASCII-8BIT"))
ents = Dir.entries(".", {:encoding => Encoding.find("filesystem")})
filename = win_expected_filename
end
end
end end
exit result assert_include(ents, filename)
EOS EOS
} }
end end
@ -224,18 +236,24 @@ class TestDir_M17N < Test::Unit::TestCase
def test_filename_ext_euc_jp_and_int_utf_8 def test_filename_ext_euc_jp_and_int_utf_8
with_tmpdir {|d| with_tmpdir {|d|
assert_ruby_status(%w[-EEUC-JP], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EEUC-JP], <<-'EOS', :chdir=>d)
filename = "\xA4\xA2".force_encoding("euc-jp") filename = "\xA4\xA2".force_encoding("euc-jp")
File.open(filename, "w") {} File.open(filename, "w") {}
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2".force_encoding("euc-jp"))) if /darwin/ =~ RUBY_PLATFORM && ents.include?(eucjp_filename = "%A4%A2".force_encoding("euc-jp"))
filename = eucjp_filename
end
assert_include(ents, filename)
EOS EOS
assert_ruby_status(%w[-EEUC-JP:UTF-8], <<-'EOS', nil, :chdir=>d) assert_separately(%w[-EEUC-JP:UTF-8], <<-'EOS', :chdir=>d)
filename = "\u3042" filename = "\u3042"
opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM opts = {:encoding => Encoding.default_external} if /mswin|mingw/ =~ RUBY_PLATFORM
ents = Dir.entries(".", opts) ents = Dir.entries(".", opts)
exit ents.include?(filename) || (/darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2")) if /darwin/ =~ RUBY_PLATFORM && ents.include?("%A4%A2")
filename = "%A4%A2"
end
assert_include(ents, filename)
EOS EOS
} }
end end