|
| 1 | +# Copyright (c) 2021 Oracle and/or its affiliates. All rights reserved. This |
| 2 | +# code is released under a tri EPL/GPL/LGPL license. You can use it, |
| 3 | +# redistribute it and/or modify it under the terms of the: |
| 4 | +# |
| 5 | +# Eclipse Public License version 2.0, or |
| 6 | +# GNU General Public License version 2, or |
| 7 | +# GNU Lesser General Public License version 2.1. |
| 8 | + |
| 9 | +require_relative '../ruby/spec_helper' |
| 10 | + |
| 11 | +# This spec can also run on CRuby, for comparison |
| 12 | +describe "Always-inlined core methods" do |
| 13 | + describe "are part of the backtrace if the error happens inside that core method" do |
| 14 | + it "for #public_send" do |
| 15 | + -> { |
| 16 | + public_send() |
| 17 | + }.should raise_error(ArgumentError) { |e| e.backtrace_locations[0].label.should == 'public_send' } |
| 18 | + -> { |
| 19 | + public_send(Object.new) |
| 20 | + }.should raise_error(TypeError) { |e| e.backtrace_locations[0].label.should == 'public_send' } |
| 21 | + end |
| 22 | + |
| 23 | + guard -> { RUBY_ENGINE != "ruby" } do |
| 24 | + it "for #send" do |
| 25 | + -> { |
| 26 | + send() |
| 27 | + }.should raise_error(ArgumentError) { |e| e.backtrace_locations[0].label.should == '__send__' } |
| 28 | + -> { |
| 29 | + send(Object.new) |
| 30 | + }.should raise_error(TypeError) { |e| e.backtrace_locations[0].label.should == '__send__' } |
| 31 | + end |
| 32 | + |
| 33 | + it "for #__send__" do |
| 34 | + -> { |
| 35 | + __send__() |
| 36 | + }.should raise_error(ArgumentError) { |e| e.backtrace_locations[0].label.should == '__send__' } |
| 37 | + -> { |
| 38 | + __send__(Object.new) |
| 39 | + }.should raise_error(TypeError) { |e| e.backtrace_locations[0].label.should == '__send__' } |
| 40 | + end |
| 41 | + end |
| 42 | + end |
| 43 | + |
| 44 | + describe "are not part of the backtrace if the error happens in a different method" do |
| 45 | + it "for #public_send" do |
| 46 | + -> { |
| 47 | + public_send(:yield_self) { raise "foo" } |
| 48 | + }.should raise_error(RuntimeError, "foo") { |e| |
| 49 | + e.backtrace_locations[0].label.should.start_with?('block (5 levels)') |
| 50 | + e.backtrace_locations[1].label.should == 'yield_self' |
| 51 | + if RUBY_ENGINE == 'ruby' |
| 52 | + e.backtrace_locations[2].label.should == 'public_send' |
| 53 | + else |
| 54 | + e.backtrace_locations[2].label.should.start_with?('block (4 levels)') |
| 55 | + end |
| 56 | + } |
| 57 | + end |
| 58 | + |
| 59 | + it "for #send" do |
| 60 | + -> { |
| 61 | + send(:yield_self) { raise "foo" } |
| 62 | + }.should raise_error(RuntimeError, "foo") { |e| |
| 63 | + e.backtrace_locations[0].label.should.start_with?('block (5 levels)') |
| 64 | + e.backtrace_locations[1].label.should == 'yield_self' |
| 65 | + e.backtrace_locations[2].label.should.start_with?('block (4 levels)') |
| 66 | + } |
| 67 | + end |
| 68 | + |
| 69 | + it "for #__send__" do |
| 70 | + -> { |
| 71 | + __send__(:yield_self) { raise "foo" } |
| 72 | + }.should raise_error(RuntimeError, "foo") { |e| |
| 73 | + e.backtrace_locations[0].label.should.start_with?('block (5 levels)') |
| 74 | + e.backtrace_locations[1].label.should == 'yield_self' |
| 75 | + e.backtrace_locations[2].label.should.start_with?('block (4 levels)') |
| 76 | + } |
| 77 | + end |
| 78 | + end |
| 79 | +end |
0 commit comments