ruby-changes:66174
From: Hiroshi <ko1@a...>
Date: Wed, 12 May 2021 17:25:19 +0900 (JST)
Subject: [ruby-changes:66174] d5237c5d10 (master): [rubygems/rubygems] Import capture_subprocess_io from minitest
https://git.ruby-lang.org/ruby.git/commit/?id=d5237c5d10 From d5237c5d10013e81baab5a78ab74c5b0f2c05825 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA <hsbt@r...> Date: Tue, 11 May 2021 13:04:32 +0900 Subject: [rubygems/rubygems] Import capture_subprocess_io from minitest https://github.com/rubygems/rubygems/commit/8b2ca6df3a --- lib/rubygems/test_case.rb | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 7075347..3d8e6f4 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -145,6 +145,43 @@ class Gem::TestCase < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/lib/rubygems/test_case.rb#L145 assert File.directory?(path), msg end + # https://github.com/seattlerb/minitest/blob/master/lib/minitest/assertions.rb#L188 + def _synchronize + yield + end + + # https://github.com/seattlerb/minitest/blob/master/lib/minitest/assertions.rb#L546 + def capture_subprocess_io + _synchronize do + begin + require "tempfile" + + captured_stdout, captured_stderr = Tempfile.new("out"), Tempfile.new("err") + + orig_stdout, orig_stderr = $stdout.dup, $stderr.dup + $stdout.reopen captured_stdout + $stderr.reopen captured_stderr + + yield + + $stdout.rewind + $stderr.rewind + + return captured_stdout.read, captured_stderr.read + ensure + captured_stdout.unlink + captured_stderr.unlink + $stdout.reopen orig_stdout + $stderr.reopen orig_stderr + + orig_stdout.close + orig_stderr.close + captured_stdout.close + captured_stderr.close + end + end + end + ## # Sets the ENABLE_SHARED entry in RbConfig::CONFIG to +value+ and restores # the original value when the block ends -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/