ruby-changes:70242
From: David <ko1@a...>
Date: Wed, 15 Dec 2021 19:47:00 +0900 (JST)
Subject: [ruby-changes:70242] c2dbdf3067 (master): [rubygems/rubygems] Extract a helper to temporarily modify internal encoding
https://git.ruby-lang.org/ruby.git/commit/?id=c2dbdf3067 From c2dbdf3067c334e22946fbda74181d3a94afbf97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...> Date: Mon, 13 Dec 2021 16:52:37 +0100 Subject: [rubygems/rubygems] Extract a helper to temporarily modify internal encoding https://github.com/rubygems/rubygems/commit/93051fd2aa --- test/rubygems/helper.rb | 9 +++++++++ test/rubygems/test_gem_specification.rb | 27 ++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index b0ad5aafcd6..f321b02e482 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -1300,6 +1300,15 @@ Also, a list: https://github.com/ruby/ruby/blob/trunk/test/rubygems/helper.rb#L1300 Gem.instance_variable_set :@ruby, orig_ruby end + def with_internal_encoding(encoding) + int_enc = Encoding.default_internal + silence_warnings { Encoding.default_internal = encoding } + + yield + ensure + silence_warnings { Encoding.default_internal = int_enc } + end + def silence_warnings old_verbose, $VERBOSE = $VERBOSE, false yield diff --git a/test/rubygems/test_gem_specification.rb b/test/rubygems/test_gem_specification.rb index 3062b66bc6f..b1d925bb57b 100644 --- a/test/rubygems/test_gem_specification.rb +++ b/test/rubygems/test_gem_specification.rb @@ -873,24 +873,21 @@ dependencies: [] https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_specification.rb#L873 end def test_self_load_utf8_with_ascii_encoding - int_enc = Encoding.default_internal - silence_warnings { Encoding.default_internal = 'US-ASCII' } - - spec2 = @a2.dup - bin = "\u5678".dup - spec2.authors = [bin] - full_path = spec2.spec_file - write_file full_path do |io| - io.write spec2.to_ruby_for_cache.force_encoding('BINARY').sub("\\u{5678}", bin.force_encoding('BINARY')) - end + with_internal_encoding('US-ASCII') do + spec2 = @a2.dup + bin = "\u5678".dup + spec2.authors = [bin] + full_path = spec2.spec_file + write_file full_path do |io| + io.write spec2.to_ruby_for_cache.force_encoding('BINARY').sub("\\u{5678}", bin.force_encoding('BINARY')) + end - spec = Gem::Specification.load full_path + spec = Gem::Specification.load full_path - spec2.files.clear + spec2.files.clear - assert_equal spec2, spec - ensure - silence_warnings { Encoding.default_internal = int_enc } + assert_equal spec2, spec + end end def test_self_load_legacy_ruby -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/