ruby-changes:42448
From: nobu <ko1@a...>
Date: Sat, 9 Apr 2016 09:28:35 +0900 (JST)
Subject: [ruby-changes:42448] nobu:r54522 (trunk): assertions.rb: set default internal encoding
nobu 2016-04-09 10:25:11 +0900 (Sat, 09 Apr 2016) New Revision: 54522 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=54522 Log: 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. Modified files: trunk/test/-ext-/struct/test_member.rb trunk/test/-ext-/symbol/test_type.rb trunk/test/lib/test/unit/assertions.rb trunk/test/ruby/test_class.rb trunk/test/ruby/test_const.rb trunk/test/ruby/test_exception.rb trunk/test/ruby/test_method.rb trunk/test/ruby/test_module.rb trunk/test/ruby/test_numeric.rb trunk/test/ruby/test_object.rb trunk/test/ruby/test_pack.rb trunk/test/ruby/test_rational.rb trunk/test/ruby/test_regexp.rb Index: test/ruby/test_const.rb =================================================================== --- test/ruby/test_const.rb (revision 54521) +++ test/ruby/test_const.rb (revision 54522) @@ -53,12 +53,10 @@ class TestConst < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_const.rb#L53 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 Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 54521) +++ test/ruby/test_module.rb (revision 54522) @@ -258,7 +258,7 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L258 "\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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L709 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1965 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 Index: test/ruby/test_exception.rb =================================================================== --- test/ruby/test_exception.rb (revision 54521) +++ test/ruby/test_exception.rb (revision 54522) @@ -430,11 +430,9 @@ end.join https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L430 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 Index: test/ruby/test_class.rb =================================================================== --- test/ruby/test_class.rb (revision 54521) +++ test/ruby/test_class.rb (revision 54522) @@ -544,9 +544,7 @@ class TestClass < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_class.rb#L544 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 Index: test/ruby/test_regexp.rb =================================================================== --- test/ruby/test_regexp.rb (revision 54521) +++ test/ruby/test_regexp.rb (revision 54522) @@ -586,9 +586,7 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L586 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 Index: test/ruby/test_object.rb =================================================================== --- test/ruby/test_object.rb (revision 54521) +++ test/ruby/test_object.rb (revision 54522) @@ -387,19 +387,15 @@ class TestObject < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_object.rb#L387 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 Index: test/ruby/test_rational.rb =================================================================== --- test/ruby/test_rational.rb (revision 54521) +++ test/ruby/test_rational.rb (revision 54522) @@ -112,9 +112,7 @@ class Rational_Test < Test::Unit::TestCa https://github.com/ruby/ruby/blob/trunk/test/ruby/test_rational.rb#L112 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()} Index: test/ruby/test_pack.rb =================================================================== --- test/ruby/test_pack.rb (revision 54521) +++ test/ruby/test_pack.rb (revision 54522) @@ -790,9 +790,7 @@ EXPECTED https://github.com/ruby/ruby/blob/trunk/test/ruby/test_pack.rb#L790 [].pack("\x7f") } assert_warning(/\A(.* in '\u{3042}'\n)+\z/) { - EnvUtil.with_default_external(Encoding::UTF_8) { - [].pack("\u{3042}") - } + [].pack("\u{3042}") } end Index: test/ruby/test_method.rb =================================================================== --- test/ruby/test_method.rb (revision 54521) +++ test/ruby/test_method.rb (revision 54522) @@ -252,11 +252,9 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L252 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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L284 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 Index: test/ruby/test_numeric.rb =================================================================== --- test/ruby/test_numeric.rb (revision 54521) +++ test/ruby/test_numeric.rb (revision 54522) @@ -18,18 +18,14 @@ class TestNumeric < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_numeric.rb#L18 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" Index: test/-ext-/symbol/test_type.rb =================================================================== --- test/-ext-/symbol/test_type.rb (revision 54521) +++ test/-ext-/symbol/test_type.rb (revision 54522) @@ -123,21 +123,17 @@ module Test_Symbol https://github.com/ruby/ruby/blob/trunk/test/-ext-/symbol/test_type.rb#L123 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 Index: test/-ext-/struct/test_member.rb =================================================================== --- test/-ext-/struct/test_member.rb (revision 54521) +++ test/-ext-/struct/test_member.rb (revision 54522) @@ -9,8 +9,6 @@ class Bug::Struct::Test_Member < Test:: https://github.com/ruby/ruby/blob/trunk/test/-ext-/struct/test_member.rb#L9 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 Index: test/lib/test/unit/assertions.rb =================================================================== --- test/lib/test/unit/assertions.rb (revision 54521) +++ test/lib/test/unit/assertions.rb (revision 54522) @@ -131,14 +131,20 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit/assertions.rb#L131 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 https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit/assertions.rb#L632 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 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/