[前][次][番号順一覧][スレッド一覧]

ruby-changes:61554

From: David <ko1@a...>
Date: Fri, 5 Jun 2020 07:34:38 +0900 (JST)
Subject: [ruby-changes:61554] b35793e0e7 (master): [rubygems/rubygems] Fix test warnings

https://git.ruby-lang.org/ruby.git/commit/?id=b35793e0e7

From b35793e0e74c8abc39d0ae58f75a6ea10983749c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Thu, 21 May 2020 18:52:30 +0200
Subject: [rubygems/rubygems] Fix test warnings

Since `rake package` started printing to stdout by default, we get these
warnings printed when running rubygems tests:

```
$ rake
Run options: --seed 6097

# Running:

......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
 .....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
 ....................................................................................................................................................................................mkdir -p pkg
mkdir -p pkg/pkgr-1.2.3
rm -f pkg/pkgr-1.2.3/x
ln x pkg/pkgr-1.2.3/x
rm -f pkg/pkgr-1.2.3/y
ln y pkg/pkgr-1.2.3/y
cd pkg/pkgr-1.2.3
cd -
....

Finished in 50.578889s, 43.0812 runs/s, 134.8191 assertions/s.
2179 runs, 6819 assertions, 0 failures, 0 errors, 0 skips
Coverage report generated for Unit Tests to /home/deivid/Code/rubygems/coverage. 8080 / 8978 LOC (90.0%) covered.
```

The reason is that, although these tests wrap the
`Rake.application["package"].invoke` with a `capture_io` block, the rake
application initialization happens outside of this block, and a copy of
`$stdout` is saved in there, and that's where the task prints. So the
`capture_io` `$stdout` and `$stderr` dance is not effective.

To fix, we move the `Rake` application initialization inside the
`capture_io` block.

https://github.com/rubygems/rubygems/commit/7f6e2398a5

diff --git a/test/rubygems/test_gem_package_task.rb b/test/rubygems/test_gem_package_task.rb
index 9d87db8..0ce9f08 100644
--- a/test/rubygems/test_gem_package_task.rb
+++ b/test/rubygems/test_gem_package_task.rb
@@ -8,8 +8,6 @@ class TestGemPackageTask < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_package_task.rb#L8
   def setup
     super
 
-    Rake.application = Rake::Application.new
-
     @original_rake_fileutils_verbosity = RakeFileUtils.verbose_flag
   end
 
@@ -31,6 +29,8 @@ class TestGemPackageTask < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_package_task.rb#L29
       g.summary = 'summary'
     end
 
+    Rake.application = Rake::Application.new
+
     pkg = Gem::PackageTask.new(gem) do |p|
       p.package_files << "y"
     end
@@ -57,22 +57,24 @@ class TestGemPackageTask < Gem::TestCase https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_package_task.rb#L57
       g.summary = 'summary'
     end
 
-    pkg = Gem::PackageTask.new(gem) do |p|
-      p.package_files << "y"
-    end
+    _, err = capture_io do
+      Rake.application = Rake::Application.new
 
-    assert_equal %w[x y], pkg.package_files
+      pkg = Gem::PackageTask.new(gem) do |p|
+        p.package_files << "y"
+      end
 
-    Dir.chdir @tempdir do
-      FileUtils.touch 'x'
-      FileUtils.touch 'y'
+      assert_equal %w[x y], pkg.package_files
+
+      Dir.chdir @tempdir do
+        FileUtils.touch 'x'
+        FileUtils.touch 'y'
 
-      _, err = capture_io do
         Rake.application['package'].invoke
       end
-
-      assert_empty err
     end
+
+    assert_empty err
   end
 
   def test_gem_package_with_current_platform
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]