Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions test/lib/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,24 @@ def assert_local_raise(expected, message = nil)
else
assert_raise(expected, &block)
end
stack = caller
assert_equal stack, error.backtrace&.last(stack.size)
assert_local_backtrace error
error
end

# Asserts that +error+ was raised in the same thread as +caller+ _and_ was
# called from the same level as +caller+. The caller's own frame is ignored,
# as are all extra frames in +error+, but the remaining frames much match.
#
# NOTE: `stack = caller(2)` is different from `$!.backtrace[2..]` in JRuby.
# Rather than use `caller`, this raises a local exception to use its backtrace
# for the comparison.
def assert_local_backtrace(error)
local_stack = raise "generating local backtrace" rescue $!.backtrace[2..]
error_stack = error.backtrace&.last(local_stack.size)
assert_equal local_stack, error_stack
error_stack
end

# Combines +assert_local_raise+ with an assertion that the exception's cause
# is in the receiver thread.
#
Expand Down
2 changes: 1 addition & 1 deletion test/net/imap/test_imap_tls.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_starttls_unknown_ca
imap
end
assert_kind_of(OpenSSL::SSL::SSLError, ex)
assert_equal (stack = caller), ex.backtrace&.last(stack.size)
assert_local_backtrace ex
assert_equal false, imap.tls_verified?
assert_equal({}, imap.ssl_ctx_params)
assert_equal(nil, imap.ssl_ctx.ca_file)
Expand Down
Loading