aboutsummaryrefslogtreecommitdiffstats
path: root/test/irb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-01-08 04:17:21 +0900
committeraycabta <aycabta@gmail.com>2021-01-08 13:25:18 +0900
commit917050220a1fd41bdb3e50ea54a200b0c285bcd4 (patch)
tree462160f61e14a02c2b9d1aa425f7ba68094708bf /test/irb
parented3264d37abc54e3aade229751a9165ffd37ca2e (diff)
downloadruby-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')
-rw-r--r--test/irb/test_context.rb63
-rw-r--r--test/irb/test_raise_no_backtrace_exception.rb2
2 files changed, 63 insertions, 2 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
diff --git a/test/irb/test_raise_no_backtrace_exception.rb b/test/irb/test_raise_no_backtrace_exception.rb
index 9babc292cd..40ee0c52bf 100644
--- a/test/irb/test_raise_no_backtrace_exception.rb
+++ b/test/irb/test_raise_no_backtrace_exception.rb
@@ -17,7 +17,7 @@ IRB
def test_raise_exception_with_invalid_byte_sequence
skip if RUBY_ENGINE == 'truffleruby'
bundle_exec = ENV.key?('BUNDLE_GEMFILE') ? ['-rbundler/setup'] : []
- assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<~IRB, /StandardError \(A\\xF3B\)/, [])
+ assert_in_out_err(bundle_exec + %w[-rirb -W0 -e IRB.start(__FILE__) -- -f --], <<~IRB, /A\\xF3B \(StandardError\)/, [])
raise StandardError, "A\\xf3B"
IRB
end