diff options
author | aycabta <aycabta@gmail.com> | 2021-01-08 04:17:21 +0900 |
---|---|---|
committer | aycabta <aycabta@gmail.com> | 2021-01-08 13:25:18 +0900 |
commit | 917050220a1fd41bdb3e50ea54a200b0c285bcd4 (patch) | |
tree | 462160f61e14a02c2b9d1aa425f7ba68094708bf /test/irb/test_context.rb | |
parent | ed3264d37abc54e3aade229751a9165ffd37ca2e (diff) | |
download | ruby-917050220a1fd41bdb3e50ea54a200b0c285bcd4.tar.gz |
[ruby/irb] Use Exception#full_message to show backtrace in the correct order
[Bug #17466]
https://github.com/ruby/irb/commit/1c76845cca
Diffstat (limited to 'test/irb/test_context.rb')
-rw-r--r-- | test/irb/test_context.rb | 63 |
1 files changed, 62 insertions, 1 deletions
diff --git a/test/irb/test_context.rb b/test/irb/test_context.rb index d1c3ec67ac..b3d1884309 100644 --- a/test/irb/test_context.rb +++ b/test/irb/test_context.rb @@ -83,6 +83,7 @@ module TestIRB end def test_eval_input + skip if RUBY_ENGINE == 'truffleruby' verbose, $VERBOSE = $VERBOSE, nil input = TestInputMethod.new([ "raise 'Foo'\n", @@ -95,7 +96,7 @@ module TestIRB irb.eval_input end assert_empty err - assert_pattern_list([:*, /RuntimeError \(.*Foo.*\).*\n/, + assert_pattern_list([:*, /\(irb\):1:in `<main>': Foo \(RuntimeError\)\n/, :*, /#<RuntimeError: Foo>\n/, :*, /0$/, :*, /0$/, @@ -415,5 +416,65 @@ module TestIRB assert_equal("=> abc\ndef\n", out) end + + def test_eval_input_with_exception + skip if RUBY_ENGINE == 'truffleruby' + verbose, $VERBOSE = $VERBOSE, nil + input = TestInputMethod.new([ + "def hoge() fuga; end; def fuga() raise; end; hoge\n", + ]) + irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) + out, err = capture_output do + irb.eval_input + end + assert_empty err + if '2.5.0' <= RUBY_VERSION && RUBY_VERSION < '3.0.0' + expected = [ + :*, /Traceback \(most recent call last\):\n/, + :*, /\t 2: from \(irb\):1:in `<main>'\n/, + :*, /\t 1: from \(irb\):1:in `hoge'\n/, + :*, /\(irb\):1:in `fuga': unhandled exception\n/, + ] + else + expected = [ + :*, /\(irb\):1:in `fuga': unhandled exception\n/, + :*, /\tfrom \(irb\):1:in `hoge'\n/, + :*, /\tfrom \(irb\):1:in `<main>'\n/, + ] + end + assert_pattern_list(expected, out) + ensure + $VERBOSE = verbose + end + + def test_eval_input_with_invalid_byte_sequence_exception + skip if RUBY_ENGINE == 'truffleruby' + verbose, $VERBOSE = $VERBOSE, nil + input = TestInputMethod.new([ + %Q{def hoge() fuga; end; def fuga() raise "A\\xF3B"; end; hoge\n}, + ]) + irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input) + out, err = capture_output do + irb.eval_input + end + assert_empty err + if '2.5.0' <= RUBY_VERSION && RUBY_VERSION < '3.0.0' + expected = [ + :*, /Traceback \(most recent call last\):\n/, + :*, /\t 2: from \(irb\):1:in `<main>'\n/, + :*, /\t 1: from \(irb\):1:in `hoge'\n/, + :*, /\(irb\):1:in `fuga': A\\xF3B \(RuntimeError\)\n/, + ] + else + expected = [ + :*, /\(irb\):1:in `fuga': A\\xF3B \(RuntimeError\)\n/, + :*, /\tfrom \(irb\):1:in `hoge'\n/, + :*, /\tfrom \(irb\):1:in `<main>'\n/, + ] + end + assert_pattern_list(expected, out) + ensure + $VERBOSE = verbose + end end end |