diff options
author | Benoit Daloze <[email protected]> | 2020-10-11 13:36:25 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2020-10-26 08:47:33 +0100 |
commit | cffdacb15a363321e1c1879aa7d94924acafd1cf (patch) | |
tree | 0f5a99285c282368c929b75f5d5e47d5933863b1 /spec | |
parent | fbb2d30ee69c68ffad6287c12ca5a43753cd1b9a (diff) |
Ignore <internal: entries from core library methods for Kernel#warn(message, uplevel: n)
* Fixes [Bug #17259]
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3647
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/kernel/fixtures/warn_core_method.rb | 14 | ||||
-rw-r--r-- | spec/ruby/core/kernel/warn_spec.rb | 16 |
2 files changed, 30 insertions, 0 deletions
diff --git a/spec/ruby/core/kernel/fixtures/warn_core_method.rb b/spec/ruby/core/kernel/fixtures/warn_core_method.rb new file mode 100644 index 0000000000..f5dee6b668 --- /dev/null +++ b/spec/ruby/core/kernel/fixtures/warn_core_method.rb @@ -0,0 +1,14 @@ +raise 'should be run without RubyGems' if defined?(Gem) + +def deprecated(n=1) + # puts nil, caller(0), nil + warn "use X instead", uplevel: n +end + +1.times do # to test with a non-empty stack above the reported locations + deprecated + tap(&:deprecated) + tap { deprecated(2) } + # eval sources with a <internal: file are also ignored + eval "tap(&:deprecated)", nil, "<internal:should-be-skipped-by-warn-uplevel>" +end diff --git a/spec/ruby/core/kernel/warn_spec.rb b/spec/ruby/core/kernel/warn_spec.rb index fcba164f8f..5953a47e81 100644 --- a/spec/ruby/core/kernel/warn_spec.rb +++ b/spec/ruby/core/kernel/warn_spec.rb @@ -114,6 +114,22 @@ describe "Kernel#warn" do end end + guard -> { Kernel.instance_method(:tap).source_location } do + it "skips <internal: core library methods defined in Ruby" do + file, line = Kernel.instance_method(:tap).source_location + file.should.start_with?('<internal:') + + file = fixture(__FILE__ , "warn_core_method.rb") + n = 9 + ruby_exe(file, options: "--disable-gems", args: "2>&1").lines.should == [ + "#{file}:#{n+0}: warning: use X instead\n", + "#{file}:#{n+1}: warning: use X instead\n", + "#{file}:#{n+2}: warning: use X instead\n", + "#{file}:#{n+4}: warning: use X instead\n", + ] + end + end + ruby_version_is "3.0" do it "accepts :category keyword with a symbol" do -> { |