Skip to content

Commit

Permalink
Merge pull request #4075 from eregon/no-kernel-warn-monkey-patch
Browse files Browse the repository at this point in the history
Do not override Kernel#warn when there is no need
  • Loading branch information
deivid-rodriguez committed Dec 7, 2020
2 parents f769aa9 + 1d8375b commit 058e858
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/rubygems.rb
Expand Up @@ -119,6 +119,10 @@ module Gem
# to avoid deprecation warnings in Ruby 2.7.
UNTAINT = RUBY_VERSION < '2.7' ? :untaint.to_sym : proc{}

# When https://bugs.ruby-lang.org/issues/17259 is available, there is no need to override Kernel#warn
KERNEL_WARN_IGNORES_INTERNAL_ENTRIES = RUBY_ENGINE == "truffleruby" ||
(RUBY_ENGINE == "ruby" && RUBY_VERSION >= '3.0')

##
# An Array of Regexps that match windows Ruby platforms.

Expand Down
3 changes: 3 additions & 0 deletions lib/rubygems/core_ext/kernel_require.rb
Expand Up @@ -17,6 +17,8 @@ module Kernel
private :gem_original_require
end

file = Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES ? "<internal:#{__FILE__}>" : __FILE__
module_eval <<'RUBY', file, __LINE__ + 1
##
# When RubyGems is required, Kernel#require is replaced with our own which
# is capable of loading gems on demand.
Expand Down Expand Up @@ -166,6 +168,7 @@ def require(path)
end
end
end
RUBY

private :require

Expand Down
2 changes: 1 addition & 1 deletion lib/rubygems/core_ext/kernel_warn.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# `uplevel` keyword argument of Kernel#warn is available since ruby 2.5.
if RUBY_VERSION >= "2.5"
if RUBY_VERSION >= "2.5" && !Gem::KERNEL_WARN_IGNORES_INTERNAL_ENTRIES

module Kernel
rubygems_path = "#{__dir__}/" # Frames to be skipped start with this path.
Expand Down
2 changes: 1 addition & 1 deletion test/rubygems/test_require.rb
Expand Up @@ -709,7 +709,7 @@ def deprecated
RUBY

_, err = capture_subprocess_io do
system(*ruby_with_rubygems_in_load_path, "-w", "--enable=gems", "-C", dir, "-I", dir, "main.rb")
system(*ruby_with_rubygems_in_load_path, "-w", "--disable=gems", "-C", dir, "-I", dir, "main.rb")
end
assert_match(/main\.rb:2: warning: This is a deprecated method$/, err)
_, err = capture_subprocess_io do
Expand Down

0 comments on commit 058e858

Please sign in to comment.