summaryrefslogtreecommitdiff
path: root/tool/lib/core_assertions.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2021-10-09 17:44:01 +0900
committerNobuyoshi Nakada <[email protected]>2021-10-09 18:14:21 +0900
commitc423cc932ee16f64a845e710d92baf79729eae63 ()
tree8235ebdaba1e5b03543c204096a93b577af5652c /tool/lib/core_assertions.rb
parentfc913ad21dcb04bd3d3786f9a3072a6717a52a9a (diff)
Refactor `Test::Unit::CoreAssertions#assert_nothing_raised`
* Separate exception classes to be rescued or reraised * Use the filtered backtrace in the failure message * Raise a new `AssertionFailedError` with the original backtrace
-rw-r--r--tool/lib/core_assertions.rb28
1 files changed, 8 insertions, 20 deletions
@@ -172,27 +172,15 @@ module Test
msg = args.pop
end
begin
- line = __LINE__; yield
- rescue Test::Unit::PendedError
raise
- rescue Exception => e
- bt = e.backtrace
- as = e.instance_of?(Test::Unit::AssertionFailedError)
- if as
- ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /o
- bt.reject! {|ln| ans =~ ln}
- end
- if ((args.empty? && !as) ||
- args.any? {|a| a.instance_of?(Module) ? e.is_a?(a) : e.class == a })
- msg = message(msg) {
- "Exception raised:\n<#{mu_pp(e)}>\n" +
- "Backtrace:\n" +
- e.backtrace.map{|frame| " #{frame}"}.join("\n")
- }
- raise Test::Unit::AssertionFailedError, msg.call, bt
- else
- raise
- end
end
end