ruby-changes:49080
From: eregon <ko1@a...>
Date: Wed, 13 Dec 2017 08:41:54 +0900 (JST)
Subject: [ruby-changes:49080] eregon:r61195 (trunk): Capture the values of globals in EnvUtil to restore to the original
eregon 2017-12-13 08:41:50 +0900 (Wed, 13 Dec 2017) New Revision: 61195 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61195 Log: Capture the values of globals in EnvUtil to restore to the original * Avoids the thread-safety issues mentioned in r61192, when thread concurrently modify default Encodings or $VERBOSE. Their state will always be the original one once the test finishes. Modified files: trunk/test/lib/envutil.rb trunk/test/lib/test/unit/assertions.rb Index: test/lib/envutil.rb =================================================================== --- test/lib/envutil.rb (revision 61194) +++ test/lib/envutil.rb (revision 61195) @@ -46,6 +46,14 @@ module EnvUtil https://github.com/ruby/ruby/blob/trunk/test/lib/envutil.rb#L46 class << self attr_accessor :subprocess_timeout_scale + attr_reader :original_internal_encoding, :original_external_encoding, + :original_verbose + + def capture_global_values + @original_internal_encoding = Encoding.default_internal + @original_external_encoding = Encoding.default_external + @original_verbose = $VERBOSE + end end def apply_timeout_scale(t) @@ -167,27 +175,29 @@ module EnvUtil https://github.com/ruby/ruby/blob/trunk/test/lib/envutil.rb#L175 class << (stderr = "".dup) alias write concat end - stderr, $stderr, verbose, $VERBOSE = $stderr, stderr, $VERBOSE, true + stderr, $stderr = $stderr, stderr + $VERBOSE = true yield stderr return $stderr ensure - stderr, $stderr, $VERBOSE = $stderr, stderr, verbose + stderr, $stderr = $stderr, stderr + $VERBOSE = EnvUtil.original_verbose end module_function :verbose_warning def default_warning - verbose, $VERBOSE = $VERBOSE, false + $VERBOSE = false yield ensure - $VERBOSE = verbose + $VERBOSE = EnvUtil.original_verbose end module_function :default_warning def suppress_warning - verbose, $VERBOSE = $VERBOSE, nil + $VERBOSE = nil yield ensure - $VERBOSE = verbose + $VERBOSE = EnvUtil.original_verbose end module_function :suppress_warning @@ -200,26 +210,18 @@ module EnvUtil https://github.com/ruby/ruby/blob/trunk/test/lib/envutil.rb#L210 module_function :under_gc_stress def with_default_external(enc) - verbose, $VERBOSE = $VERBOSE, nil - origenc, Encoding.default_external = Encoding.default_external, enc - $VERBOSE = verbose + suppress_warning { Encoding.default_external = enc } yield ensure - verbose, $VERBOSE = $VERBOSE, nil - Encoding.default_external = origenc - $VERBOSE = verbose + suppress_warning { Encoding.default_external = EnvUtil.original_external_encoding } end module_function :with_default_external def with_default_internal(enc) - verbose, $VERBOSE = $VERBOSE, nil - origenc, Encoding.default_internal = Encoding.default_internal, enc - $VERBOSE = verbose + suppress_warning { Encoding.default_internal = enc } yield ensure - verbose, $VERBOSE = $VERBOSE, nil - Encoding.default_internal = origenc - $VERBOSE = verbose + suppress_warning { Encoding.default_internal = EnvUtil.original_internal_encoding } end module_function :with_default_internal @@ -291,3 +293,5 @@ if defined?(RbConfig) https://github.com/ruby/ruby/blob/trunk/test/lib/envutil.rb#L293 Gem::ConfigMap[:bindir] = dir if defined?(Gem::ConfigMap) end end + +EnvUtil.capture_global_values Index: test/lib/test/unit/assertions.rb =================================================================== --- test/lib/test/unit/assertions.rb (revision 61194) +++ test/lib/test/unit/assertions.rb (revision 61195) @@ -678,8 +678,8 @@ eom https://github.com/ruby/ruby/blob/trunk/test/lib/test/unit/assertions.rb#L678 end def assert_warning(pat, msg = nil) - stderr = EnvUtil.verbose_warning { - EnvUtil.with_default_internal(pat.encoding) { + stderr = EnvUtil.with_default_internal(pat.encoding) { + EnvUtil.verbose_warning { yield } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/