[rubygems/rubygems] Avoid crash in test teardown

If an exception happens during test `setup` method, the `teardown`
method will still be run for cleaning up, but if some other errors
occurs then, it will hide the original error.

This is happening sometimes in CI where restoring original gem hooks is
failing because the error in `setup` happened before the variable
holding the original hooks was initialized.

This commit moves initialization of `@orig_hooks` to the beginning of
the `setup` method to avoid this issue.

https://github.com/rubygems/rubygems/commit/8524d2b74d
This commit is contained in:
David Rodríguez 2022-03-23 20:52:19 +01:00 committed by git
parent 8b05b5a0e1
commit d9dd88a686

View File

@ -302,6 +302,7 @@ class Gem::TestCase < Test::Unit::TestCase
# or <tt>i686-darwin8.10.1</tt> otherwise. # or <tt>i686-darwin8.10.1</tt> otherwise.
def setup def setup
@orig_hooks = {}
@orig_env = ENV.to_hash @orig_env = ENV.to_hash
@tmp = File.expand_path("tmp") @tmp = File.expand_path("tmp")
@ -426,7 +427,6 @@ class Gem::TestCase < Test::Unit::TestCase
util_set_arch 'i686-darwin8.10.1' util_set_arch 'i686-darwin8.10.1'
end end
@orig_hooks = {}
%w[post_install_hooks done_installing_hooks post_uninstall_hooks pre_uninstall_hooks pre_install_hooks pre_reset_hooks post_reset_hooks post_build_hooks].each do |name| %w[post_install_hooks done_installing_hooks post_uninstall_hooks pre_uninstall_hooks pre_install_hooks pre_reset_hooks post_reset_hooks post_build_hooks].each do |name|
@orig_hooks[name] = Gem.send(name).dup @orig_hooks[name] = Gem.send(name).dup
end end