ruby-changes:49077
From: eregon <ko1@a...>
Date: Wed, 13 Dec 2017 06:51:59 +0900 (JST)
Subject: [ruby-changes:49077] eregon:r61192 (trunk): Do not change Encoding.default_internal in assert_raise_with_message
eregon 2017-12-13 06:51:53 +0900 (Wed, 13 Dec 2017) New Revision: 61192 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61192 Log: Do not change Encoding.default_internal in assert_raise_with_message * It is not thread-safe: if two threads call it concurrently, the default_internal Encoding might not be restored, which causes many problems. The same applies for $VERBOSE, which might also not be restored to its original value but to the new value instead. This happens because reading the original value might capture the value already changed by EnvUtil.with_default_internal in another Thread. One solution could be to capture the value of these globals before running the test. * Reverts part of r54522. Modified files: trunk/test/lib/test/unit/assertions.rb Index: test/lib/test/unit/assertions.rb =================================================================== --- test/lib/test/unit/assertions.rb (revision 61191) +++ test/lib/test/unit/assertions.rb (revision 61192) @@ -133,13 +133,10 @@ module Test https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit/assertions.rb#L133 raise TypeError, "Expected #{expected.inspect} to be a kind of String or Regexp, not #{expected.class}" end - 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 + ex = assert_raise(exception, msg || proc {"Exception(#{exception}) with message matches to #{expected.inspect}"}) do + yield end + m = ex.message msg = message(msg, "") {"Expected Exception(#{exception}) was raised, but the message doesn't match"} if assert == :assert_equal -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/