diff options
author | Yusuke Endoh <[email protected]> | 2022-02-02 15:49:13 +0900 |
---|---|---|
committer | Yusuke Endoh <[email protected]> | 2022-02-22 11:55:40 +0900 |
commit | 5099f64fa4e929e7200bae37ec05d4cfa0f1211b (patch) | |
tree | bfd06854a803b7633791e791f5fc320a5bac9744 | |
parent | 4db986431a10d7b635a17cd0024278a2ede59948 (diff) |
Add a test for Exception#detailed_message
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/5516
-rw-r--r-- | test/ruby/test_exception.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 0a0af390ca..ffa7aa6703 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1421,4 +1421,33 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| end end; end + + def test_detailed_message + e = RuntimeError.new("message") + assert_equal("message (RuntimeError)", e.detailed_message) + assert_equal("\e[1mmessage (\e[1;4mRuntimeError\e[m\e[1m)\e[m", e.detailed_message(highlight: true)) + + e = RuntimeError.new("foo\nbar\nbaz") + assert_equal("foo (RuntimeError)\nbar\nbaz", e.detailed_message) + assert_equal("\e[1mfoo (\e[1;4mRuntimeError\e[m\e[1m)\e[m\n\e[1mbar\e[m\n\e[1mbaz\e[m", e.detailed_message(highlight: true)) + + e = RuntimeError.new("") + assert_equal("unhandled exception", e.detailed_message) + assert_equal("\e[1;4munhandled exception\e[m", e.detailed_message(highlight: true)) + + e = RuntimeError.new + assert_equal("RuntimeError (RuntimeError)", e.detailed_message) + assert_equal("\e[1mRuntimeError (\e[1;4mRuntimeError\e[m\e[1m)\e[m", e.detailed_message(highlight: true)) + end + + def test_full_message_with_custom_detailed_message + e = RuntimeError.new("message") + opt_ = nil + e.define_singleton_method(:detailed_message) do |**opt| + opt_ = opt + "BOO!" + end + assert_match("BOO!", e.full_message.lines.first) + assert_equal({ highlight: Exception.to_tty? }, opt_) + end end |