File: stepping_test.rb

package info (click to toggle)
ruby-pry-byebug 3.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 324 kB
  • sloc: ruby: 1,171; makefile: 4
file content (162 lines) | stat: -rw-r--r-- 3,198 bytes parent folder | download
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# frozen_string_literal: true

require "test_helper"

#
# Tests for pry-byebug stepping commands
#
class SteppingTest < MiniTest::Test
  def setup
    super

    @output = StringIO.new
    @input = InputTester.new("break --delete-all")
  end

  def teardown
    clean_remove_const(:SteppingExample)

    super
  end
end

#
# Tests the step command without arguments
#
class StepCommandSingleStepTest < SteppingTest
  def setup
    super

    @input.add("step")
    redirect_pry_io(@input, @output) { load test_file("stepping") }
  end

  def test_stops_at_the_next_statement
    assert_match(/\=> \s*9:/, @output.string)
  end
end

#
# Tests the step command with a step argument
#
class StepCommandMultipleStepTest < SteppingTest
  def setup
    super

    @input.add("step 2")
    redirect_pry_io(@input, @output) { load test_file("stepping") }
  end

  def test_stops_a_correct_number_of_steps_after
    assert_match(/\=> \s*14:/, @output.string)
  end
end

#
# Tests the next command without arguments
#
class NextCommandSingleStepTest < SteppingTest
  def setup
    super

    @input.add("next")
    redirect_pry_io(@input, @output) { load test_file("stepping") }
  end

  def test_stops_at_the_next_line_in_the_current_frame
    assert_match(/\=> \s*26:/, @output.string)
  end
end

#
# Tests the next command with an argument
#
class NextCommandMultipleStepTest < SteppingTest
  def setup
    super

    @input.add("next 2")
    redirect_pry_io(@input, @output) { load test_file("stepping") }
  end

  def test_advances_the_correct_number_of_lines
    assert_match(/\=> \s*27:/, @output.string)
  end
end

#
# Tests that the next Ruby keyword does not conflict with the next command
#
class NextInsideMultilineInput < SteppingTest
  def setup
    super

    @input.add(
      "2.times do |i|",
      "if i == 0",
      "next",
      "end",
      "break 1001 + i",
      "end"
    )

    redirect_pry_io(@input, @output) { load test_file("stepping") }
  end

  def test_it_is_ignored
    assert_match(/\=> \s*8:/, @output.string)
    refute_match(/\=> \s*26:/, @output.string)
  end

  def test_lets_input_be_properly_evaluated
    assert_match(/=> 1002/, @output.string)
  end
end

#
# Tests the finish command
#
class FinishCommand < SteppingTest
  def setup
    super

    @input.add("break 21", "continue", "finish")
    redirect_pry_io(@input, @output) { load test_file("stepping") }
  end

  def test_advances_until_the_end_of_the_current_frame
    assert_match(/\=> \s*17:/, @output.string)
  end
end

#
# Tests the continue command without arguments
#
class ContinueCommandWithoutArguments < SteppingTest
  def setup
    super

    @input.add("break 16", "continue")
    redirect_pry_io(@input, @output) { load test_file("stepping") }
  end

  def test_advances_until_the_next_breakpoint
    assert_match(/\=> \s*16:/, @output.string)
  end
end

#
# Tests the continue command with a line argument
#
class ContinueCommandWithALineArgument < SteppingTest
  def setup
    super

    @input.add("continue 16")
    redirect_pry_io(@input, @output) { load test_file("stepping") }
  end

  def test_advances_until_the_specified_line
    assert_match(/\=> \s*16:/, @output.string)
  end
end