From 404bf57aaffd64cb251574e2916e393d272f77a3 Mon Sep 17 00:00:00 2001 From: nobu Date: Sat, 9 Apr 2016 01:25:11 +0000 Subject: 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 --- test/lib/test/unit/assertions.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'test/lib') 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 -- cgit v1.2.3