diff options
Diffstat (limited to 'test/ruby/test_backtrace.rb')
-rw-r--r-- | test/ruby/test_backtrace.rb | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/test/ruby/test_backtrace.rb b/test/ruby/test_backtrace.rb index bb0562c0bb..fca7b62030 100644 --- a/test/ruby/test_backtrace.rb +++ b/test/ruby/test_backtrace.rb @@ -155,6 +155,10 @@ class TestBacktrace < Test::Unit::TestCase end def test_each_backtrace_location + assert_nil(Thread.each_caller_location {}) + + assert_raise(LocalJumpError) {Thread.each_caller_location} + i = 0 cl = caller_locations(1, 1)[0]; ecl = Thread.each_caller_location{|x| i+=1; break x if i == 1} assert_equal(cl.to_s, ecl.to_s) @@ -181,6 +185,10 @@ class TestBacktrace < Test::Unit::TestCase assert_raise(StopIteration) { ecl.next } + + ary = [] + cl = caller_locations(1, 2); Thread.each_caller_location(1, 2) {|x| ary << x} + assert_equal(cl.map(&:to_s), ary.map(&:to_s)) end def test_caller_locations_first_label @@ -215,15 +223,15 @@ class TestBacktrace < Test::Unit::TestCase @res = caller_locations(2, 1).inspect end @line = __LINE__ + 1 - 1.times.map { 1.times.map { foo } } - assert_equal("[\"#{__FILE__}:#{@line}:in `times'\"]", @res) + [1].map.map { [1].map.map { foo } } + assert_equal("[\"#{__FILE__}:#{@line}:in 'Array#map'\"]", @res) end def test_caller_location_path_cfunc_iseq_no_pc def self.foo @res = caller_locations(2, 1)[0].path end - 1.times.map { 1.times.map { foo } } + [1].map.map { [1].map.map { foo } } assert_equal(__FILE__, @res) end @@ -292,13 +300,13 @@ class TestBacktrace < Test::Unit::TestCase end def test_caller_locations_label - assert_equal("#{__method__}", caller_locations(0, 1)[0].label) + assert_equal("TestBacktrace##{__method__}", caller_locations(0, 1)[0].label) loc, = tap {break caller_locations(0, 1)} - assert_equal("block in #{__method__}", loc.label) + assert_equal("block in TestBacktrace##{__method__}", loc.label) begin raise rescue - assert_equal("rescue in #{__method__}", caller_locations(0, 1)[0].label) + assert_equal("TestBacktrace##{__method__}", caller_locations(0, 1)[0].label) end end @@ -378,17 +386,17 @@ class TestBacktrace < Test::Unit::TestCase def test_core_backtrace_hash_merge e = assert_raise(TypeError) do - {**nil} + {**1} end assert_not_match(/\Acore#/, e.backtrace_locations[0].base_label) end def test_notty_backtrace - err = ["-:1:in `<main>': unhandled exception"] + err = ["-:1:in '<main>': unhandled exception"] assert_in_out_err([], "raise", [], err) - err = ["-:2:in `foo': foo! (RuntimeError)", - "\tfrom -:4:in `<main>'"] + err = ["-:2:in 'Object#foo': foo! (RuntimeError)", + "\tfrom -:4:in '<main>'"] assert_in_out_err([], <<-"end;", [], err) def foo raise "foo!" @@ -396,12 +404,11 @@ class TestBacktrace < Test::Unit::TestCase foo end; - err = ["-:7:in `rescue in bar': bar! (RuntimeError)", - "\tfrom -:4:in `bar'", - "\tfrom -:9:in `<main>'", - "-:2:in `foo': foo! (RuntimeError)", - "\tfrom -:5:in `bar'", - "\tfrom -:9:in `<main>'"] + err = ["-:7:in 'Object#bar': bar! (RuntimeError)", + "\tfrom -:9:in '<main>'", + "-:2:in 'Object#foo': foo! (RuntimeError)", + "\tfrom -:5:in 'Object#bar'", + "\tfrom -:9:in '<main>'"] assert_in_out_err([], <<-"end;", [], err) def foo raise "foo!" @@ -416,7 +423,7 @@ class TestBacktrace < Test::Unit::TestCase end def test_caller_to_enum - err = ["-:3:in `foo': unhandled exception", "\tfrom -:in `each'"] + err = ["-:3:in 'Object#foo': unhandled exception", "\tfrom -:in 'Enumerator#each'"] assert_in_out_err([], <<-"end;", [], err, "[ruby-core:91911]") def foo return to_enum(__method__) unless block_given? @@ -428,4 +435,23 @@ class TestBacktrace < Test::Unit::TestCase enum.next end; end + + def test_no_receiver_for_anonymous_class + err = ["-:2:in 'bar': unhandled exception", # Not '#<Class:0xXXX>.bar' + "\tfrom -:3:in '<main>'"] + assert_in_out_err([], <<-"end;", [], err) + foo = Class.new + def foo.bar = raise + foo.bar + end; + + err = ["-:3:in 'baz': unhandled exception", # Not '#<Class:0xXXX>::Bar.baz' + "\tfrom -:4:in '<main>'"] + assert_in_out_err([], <<-"end;", [], err) + foo = Class.new + foo::Bar = Class.new + def (foo::Bar).baz = raise + foo::Bar.baz + end; + end end |