From 917050220a1fd41bdb3e50ea54a200b0c285bcd4 Mon Sep 17 00:00:00 2001 From: aycabta Date: Fri, 8 Jan 2021 04:17:21 +0900 Subject: [ruby/irb] Use Exception#full_message to show backtrace in the correct order [Bug #17466] https://github.com/ruby/irb/commit/1c76845cca --- test/irb/test_context.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'test/irb/test_context.rb') 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 `
': Foo \(RuntimeError\)\n/, :*, /#\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 `
'\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 `
'\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 `
'\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 `
'\n/, + ] + end + assert_pattern_list(expected, out) + ensure + $VERBOSE = verbose + end end end -- cgit v1.2.3