1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

test_exception.rb: assertions with Exception.to_tty?

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62899 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-03-22 16:05:04 +00:00
parent 9d091c851a
commit e852f9d624

View file

@ -1277,19 +1277,35 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
bt = ["test:100", "test:99", "test:98", "test:1"]
e = assert_raise(RuntimeError) {raise RuntimeError, "testerror", bt}
bottom = "test:100: testerror (RuntimeError)\n"
top = "test:1\n"
remark = "Traceback (most recent call last):"
message = e.full_message(highlight: false, order: :top)
assert_not_match(/\e/, message)
assert_operator(message.count("\n"), :>, 2)
assert_operator(message, :start_with?, "test:100: testerror (RuntimeError)\n")
assert_operator(message, :end_with?, "test:1\n")
assert_operator(message, :start_with?, bottom)
assert_operator(message, :end_with?, top)
message = e.full_message(highlight: false, order: :bottom)
assert_not_match(/\e/, message)
assert_operator(message.count("\n"), :>, 2)
assert_operator(message, :start_with?, "Traceback (most recent call last):")
assert_operator(message, :end_with?, "test:100: testerror (RuntimeError)\n")
assert_operator(message, :start_with?, remark)
assert_operator(message, :end_with?, bottom)
message = e.full_message(highlight: true)
assert_match(/\e/, message)
message = e.full_message
if Exception.to_tty?
assert_match(/\e/, message)
message = message.gsub(/\e\[[\d;]*m/, '')
assert_operator(message, :start_with?, remark)
assert_operator(message, :end_with?, bottom)
else
assert_not_match(/\e/, message)
assert_operator(message, :start_with?, bottom)
assert_operator(message, :end_with?, top)
end
end
end