1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/irb] Fix BACK_TRACE_LIMIT logic

https://github.com/ruby/irb/commit/30dc5d43fe
This commit is contained in:
aycabta 2021-01-08 04:51:28 +09:00
parent 917050220a
commit 111fddd543
2 changed files with 68 additions and 2 deletions

View file

@ -640,8 +640,8 @@ module IRB
lines = lines.map { |l| @context.workspace.filter_backtrace(l) }.compact
if lines.size > @context.back_trace_limit
omit = lines.size - @context.back_trace_limit
lines[0..(@context.back_trace_limit - 1)]
lines << '... %d levels...' % omit
lines = lines[0..(@context.back_trace_limit - 1)]
lines << "\t... %d levels..." % omit
end
end
lines = lines.reverse if order == :bottom

View file

@ -476,5 +476,71 @@ module TestIRB
ensure
$VERBOSE = verbose
end
def test_eval_input_with_long_exception
skip if RUBY_ENGINE == 'truffleruby'
verbose, $VERBOSE = $VERBOSE, nil
nesting = 20
generated_code = ''
nesting.times do |i|
generated_code << "def a#{i}() a#{i + 1}; end; "
end
generated_code << "def a#{nesting}() raise; end; a0\n"
input = TestInputMethod.new([
generated_code
])
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... 5 levels...\n/,
:*, /\t16: from \(irb\):1:in `a4'\n/,
:*, /\t15: from \(irb\):1:in `a5'\n/,
:*, /\t14: from \(irb\):1:in `a6'\n/,
:*, /\t13: from \(irb\):1:in `a7'\n/,
:*, /\t12: from \(irb\):1:in `a8'\n/,
:*, /\t11: from \(irb\):1:in `a9'\n/,
:*, /\t10: from \(irb\):1:in `a10'\n/,
:*, /\t 9: from \(irb\):1:in `a11'\n/,
:*, /\t 8: from \(irb\):1:in `a12'\n/,
:*, /\t 7: from \(irb\):1:in `a13'\n/,
:*, /\t 6: from \(irb\):1:in `a14'\n/,
:*, /\t 5: from \(irb\):1:in `a15'\n/,
:*, /\t 4: from \(irb\):1:in `a16'\n/,
:*, /\t 3: from \(irb\):1:in `a17'\n/,
:*, /\t 2: from \(irb\):1:in `a18'\n/,
:*, /\t 1: from \(irb\):1:in `a19'\n/,
:*, /\(irb\):1:in `a20': unhandled exception\n/,
]
else
expected = [
:*, /\(irb\):1:in `a20': unhandled exception\n/,
:*, /\tfrom \(irb\):1:in `a19'\n/,
:*, /\tfrom \(irb\):1:in `a18'\n/,
:*, /\tfrom \(irb\):1:in `a17'\n/,
:*, /\tfrom \(irb\):1:in `a16'\n/,
:*, /\tfrom \(irb\):1:in `a15'\n/,
:*, /\tfrom \(irb\):1:in `a14'\n/,
:*, /\tfrom \(irb\):1:in `a13'\n/,
:*, /\tfrom \(irb\):1:in `a12'\n/,
:*, /\tfrom \(irb\):1:in `a11'\n/,
:*, /\tfrom \(irb\):1:in `a10'\n/,
:*, /\tfrom \(irb\):1:in `a9'\n/,
:*, /\tfrom \(irb\):1:in `a8'\n/,
:*, /\tfrom \(irb\):1:in `a7'\n/,
:*, /\tfrom \(irb\):1:in `a6'\n/,
:*, /\tfrom \(irb\):1:in `a5'\n/,
:*, /\tfrom \(irb\):1:in `a4'\n/,
:*, /\t... 5 levels...\n/,
]
end
assert_pattern_list(expected, out)
ensure
$VERBOSE = verbose
end
end
end