diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-09 01:25:11 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-04-09 01:25:11 +0000 |
commit | db882e44f92f8e0ea60b86a0c5320fb344a0e443 (patch) | |
tree | 7d8a4973cb71de85d1917b1bf17c5cd6f625393d /test | |
parent | 035ce9f7b5856dc6508c5453fe595f023332a979 (diff) | |
download | ruby-db882e44f92f8e0ea60b86a0c5320fb344a0e443.tar.gz |
assertions.rb: set default internal encoding
* test/lib/test/unit/assertions.rb (assert_raise_with_message):
set default internal encoding to the excpected message, which
affects String#inspect in messages.
* test/lib/test/unit/assertions.rb (assert_warning): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54522 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/-ext-/struct/test_member.rb | 4 | ||||
-rw-r--r-- | test/-ext-/symbol/test_type.rb | 20 | ||||
-rw-r--r-- | test/lib/test/unit/assertions.rb | 20 | ||||
-rw-r--r-- | test/ruby/test_class.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_const.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_exception.rb | 8 | ||||
-rw-r--r-- | test/ruby/test_method.rb | 16 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 11 | ||||
-rw-r--r-- | test/ruby/test_numeric.rb | 20 | ||||
-rw-r--r-- | test/ruby/test_object.rb | 12 | ||||
-rw-r--r-- | test/ruby/test_pack.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_rational.rb | 4 | ||||
-rw-r--r-- | test/ruby/test_regexp.rb | 4 |
13 files changed, 53 insertions, 78 deletions
diff --git a/test/-ext-/struct/test_member.rb b/test/-ext-/struct/test_member.rb index 5ee0adcf67..94735cacb8 100644 --- a/test/-ext-/struct/test_member.rb +++ b/test/-ext-/struct/test_member.rb @@ -9,8 +9,6 @@ class Bug::Struct::Test_Member < Test::Unit::TestCase s = S.new(1) assert_equal(1, s.get(:a)) assert_raise_with_message(NameError, /is not a struct member/) {s.get(:b)} - EnvUtil.with_default_external(Encoding::UTF_8) do - assert_raise_with_message(NameError, /\u{3042}/) {s.get(:"\u{3042}")} - end + assert_raise_with_message(NameError, /\u{3042}/) {s.get(:"\u{3042}")} end end diff --git a/test/-ext-/symbol/test_type.rb b/test/-ext-/symbol/test_type.rb index 32a700d273..7cb3c7b6ef 100644 --- a/test/-ext-/symbol/test_type.rb +++ b/test/-ext-/symbol/test_type.rb @@ -123,21 +123,17 @@ module Test_Symbol end def test_check_id_invalid_type - EnvUtil.with_default_external(Encoding::UTF_8) do - cx = EnvUtil.labeled_class("X\u{1f431}") - assert_raise_with_message(TypeError, /X\u{1F431}/) { - Bug::Symbol.pinneddown?(cx) - } - end + cx = EnvUtil.labeled_class("X\u{1f431}") + assert_raise_with_message(TypeError, /X\u{1F431}/) { + Bug::Symbol.pinneddown?(cx) + } end def test_check_symbol_invalid_type - EnvUtil.with_default_external(Encoding::UTF_8) do - cx = EnvUtil.labeled_class("X\u{1f431}") - assert_raise_with_message(TypeError, /X\u{1F431}/) { - Bug::Symbol.find(cx) - } - end + cx = EnvUtil.labeled_class("X\u{1f431}") + assert_raise_with_message(TypeError, /X\u{1F431}/) { + Bug::Symbol.find(cx) + } end end end diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb index 3cbf32882e..e2bea19c00 100644 --- a/test/lib/test/unit/assertions.rb +++ b/test/lib/test/unit/assertions.rb @@ -131,14 +131,20 @@ module Test raise TypeError, "Expected #{expected.inspect} to be a kind of String or Regexp, not #{expected.class}" end - ex = assert_raise(exception, msg || proc {"Exception(#{exception}) with message matches to #{expected.inspect}"}) {yield} + ex = m = nil + EnvUtil.with_default_internal(expected.encoding) do + ex = assert_raise(exception, msg || proc {"Exception(#{exception}) with message matches to #{expected.inspect}"}) do + yield + end + m = ex.message + end msg = message(msg, "") {"Expected Exception(#{exception}) was raised, but the message doesn't match"} if assert == :assert_equal - assert_equal(expected, ex.message, msg) + assert_equal(expected, m, msg) else - msg = message(msg) { "Expected #{mu_pp expected} to match #{mu_pp ex.message}" } - assert expected =~ ex.message, msg + msg = message(msg) { "Expected #{mu_pp expected} to match #{mu_pp m}" } + assert expected =~ m, msg block.binding.eval("proc{|_|$~=_}").call($~) end ex @@ -626,7 +632,11 @@ eom end def assert_warning(pat, msg = nil) - stderr = EnvUtil.verbose_warning { yield } + stderr = EnvUtil.verbose_warning { + EnvUtil.with_default_internal(pat.encoding) { + yield + } + } msg = message(msg) {diff pat, stderr} assert(pat === stderr, msg) end diff --git a/test/ruby/test_class.rb b/test/ruby/test_class.rb index ce9ffab3c5..65f854d1ff 100644 --- a/test/ruby/test_class.rb +++ b/test/ruby/test_class.rb @@ -544,9 +544,7 @@ class TestClass < Test::Unit::TestCase m = Module.new o = m.module_eval "class A\u{3042}; self; end.new" assert_raise_with_message(TypeError, /A\u{3042}/) { - EnvUtil.with_default_internal(Encoding::UTF_8) { - o::Foo - } + o::Foo } end diff --git a/test/ruby/test_const.rb b/test/ruby/test_const.rb index ff83257c5a..ef5c295b07 100644 --- a/test/ruby/test_const.rb +++ b/test/ruby/test_const.rb @@ -53,12 +53,10 @@ class TestConst < Test::Unit::TestCase name = "X\u{5b9a 6570}" c.const_set(name, 1) prev_line = __LINE__ - 1 - EnvUtil.with_default_internal(Encoding::UTF_8) do - assert_warning(<<-WARNING) {c.const_set(name, 2)} + assert_warning(<<-WARNING) {c.const_set(name, 2)} #{__FILE__}:#{__LINE__-1}: warning: already initialized constant #{c}::#{name} #{__FILE__}:#{prev_line}: warning: previous definition of #{name} was here WARNING - end end def test_redefinition_memory_leak diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 262d27f080..5023262e5d 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -430,11 +430,9 @@ end.join bug3237 = '[ruby-core:29948]' str = "\u2600" id = :"\u2604" - EnvUtil.with_default_external(Encoding::UTF_8) do - msg = "undefined method `#{id}' for #{str.inspect}:String" - assert_raise_with_message(NoMethodError, msg, bug3237) do - str.__send__(id) - end + msg = "undefined method `#{id}' for \"#{str}\":String" + assert_raise_with_message(NoMethodError, msg, bug3237) do + str.__send__(id) end end diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb index 7816e6c3a0..a87f46092d 100644 --- a/test/ruby/test_method.rb +++ b/test/ruby/test_method.rb @@ -252,11 +252,9 @@ class TestMethod < Test::Unit::TestCase m = o.method(:bar).unbind assert_raise(TypeError) { m.bind(Object.new) } - EnvUtil.with_default_external(Encoding::UTF_8) do - cx = EnvUtil.labeled_class("X\u{1f431}") - assert_raise_with_message(TypeError, /X\u{1f431}/) { - o.method(cx) - } + cx = EnvUtil.labeled_class("X\u{1f431}") + assert_raise_with_message(TypeError, /X\u{1f431}/) do + o.method(cx) end end @@ -286,11 +284,9 @@ class TestMethod < Test::Unit::TestCase assert_raise(TypeError) do Class.new.class_eval { define_method(:bar, o.method(:bar)) } end - EnvUtil.with_default_external(Encoding::UTF_8) do - cx = EnvUtil.labeled_class("X\u{1f431}") - assert_raise_with_message(TypeError, /X\u{1F431}/) { - Class.new {define_method(cx) {}} - } + cx = EnvUtil.labeled_class("X\u{1f431}") + assert_raise_with_message(TypeError, /X\u{1F431}/) do + Class.new {define_method(cx) {}} end end diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 5c07f7a382..21162e2256 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -258,7 +258,7 @@ class TestModule < Test::Unit::TestCase "\u3042", "Name?", ].each do |name, msg| - expected = "wrong constant name %s" % quote(name) + expected = "wrong constant name %s" % name msg = "#{msg}#{': ' if msg}wrong constant name #{name.dump}" assert_raise_with_message(NameError, expected, "#{msg} to #{m}") do yield name @@ -709,9 +709,7 @@ class TestModule < Test::Unit::TestCase assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-32be"), :foo) } assert_raise(NameError) { c1.const_set("X\u{3042}".encode("utf-32le"), :foo) } cx = EnvUtil.labeled_class("X\u{3042}") - EnvUtil.with_default_external(Encoding::UTF_8) { - assert_raise_with_message(TypeError, /X\u{3042}/) { c1.const_set(cx, :foo) } - } + assert_raise_with_message(TypeError, /X\u{3042}/) { c1.const_set(cx, :foo) } end def test_const_get_invalid_name @@ -1967,10 +1965,7 @@ class TestModule < Test::Unit::TestCase name = "@\u{5909 6570}" assert_warning(/instance variable #{name} not initialized/) do - val = EnvUtil.with_default_external(Encoding::UTF_8) { - a.instance_eval(name) - } - assert_nil(val) + assert_nil(a.instance_eval(name)) end end diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb index 1710cf8d84..7d53aaaa8e 100644 --- a/test/ruby/test_numeric.rb +++ b/test/ruby/test_numeric.rb @@ -18,18 +18,14 @@ class TestNumeric < Test::Unit::TestCase assert_raise_with_message(TypeError, /can't be coerced into /) {1|:foo} assert_raise_with_message(TypeError, /can't be coerced into /) {1^:foo} - EnvUtil.with_default_external(Encoding::UTF_8) do - assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"} - assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"} - assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"} - assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"} - end - EnvUtil.with_default_external(Encoding::US_ASCII) do - assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"} - assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"} - assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"} - assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"} - end + assert_raise_with_message(TypeError, /:\u{3042}/) {1+:"\u{3042}"} + assert_raise_with_message(TypeError, /:\u{3042}/) {1&:"\u{3042}"} + assert_raise_with_message(TypeError, /:\u{3042}/) {1|:"\u{3042}"} + assert_raise_with_message(TypeError, /:\u{3042}/) {1^:"\u{3042}"} + assert_raise_with_message(TypeError, /:"\\u3042"/) {1+:"\u{3042}"} + assert_raise_with_message(TypeError, /:"\\u3042"/) {1&:"\u{3042}"} + assert_raise_with_message(TypeError, /:"\\u3042"/) {1|:"\u{3042}"} + assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"} bug10711 = '[ruby-core:67405] [Bug #10711]' exp = "1.2 can't be coerced into Fixnum" diff --git a/test/ruby/test_object.rb b/test/ruby/test_object.rb index e170935c3b..62390ad5b5 100644 --- a/test/ruby/test_object.rb +++ b/test/ruby/test_object.rb @@ -387,19 +387,15 @@ class TestObject < Test::Unit::TestCase m = "\u{30e1 30bd 30c3 30c9}" c = Class.new - EnvUtil.with_default_external(Encoding::UTF_8) do - assert_raise_with_message(NameError, /#{m}/) do - c.class_eval {remove_method m} - end + assert_raise_with_message(NameError, /#{m}/) do + c.class_eval {remove_method m} end c = Class.new { define_method(m) {} remove_method(m) } - EnvUtil.with_default_external(Encoding::UTF_8) do - assert_raise_with_message(NameError, /#{m}/) do - c.class_eval {remove_method m} - end + assert_raise_with_message(NameError, /#{m}/) do + c.class_eval {remove_method m} end end diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb index 2d7c0ae8e6..c5af6f2152 100644 --- a/test/ruby/test_pack.rb +++ b/test/ruby/test_pack.rb @@ -790,9 +790,7 @@ EXPECTED [].pack("\x7f") } assert_warning(/\A(.* in '\u{3042}'\n)+\z/) { - EnvUtil.with_default_external(Encoding::UTF_8) { - [].pack("\u{3042}") - } + [].pack("\u{3042}") } end diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index ae46965bcd..801a6fe872 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -112,9 +112,7 @@ class Rational_Test < Test::Unit::TestCase assert_raise(TypeError){Rational(nil)} assert_raise(ArgumentError){Rational('')} assert_raise_with_message(ArgumentError, /\u{221a 2668}/) { - EnvUtil.with_default_external(Encoding::UTF_8) { - Rational("\u{221a 2668}") - } + Rational("\u{221a 2668}") } assert_raise(TypeError){Rational(Object.new)} assert_raise(ArgumentError){Rational()} diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 55e1f3a9c6..fdb27a6c61 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -586,9 +586,7 @@ class TestRegexp < Test::Unit::TestCase key = "\u{3042}" [Encoding::UTF_8, Encoding::Shift_JIS, Encoding::EUC_JP].each do |enc| idx = key.encode(enc) - EnvUtil.with_default_external(enc) do - assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]} - end + assert_raise_with_message(IndexError, /#{idx}/, bug10877) {$~[idx]} end end |