summaryrefslogtreecommitdiff
path: root/test/ruby/test_backtrace.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_backtrace.rb')
-rw-r--r--test/ruby/test_backtrace.rb31
1 files changed, 30 insertions, 1 deletions
diff --git a/test/ruby/test_backtrace.rb b/test/ruby/test_backtrace.rb
index 60f9605e40..332d76c58e 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,20 @@ 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_each_caller_location_single_cfunc_frame
+ assert_normal_exit <<~'RUBY'
+ tap { Thread.each_caller_location(1, 1) { |loc| loc.label } }
+ RUBY
+
+ cl = nil; ary = []
+ tap { cl = caller_locations(1, 1); Thread.each_caller_location(1, 1) { |x| ary << x } }
+ assert_equal(cl.map(&:to_s), ary.map(&:to_s))
end
def test_caller_locations_first_label
@@ -397,7 +415,6 @@ class TestBacktrace < Test::Unit::TestCase
end;
err = ["-:7:in 'Object#bar': bar! (RuntimeError)",
- "\tfrom -:4:in 'Object#bar'",
"\tfrom -:9:in '<main>'",
"-:2:in 'Object#foo': foo! (RuntimeError)",
"\tfrom -:5:in 'Object#bar'",
@@ -447,4 +464,16 @@ class TestBacktrace < Test::Unit::TestCase
foo::Bar.baz
end;
end
+
+ def test_backtrace_internal_frame
+ backtrace = tap { break caller_locations(0) }
+ assert_equal(__FILE__, backtrace[1].path) # not "<internal:kernel>"
+ assert_equal("Kernel#tap", backtrace[1].label)
+ end
+
+ def test_backtrace_on_argument_error
+ lineno = __LINE__; [1, 2].inject(:tap)
+ rescue ArgumentError
+ assert_equal("#{ __FILE__ }:#{ lineno }:in 'Kernel#tap'", $!.backtrace[0].to_s)
+ end
end