зеркало из https://github.com/github/ruby.git
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:
Родитель
d5a7c704ac
Коммит
c0f0cff56f
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче