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
Родитель d5a7c704ac
Коммит c0f0cff56f
3 изменённых файлов: 28 добавлений и 2 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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

Просмотреть файл

@ -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