1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Check whether to skip every frame

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64826 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-09-24 14:26:00 +00:00
parent d5a7c704ac
commit c0f0cff56f
3 changed files with 28 additions and 2 deletions

View file

@ -1392,5 +1392,6 @@ Gem::Specification.load_defaults
require 'rubygems/core_ext/kernel_gem'
require 'rubygems/core_ext/kernel_require'
require 'rubygems/core_ext/kernel_warn'
Gem.use_gemdeps

View file

@ -9,8 +9,15 @@ if RUBY_VERSION >= "2.5"
module_function define_method(:warn) {|*messages, uplevel: nil|
if uplevel
while (loc, = caller_locations(uplevel, 1); loc && loc.path.start_with?(path))
uplevel += 1
uplevel, = [uplevel].pack("l!").unpack("l!")
if uplevel >= 0
start = 0
begin
loc, = caller_locations(start, 1)
break start += uplevel unless loc
start += 1
end while (loc.path.start_with?(path) or (uplevel -= 1) >= 0)
uplevel = start
end
original_warn.call(*messages, uplevel: uplevel)
else

View file

@ -412,6 +412,24 @@ class TestGemRequire < Gem::TestCase
end
end
if RUBY_VERSION >= "2.5"
def test_no_kernel_require_in_warn_with_uplevel
lib = File.realpath("../../../lib", __FILE__)
Dir.mktmpdir("warn_test") do |dir|
File.write(dir + "/sub.rb", "warn 'uplevel', 'test', uplevel: 1\n")
File.write(dir + "/main.rb", "require 'sub'\n")
_, err = capture_subprocess_io do
system(@@ruby, "-w", "-rpp", "--disable=gems", "-I", lib, "-C", dir, "-I.", "main.rb")
end
assert_equal "main.rb:1: warning: uplevel\ntest\n", err
_, err = capture_subprocess_io do
system(@@ruby, "-w", "-rpp", "--enable=gems", "-I", lib, "-C", dir, "-I.", "main.rb")
end
assert_equal "main.rb:1: warning: uplevel\ntest\n", err
end
end
end
def silence_warnings
old_verbose, $VERBOSE = $VERBOSE, false
yield