From 16e6d7d186bc9d2ccd14bf5c18cca7f53ff9d970 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Wed, 6 Apr 2022 21:51:00 +0200 Subject: [PATCH] [rubygems/rubygems] Set `@tempdir` as early as possible We have seen some errors during test `setup` before `@tempdir` is actually set, in particular, when instantiating `Gem::MockUI` which in turn requires `stringio`. In this case, the `teardown` method will also produce an error because it tries to remove the `@tempdir`, which has not been set, so tries to remove a `nil` directory. It results in a confusing error like ``` :85:in `require': Interrupt Error: test_bump_one_level(TestGemVersion): TypeError: no implicit conversion of nil into String C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/3.1.0/fileutils.rb:1570:in `path' from :85:in `require' C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/3.1.0/fileutils.rb:1570:in `block in fu_list' from D:/a/rubygems/rubygems/lib/rubygems/mock_gem_ui.rb:43:in `initialize' C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/3.1.0/fileutils.rb:1570:in `map' from D:/a/rubygems/rubygems/test/rubygems/helper.rb:323:in `new' C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/3.1.0/fileutils.rb:1570:in `fu_list' from D:/a/rubygems/rubygems/test/rubygems/helper.rb:323:in `setup' C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/3.1.0/fileutils.rb:616:in `rm_r' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/fixture.rb:284:in `run_fixture_callback' C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/3.1.0/fileutils.rb:638:in `rm_rf' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/fixture.rb:272:in `block in create_fixtures_runner' D:/a/rubygems/rubygems/test/rubygems/helper.rb:462:in `teardown' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/fixture.rb:276:in `block in create_fixtures_runner' =============================================================================== from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/fixture.rb:257:in `run_fixture' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/fixture.rb:292:in `run_setup' Finished in 683.0312862 seconds. from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testcase.rb:564:in `block in run' ------------------------------------------------------------------------------- from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testcase.rb:563:in `catch' 2185 tests, 5929 assertions, 0 failures, 1 errors, 28 pendings, 0 omissions, 0 notifications from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testcase.rb:563:in `run' 98.7185% passed from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testsuite.rb:124:in `run_test' ------------------------------------------------------------------------------- from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testsuite.rb:53:in `run' 3.20 tests/s, 8.68 assertions/sTerminate batch job (Y/N)? from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testsuite.rb:124:in `run_test' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testsuite.rb:53:in `run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testsuite.rb:124:in `run_test' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/testsuite.rb:53:in `run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunnermediator.rb:67:in `run_suite' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunnermediator.rb:45:in `block (2 levels) in run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunnermediator.rb:102:in `with_listener' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunnermediator.rb:41:in `block in run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunnermediator.rb:39:in `catch' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunnermediator.rb:39:in `run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunner.rb:40:in `start_mediator' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunner.rb:25:in `start' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/ui/testrunnerutilities.rb:24:in `run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/autorunner.rb:458:in `block in run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/autorunner.rb:514:in `change_work_directory' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/autorunner.rb:457:in `run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit/autorunner.rb:66:in `run' from C:/hostedtoolcache/windows/Ruby/3.1.1/x64/lib/ruby/gems/3.1.0/gems/test-unit-3.5.3/lib/test/unit.rb:518:in `block (2 levels) in ' rake aborted! Interrupt: ``` The should make this same error much cleaner if it happens again. https://github.com/rubygems/rubygems/commit/fa649d22e8 --- test/rubygems/helper.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index 0fff8cafe8..5ed51fec10 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -308,6 +308,9 @@ class Gem::TestCase < Test::Unit::TestCase FileUtils.mkdir_p @tmp + @tempdir = Dir.mktmpdir("test_rubygems_", @tmp) + @tempdir.tap(&Gem::UNTAINT) + ENV['GEM_VENDOR'] = nil ENV['GEMRC'] = nil ENV['XDG_CACHE_HOME'] = nil @@ -325,9 +328,6 @@ class Gem::TestCase < Test::Unit::TestCase # capture output Gem::DefaultUserInteraction.ui = Gem::MockGemUi.new - @tempdir = Dir.mktmpdir("test_rubygems_", @tmp) - @tempdir.tap(&Gem::UNTAINT) - ENV["TMPDIR"] = @tempdir @orig_SYSTEM_WIDE_CONFIG_FILE = Gem::ConfigFile::SYSTEM_WIDE_CONFIG_FILE