Skip to content

Commit 30dc5d4

Browse files
committed
Fix BACK_TRACE_LIMIT logic
1 parent 1c76845 commit 30dc5d4

File tree

2 files changed

+68
-2
lines changed

2 files changed

+68
-2
lines changed

lib/irb.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ def handle_exception(exc)
640640
lines = lines.map { |l| @context.workspace.filter_backtrace(l) }.compact
641641
if lines.size > @context.back_trace_limit
642642
omit = lines.size - @context.back_trace_limit
643-
lines[0..(@context.back_trace_limit - 1)]
644-
lines << '... %d levels...' % omit
643+
lines = lines[0..(@context.back_trace_limit - 1)]
644+
lines << "\t... %d levels..." % omit
645645
end
646646
end
647647
lines = lines.reverse if order == :bottom

test/irb/test_context.rb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,5 +469,71 @@ def test_eval_input_with_invalid_byte_sequence_exception
469469
ensure
470470
$VERBOSE = verbose
471471
end
472+
473+
def test_eval_input_with_long_exception
474+
skip if RUBY_ENGINE == 'truffleruby'
475+
verbose, $VERBOSE = $VERBOSE, nil
476+
nesting = 20
477+
generated_code = ''
478+
nesting.times do |i|
479+
generated_code << "def a#{i}() a#{i + 1}; end; "
480+
end
481+
generated_code << "def a#{nesting}() raise; end; a0\n"
482+
input = TestInputMethod.new([
483+
generated_code
484+
])
485+
irb = IRB::Irb.new(IRB::WorkSpace.new(Object.new), input)
486+
out, err = capture_output do
487+
irb.eval_input
488+
end
489+
assert_empty err
490+
if '2.5.0' <= RUBY_VERSION && RUBY_VERSION < '3.0.0'
491+
expected = [
492+
:*, /Traceback \(most recent call last\):\n/,
493+
:*, /\t... 5 levels...\n/,
494+
:*, /\t16: from \(irb\):1:in `a4'\n/,
495+
:*, /\t15: from \(irb\):1:in `a5'\n/,
496+
:*, /\t14: from \(irb\):1:in `a6'\n/,
497+
:*, /\t13: from \(irb\):1:in `a7'\n/,
498+
:*, /\t12: from \(irb\):1:in `a8'\n/,
499+
:*, /\t11: from \(irb\):1:in `a9'\n/,
500+
:*, /\t10: from \(irb\):1:in `a10'\n/,
501+
:*, /\t 9: from \(irb\):1:in `a11'\n/,
502+
:*, /\t 8: from \(irb\):1:in `a12'\n/,
503+
:*, /\t 7: from \(irb\):1:in `a13'\n/,
504+
:*, /\t 6: from \(irb\):1:in `a14'\n/,
505+
:*, /\t 5: from \(irb\):1:in `a15'\n/,
506+
:*, /\t 4: from \(irb\):1:in `a16'\n/,
507+
:*, /\t 3: from \(irb\):1:in `a17'\n/,
508+
:*, /\t 2: from \(irb\):1:in `a18'\n/,
509+
:*, /\t 1: from \(irb\):1:in `a19'\n/,
510+
:*, /\(irb\):1:in `a20': unhandled exception\n/,
511+
]
512+
else
513+
expected = [
514+
:*, /\(irb\):1:in `a20': unhandled exception\n/,
515+
:*, /\tfrom \(irb\):1:in `a19'\n/,
516+
:*, /\tfrom \(irb\):1:in `a18'\n/,
517+
:*, /\tfrom \(irb\):1:in `a17'\n/,
518+
:*, /\tfrom \(irb\):1:in `a16'\n/,
519+
:*, /\tfrom \(irb\):1:in `a15'\n/,
520+
:*, /\tfrom \(irb\):1:in `a14'\n/,
521+
:*, /\tfrom \(irb\):1:in `a13'\n/,
522+
:*, /\tfrom \(irb\):1:in `a12'\n/,
523+
:*, /\tfrom \(irb\):1:in `a11'\n/,
524+
:*, /\tfrom \(irb\):1:in `a10'\n/,
525+
:*, /\tfrom \(irb\):1:in `a9'\n/,
526+
:*, /\tfrom \(irb\):1:in `a8'\n/,
527+
:*, /\tfrom \(irb\):1:in `a7'\n/,
528+
:*, /\tfrom \(irb\):1:in `a6'\n/,
529+
:*, /\tfrom \(irb\):1:in `a5'\n/,
530+
:*, /\tfrom \(irb\):1:in `a4'\n/,
531+
:*, /\t... 5 levels...\n/,
532+
]
533+
end
534+
assert_pattern_list(expected, out)
535+
ensure
536+
$VERBOSE = verbose
537+
end
472538
end
473539
end

0 commit comments

Comments
 (0)