1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
# frozen_string_literal: true
require "test_helper"
module Byebug
#
# Tests post mortem functionality.
#
class PostMortemTest < TestCase
def program
strip_line_numbers <<-RUBY
1: module Byebug
2: #
3: # Toy class to test post mortem functionality
4: #
5: class #{example_class}
6: def a
7: fail "blabla"
8: end
9: end
10:
11: byebug
12:
13: c = #{example_class}.new
14: c.a
15: end
RUBY
end
def test_rises_before_exit_in_post_mortem_mode
with_setting :post_mortem, true do
enter "cont"
assert_raises(RuntimeError) { debug_code(program) }
end
end
def test_post_mortem_mode_sets_post_mortem_flag_to_true
with_setting :post_mortem, true do
enter "cont"
begin
debug_code(program)
rescue RuntimeError
assert_equal true, Byebug.post_mortem?
end
end
end
def test_execution_is_stopped_at_the_correct_line_after_exception
with_setting :post_mortem, true do
enter "cont"
begin
debug_code(program)
rescue StandardError
assert_equal 7, Byebug.raised_exception.__bb_context.frame.line
end
end
end
def test_command_forbidden_in_post_mortem_mode
with_post_mortem_processor do
with_setting :post_mortem, true do
enter "help next"
begin
debug_code(program)
rescue RuntimeError
check_error_includes "Unknown command 'next'. Try 'help'"
end
end
end
end
def test_command_permitted_in_post_mortem_mode
with_post_mortem_processor do
with_setting :post_mortem, true do
enter "help where"
begin
debug_code(program)
rescue RuntimeError
check_output_includes "Displays the backtrace"
end
end
end
end
private
def with_post_mortem_processor
old_processor = Context.processor
Context.processor = PostMortemProcessor
yield
ensure
Context.processor = old_processor
end
end
end
|