summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-22 16:05:04 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-22 16:05:04 +0000
commite852f9d624aa5e6cec9d04063ed5f32c124573b0 (patch)
tree12a39bfde62b885a098d10a0c98cf5b617cc0b7a /test/ruby
parent9d091c851a6029ac477ecde30766b2d25bad637b (diff)
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
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_exception.rb24
1 files changed, 20 insertions, 4 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb
index 45dbcca22f..574ffbc537 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -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