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 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
# frozen_string_literal: true
require "test_helper"
module Byebug
#
# Tests basic stepping behaviour.
#
class BasicSteppingTest < TestCase
def program
strip_line_numbers <<-RUBY
1: module Byebug
2: #
3: # Toy class to test stepping.
4: #
5: class #{example_class}
6: def self.add_four(num)
7: num += 4
8: num
9: end
10: end
11:
12: byebug
13:
14: res = #{example_class}.add_four(7)
15:
16: res + 1
17: end
RUBY
end
def test_step_goes_to_the_next_statement
enter "step"
debug_code(program) { assert_equal 7, frame.line }
end
def test_s_goes_to_the_next_statement
enter "s"
debug_code(program) { assert_equal 7, frame.line }
end
end
#
# Tests step/next with arguments higher than one.
#
class MoreThanOneStepTest < TestCase
def program
strip_line_numbers <<-RUBY
1: module Byebug
2: #
3: # Toy class to test advanced stepping.
4: #
5: class #{example_class}
6: def self.add_three(num)
7: byebug
8: 2.times do
9: num += 1
10: end
11:
12: num *= 2
13: num
14: end
15: end
16:
17: res = #{example_class}.add_three(7)
18:
19: res
20: end
RUBY
end
def step_steps_into_blocks
enter "step 2"
debug_code(program) { assert_equal 9, frame.line }
end
def step_steps_out_of_blocks_when_done
enter "step 3"
debug_code(program) { assert_equal 12, frame.line }
end
end
#
# Tests step/next behaviour in combination with backtrace commands.
#
class SteppingBacktracesTest < TestCase
def program
strip_line_numbers <<-RUBY
1: module Byebug
2: #
3: # Toy class to test the combination of "up" and "next" commands.
4: #
5: class #{example_class}
6: def a
7: byebug
8: r = b(c)
9: r + 1
10: end
11:
12: def b(p)
13: r = 2
14: p + r
15: end
16:
17: def c
18: s = 3
19: s + 2
20: end
21: end
22:
23: #{example_class}.new.a
24: end
RUBY
end
def test_step_then_up_then_steps_in_from_the_upper_frame
enter "step", "up", "step"
debug_code(program) { assert_equal 13, frame.line }
end
end
end
|