mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
fc913ad21d
commit
c423cc932e
1 changed files with 8 additions and 20 deletions
|
@ -172,27 +172,15 @@ module Test
|
||||||
msg = args.pop
|
msg = args.pop
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
line = __LINE__; yield
|
yield
|
||||||
rescue Test::Unit::PendedError
|
rescue Test::Unit::PendedError, *(Test::Unit::AssertionFailedError if args.empty?)
|
||||||
raise
|
raise
|
||||||
rescue Exception => e
|
rescue *(args.empty? ? Exception : args) => e
|
||||||
bt = e.backtrace
|
msg = message(msg) {
|
||||||
as = e.instance_of?(Test::Unit::AssertionFailedError)
|
"Exception raised:\n<#{mu_pp(e)}>\n""Backtrace:\n" <<
|
||||||
if as
|
Test.filter_backtrace(e.backtrace).map{|frame| " #{frame}"}.join("\n")
|
||||||
ans = /\A#{Regexp.quote(__FILE__)}:#{line}:in /o
|
}
|
||||||
bt.reject! {|ln| ans =~ ln}
|
raise Test::Unit::AssertionFailedError, msg.call, e.backtrace
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue