byebug 3.1.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (97) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +4 -2
  3. data/CHANGELOG.md +15 -0
  4. data/GUIDE.md +17 -35
  5. data/Gemfile +8 -5
  6. data/LICENSE +1 -1
  7. data/README.md +10 -22
  8. data/Rakefile +1 -1
  9. data/ext/byebug/byebug.c +3 -2
  10. data/lib/byebug.rb +3 -38
  11. data/lib/byebug/commands/break.rb +83 -0
  12. data/lib/byebug/commands/catchpoint.rb +0 -1
  13. data/lib/byebug/commands/condition.rb +10 -6
  14. data/lib/byebug/commands/continue.rb +3 -6
  15. data/lib/byebug/commands/delete.rb +38 -0
  16. data/lib/byebug/commands/edit.rb +0 -2
  17. data/lib/byebug/commands/enable.rb +7 -8
  18. data/lib/byebug/commands/finish.rb +0 -2
  19. data/lib/byebug/commands/frame.rb +13 -15
  20. data/lib/byebug/commands/help.rb +1 -3
  21. data/lib/byebug/commands/history.rb +3 -3
  22. data/lib/byebug/commands/info.rb +4 -13
  23. data/lib/byebug/commands/interrupt.rb +25 -0
  24. data/lib/byebug/commands/kill.rb +0 -2
  25. data/lib/byebug/commands/list.rb +2 -4
  26. data/lib/byebug/commands/method.rb +2 -8
  27. data/lib/byebug/commands/quit.rb +0 -2
  28. data/lib/byebug/commands/reload.rb +2 -15
  29. data/lib/byebug/commands/repl.rb +0 -3
  30. data/lib/byebug/commands/{control.rb → restart.rb} +2 -26
  31. data/lib/byebug/commands/save.rb +0 -1
  32. data/lib/byebug/commands/set.rb +4 -7
  33. data/lib/byebug/commands/show.rb +0 -3
  34. data/lib/byebug/commands/source.rb +0 -3
  35. data/lib/byebug/commands/stepping.rb +3 -4
  36. data/lib/byebug/commands/trace.rb +0 -1
  37. data/lib/byebug/commands/variables.rb +3 -4
  38. data/lib/byebug/context.rb +0 -1
  39. data/lib/byebug/helper.rb +23 -0
  40. data/lib/byebug/interfaces/script_interface.rb +1 -1
  41. data/lib/byebug/processors/command_processor.rb +9 -9
  42. data/lib/byebug/remote.rb +2 -2
  43. data/lib/byebug/setting.rb +3 -1
  44. data/lib/byebug/settings/autoeval.rb +3 -1
  45. data/lib/byebug/settings/autoirb.rb +3 -1
  46. data/lib/byebug/settings/autolist.rb +3 -1
  47. data/lib/byebug/settings/autoreload.rb +1 -3
  48. data/lib/byebug/settings/autosave.rb +1 -3
  49. data/lib/byebug/settings/callstyle.rb +2 -4
  50. data/lib/byebug/settings/fullpath.rb +1 -3
  51. data/lib/byebug/settings/histfile.rb +1 -3
  52. data/lib/byebug/settings/histsize.rb +0 -4
  53. data/lib/byebug/settings/listsize.rb +1 -3
  54. data/lib/byebug/settings/post_mortem.rb +14 -1
  55. data/lib/byebug/settings/width.rb +1 -17
  56. data/lib/byebug/version.rb +1 -1
  57. data/test/break_test.rb +376 -0
  58. data/test/condition_test.rb +82 -0
  59. data/test/continue_test.rb +27 -30
  60. data/test/debugger_alias_test.rb +4 -4
  61. data/test/delete_test.rb +26 -0
  62. data/test/display_test.rb +80 -102
  63. data/test/edit_test.rb +28 -31
  64. data/test/eval_test.rb +50 -80
  65. data/test/finish_test.rb +23 -23
  66. data/test/frame_test.rb +172 -186
  67. data/test/help_test.rb +27 -37
  68. data/test/history_test.rb +32 -41
  69. data/test/info_test.rb +198 -230
  70. data/test/interrupt_test.rb +17 -36
  71. data/test/irb_test.rb +47 -0
  72. data/test/kill_test.rb +19 -19
  73. data/test/list_test.rb +126 -133
  74. data/test/method_test.rb +21 -54
  75. data/test/post_mortem_test.rb +44 -46
  76. data/test/pry_test.rb +42 -0
  77. data/test/quit_test.rb +17 -15
  78. data/test/reload_test.rb +23 -28
  79. data/test/restart_test.rb +35 -63
  80. data/test/save_test.rb +46 -62
  81. data/test/set_test.rb +93 -144
  82. data/test/show_test.rb +50 -71
  83. data/test/source_test.rb +23 -26
  84. data/test/stepping_test.rb +125 -153
  85. data/test/support/matchers.rb +1 -6
  86. data/test/support/test_interface.rb +1 -1
  87. data/test/support/{test_dsl.rb → utils.rb} +17 -64
  88. data/test/test_helper.rb +25 -7
  89. data/test/thread_test.rb +101 -89
  90. data/test/trace_test.rb +48 -85
  91. data/test/variables_test.rb +43 -80
  92. metadata +18 -13
  93. data/lib/byebug/commands/breakpoints.rb +0 -137
  94. data/lib/byebug/commands/skip.rb +0 -30
  95. data/test/breakpoints_test.rb +0 -474
  96. data/test/conditions_test.rb +0 -82
  97. data/test/repl_test.rb +0 -75
@@ -1,44 +1,41 @@
1
- module SourceTest
2
- class SourceTestCase < TestDsl::TestCase
3
- let(:filename) { 'source_example.txt' }
4
-
5
- before do
1
+ module Byebug
2
+ class SourceTestCase < TestCase
3
+ def setup
6
4
  @example = -> do
7
5
  byebug
8
6
  a = 2
9
7
  a = 3
10
8
  end
11
9
 
12
- File.open(filename, 'w') do |f|
10
+ File.open('source_example.txt', 'w') do |f|
13
11
  f.puts 'break 2'
14
12
  f.puts 'break 3 if true'
15
13
  end
16
- end
17
-
18
- after { FileUtils.rm(filename) }
19
14
 
20
- it 'must run commands from file' do
21
- enter "source #{filename}"
22
- debug_proc(@example) do
23
- Byebug.breakpoints[0].pos.must_equal 2
24
- Byebug.breakpoints[1].pos.must_equal 3
25
- Byebug.breakpoints[1].expr.must_equal 'true'
26
- end
15
+ super
27
16
  end
28
17
 
29
- it 'must be able to use shortcut' do
30
- enter "so #{filename}"
31
- debug_proc(@example) { Byebug.breakpoints[0].pos.must_equal 2 }
18
+ def teardown
19
+ FileUtils.rm('source_example.txt')
32
20
  end
33
21
 
34
- it 'must show an error if file is not found' do
35
- enter 'source blabla'
36
- debug_proc(@example)
37
- check_error_includes(/File ".*blabla" not found/)
38
- end
22
+ %w(source so).each do |cmd_alias|
23
+ define_method(:"test_#{cmd_alias}_runs_byebug_commands_from_file") do
24
+ enter "#{cmd_alias} source_example.txt"
25
+ debug_proc(@example) do
26
+ assert_equal 2, Byebug.breakpoints[0].pos
27
+ assert_equal 3, Byebug.breakpoints[1].pos
28
+ assert_equal 'true', Byebug.breakpoints[1].expr
29
+ end
30
+ end
31
+
32
+ define_method(:"test_#{cmd_alias}_shows_an_error_if_file_not_found") do
33
+ enter "#{cmd_alias} blabla"
34
+ debug_proc(@example)
35
+ check_error_includes(/File ".*blabla" not found/)
36
+ end
39
37
 
40
- describe 'Help' do
41
- it 'must show help when used without arguments' do
38
+ define_method(:"test_#{cmd_alias}_without_arguments_shows_help") do
42
39
  enter 'source'
43
40
  debug_proc(@example)
44
41
  check_output_includes \
@@ -1,4 +1,4 @@
1
- module SteppingTest
1
+ module Byebug
2
2
  class Example
3
3
  def self.a(num)
4
4
  num += 2
@@ -16,8 +16,41 @@ module SteppingTest
16
16
  end
17
17
  end
18
18
 
19
- class SteppingTestCase < TestDsl::TestCase
20
- before do
19
+ class BasicSteppingTestCase < TestCase
20
+ def setup
21
+ @example = -> do
22
+ byebug
23
+
24
+ ex = Example.c(7)
25
+ ex
26
+ end
27
+
28
+ super
29
+ end
30
+
31
+ def test_next_goes_to_the_next_line
32
+ enter 'next'
33
+ debug_proc(@example) { assert_equal 25, state.line }
34
+ end
35
+
36
+ def test_n_goes_to_the_next_line
37
+ enter 'n'
38
+ debug_proc(@example) { assert_equal 25, state.line }
39
+ end
40
+
41
+ def test_step_goes_to_the_next_statement
42
+ enter 'step'
43
+ debug_proc(@example) { assert_equal 14, state.line }
44
+ end
45
+
46
+ def test_s_goes_to_the_next_statement
47
+ enter 's'
48
+ debug_proc(@example) { assert_equal 14, state.line }
49
+ end
50
+ end
51
+
52
+ class AdvancedStepping < TestCase
53
+ def setup
21
54
  @example = -> do
22
55
  byebug
23
56
 
@@ -28,184 +61,123 @@ module SteppingTest
28
61
 
29
62
  Example.b(ex)
30
63
  end
31
- end
32
64
 
33
- describe 'Next Command' do
34
- describe 'method call behaviour' do
35
- before { enter 'break 9', 'cont' }
65
+ super
36
66
 
37
- it 'must leave on the same line by default' do
38
- enter 'next'
39
- debug_proc(@example) { state.line.must_equal 9 }
40
- end
67
+ enter 'break 9', 'cont'
68
+ end
41
69
 
42
- it 'must go to the next line if forced by "plus" sign' do
43
- enter 'next+'
44
- debug_proc(@example) { state.line.must_equal 10 }
45
- end
70
+ %w(next step).each do |cmd|
71
+ define_method(:"test_#{cmd}_stays_by_default") do
72
+ enter cmd
73
+ debug_proc(@example) { assert_equal 9, state.line }
74
+ end
46
75
 
47
- it 'must leave on the same line if forced by "minus" sign' do
48
- enter 'next-'
49
- debug_proc(@example) { state.line.must_equal 9 }
50
- end
76
+ define_method(:"test_#{cmd}+_goes_2_next_line") do
77
+ enter "#{cmd}+"
78
+ debug_proc(@example) { assert_equal 10, state.line }
79
+ end
51
80
 
52
- describe 'when forcestep is set' do
53
- temporary_change_hash Byebug::Setting, :forcestep, true
81
+ define_method(:"test_#{cmd}-_stays") do
82
+ enter "#{cmd}-"
83
+ debug_proc(@example) { assert_equal 9, state.line }
84
+ end
54
85
 
55
- it 'must go to the next line' do
56
- enter 'next'
57
- debug_proc(@example) { state.line.must_equal 10 }
58
- end
86
+ define_method(:"test_#{cmd}_goes_2_next_line_if_forcestep_is_set") do
87
+ enter 'set forcestep', cmd
88
+ debug_proc(@example) { assert_equal 10, state.line }
89
+ end
59
90
 
60
- it 'must go to the next line (by shortcut)' do
61
- enter 'n'
62
- debug_proc(@example) { state.line.must_equal 10 }
63
- end
91
+ define_method(:"test_#{cmd}+_goes_2_next_line_regardless_forcestep") do
92
+ enter 'set forcestep', "#{cmd}+"
93
+ debug_proc(@example) { assert_equal 10, state.line }
94
+ end
95
+
96
+ define_method(:"test_#{cmd}-_stays_regardless_forcestep") do
97
+ enter 'set forcestep', "#{cmd}-"
98
+ debug_proc(@example) { assert_equal 9, state.line }
99
+ end
100
+ end
64
101
 
65
- it 'must go the specified number of lines forward by default' do
66
- enter 'next 2'
67
- debug_proc(@example) { state.line.must_equal 25 }
68
- end
102
+ def test_next_goes_the_specified_number_of_lines_forward_by_default
103
+ enter 'set forcestep', 'next 2'
104
+ debug_proc(@example) { assert_equal 58, state.line }
105
+ end
69
106
 
70
- it 'must inform when not staying in the same frame' do
71
- enter 'next 2'
72
- debug_proc(@example)
73
- check_output_includes \
74
- 'Next went up a frame because previous frame finished'
75
- end
107
+ def test_next_informs_when_not_staying_in_the_same_frame
108
+ enter 'set forcestep', 'next 2'
109
+ debug_proc(@example)
110
+ check_output_includes \
111
+ 'Next went up a frame because previous frame finished'
112
+ end
76
113
 
114
+ def step_goes_the_specified_number_of_statements_forward_by_default
115
+ enter 'set forcestep', 'step 2'
116
+ debug_proc(@example) { assert_equal 58, state.line }
117
+ end
77
118
 
78
- it 'must ignore it if "minus" is specified' do
79
- enter 'next-'
80
- debug_proc(@example) { state.line.must_equal 9 }
81
- end
82
- end
83
- end
119
+ def test_next_steps_OVER_blocks
120
+ enter 'break 58', 'cont', 'next'
121
+ debug_proc(@example) { assert_equal 62, state.line }
122
+ end
84
123
 
85
- describe 'block behaviour' do
86
- before { enter 'break 57', 'cont' }
124
+ def test_step_steps_INTO_blocks
125
+ enter 'break 58', 'cont', 'step'
126
+ debug_proc(@example) { assert_equal 59, state.line }
127
+ end
87
128
 
88
- it 'must step over blocks' do
89
- enter 'next'
90
- debug_proc(@example) { state.line.must_equal 24 }
91
- end
129
+ class RaiseFromCMethodExample
130
+ def a
131
+ b
132
+ rescue NameError
133
+ 1
92
134
  end
93
135
 
94
- describe 'raise/rescue behaviour' do
95
- describe 'from c method' do
96
- before do
97
- @example_raise = -> do
98
- byebug
99
-
100
- class RaiseFromCMethodExample
101
- def a
102
- b
103
- rescue NameError
104
- 1
105
- end
106
-
107
- def b
108
- c
109
- end
110
-
111
- def c
112
- d
113
- end
114
- end
115
-
116
- RaiseFromCMethodExample.new.a
117
- end
118
- enter 'break 102', 'cont'
119
- end
120
-
121
- it 'must step over rescue' do
122
- enter 'next'
123
- debug_proc(@example_raise) { state.line.must_equal 104 }
124
- end
125
- end
136
+ def b
137
+ c
138
+ end
126
139
 
127
- describe 'from ruby method' do
128
- before do
129
- @example_raise = -> do
130
- byebug
131
-
132
- class RaiseFromRubyMethodExample
133
- def a
134
- b
135
- rescue
136
- 1
137
- end
138
-
139
- def b
140
- c
141
- end
142
-
143
- def c
144
- raise 'bang'
145
- end
146
- end
147
-
148
- RaiseFromRubyMethodExample.new.a
149
- end
150
- enter 'break 134', 'cont'
151
- end
152
-
153
- it 'must step over rescue' do
154
- enter 'next'
155
- debug_proc(@example_raise) { state.line.must_equal 136 }
156
- end
157
- end
140
+ def c
141
+ d
158
142
  end
159
143
  end
160
144
 
161
- describe 'Step Command' do
162
-
163
- describe 'method call behaviour' do
164
- before { enter 'break 9', 'cont' }
165
-
166
- it 'must leave on the same line if forced by a setting' do
167
- enter 'step'
168
- debug_proc(@example) { state.line.must_equal 9 }
169
- end
170
-
171
- it 'must go to the step line if forced to do that by "plus" sign' do
172
- enter 'step+'
173
- debug_proc(@example) { state.line.must_equal 10 }
174
- end
145
+ def test_next_steps_over_rescue_when_raising_from_c_method
146
+ example_raise = -> do
147
+ byebug
175
148
 
176
- it 'must leave on the same line if forced to do that by "minus" sign' do
177
- enter 'step-'
178
- debug_proc(@example) { state.line.must_equal 9 }
179
- end
149
+ RaiseFromCMethodExample.new.a
150
+ end
180
151
 
181
- describe 'when forcestep is set' do
182
- temporary_change_hash Byebug::Setting, :forcestep, true
152
+ enter 'break 131', 'cont', 'next'
153
+ debug_proc(example_raise) { assert_equal 133, state.line }
154
+ end
183
155
 
184
- it 'must go to the step line if forced by a setting' do
185
- enter 'step'
186
- debug_proc(@example) { state.line.must_equal 10 }
187
- end
156
+ class RaiseFromRubyMethodExample
157
+ def a
158
+ b
159
+ rescue
160
+ 1
161
+ end
188
162
 
189
- it 'must go to the next line if forced by a setting (by shortcut)' do
190
- enter 's'
191
- debug_proc(@example) { state.line.must_equal 10 }
192
- end
163
+ def b
164
+ c
165
+ end
193
166
 
194
- it 'must go the specified number of lines forward by default' do
195
- enter 'step 2'
196
- debug_proc(@example) { state.line.must_equal 14 }
197
- end
198
- end
167
+ def c
168
+ raise 'bang'
199
169
  end
170
+ end
200
171
 
201
- describe 'block behaviour' do
202
- before { enter 'break 25', 'cont' }
172
+ def test_next_steps_over_rescue_when_raising_from_ruby_method
173
+ example_raise = -> do
174
+ byebug
203
175
 
204
- it 'must step into blocks' do
205
- enter 'step'
206
- debug_proc(@example) { state.line.must_equal 26 }
207
- end
176
+ RaiseFromRubyMethodExample.new.a
208
177
  end
178
+
179
+ enter 'break 158', 'cont', 'next'
180
+ debug_proc(example_raise) { assert_equal 160, state.line }
209
181
  end
210
182
  end
211
183
  end
@@ -1,4 +1,4 @@
1
- module MiniTest::Assertions
1
+ module Minitest::Assertions
2
2
 
3
3
  # This matcher checks that given collection is included into the original
4
4
  # collection and in correct order. It accepts both strings and regexps.
@@ -61,8 +61,3 @@ module MiniTest::Assertions
61
61
  result
62
62
  end
63
63
  end
64
-
65
- module MiniTest::Expectations
66
- infect_an_assertion :assert_includes_in_order, :must_include_in_order
67
- infect_an_assertion :refute_includes_in_order, :wont_include_in_order
68
- end
@@ -8,7 +8,7 @@ module Byebug
8
8
 
9
9
  def initialize
10
10
  @input_queue, @output_queue, @error_queue = [], [], []
11
- @confirm_queue, @command_queue, @history = [], [], Byebug::History.new
11
+ @confirm_queue, @command_queue, @history = [], [], History.new
12
12
  end
13
13
 
14
14
  def errmsg(*args)
@@ -1,62 +1,7 @@
1
- module TestDsl
2
-
3
- class TestCase < MiniTest::Spec
4
- include TestDsl
5
-
6
- def setup
7
- Byebug.handler = Byebug::CommandProcessor.new(Byebug::TestInterface.new)
8
- Byebug.breakpoints.clear if Byebug.breakpoints
9
- end
10
-
11
- def self.temporary_change_hash hash, key, value
12
- before do
13
- @old_hashes ||= {}
14
- @old_hashes.merge!({ hash => { key => hash[key] } }) do |k, v1, v2|
15
- v1.merge(v2)
16
- end
17
- hash[key] = value
18
- end
19
-
20
- after do
21
- hash[key] = @old_hashes[hash][key]
22
- end
23
- end
24
-
25
- def self.temporary_change_const klass, const, value
26
- before do
27
- @old_consts ||= {}
28
- old_value = klass.const_defined?(const) ?
29
- klass.const_get(const) : :__undefined__
30
- @old_consts.merge!({ klass => { const => old_value } }) do |k, v1, v2|
31
- v1.merge(v2)
32
- end
33
- klass.send :remove_const, const if klass.const_defined?(const)
34
- klass.const_set const, value unless value == :__undefined__
35
- end
36
-
37
- after do
38
- klass.send :remove_const, const if klass.const_defined?(const)
39
- klass.const_set const, @old_consts[klass][const] unless
40
- @old_consts[klass][const] == :__undefined__
41
- end
42
- end
43
- end
44
-
45
- #
46
- # Expand fullpath of a given example file
47
- #
48
- def fullpath(filename)
49
- (Pathname.new(__FILE__) + "../../examples/#{filename}.rb").cleanpath.to_s
50
- end
51
-
52
- #
53
- # Shorten a fullpath
54
- #
55
- def shortpath(fullpath)
56
- separator = File::ALT_SEPARATOR || File::SEPARATOR
57
- "...#{separator}" + fullpath.split(separator)[-3..-1].join(separator)
58
- end
1
+ require_relative 'matchers'
2
+ require_relative 'test_interface'
59
3
 
4
+ module Byebug::TestUtils
60
5
  #
61
6
  # Adds commands to the input queue, so they will be later retrieved by
62
7
  # Processor, i.e., it emulates user's input.
@@ -77,7 +22,7 @@ module TestDsl
77
22
  end
78
23
 
79
24
  #
80
- # Runs the provided Proc.
25
+ # Runs the provided Proc
81
26
  #
82
27
  # You also can specify a block, which will be executed when Processor extracts
83
28
  # all the commands from the input queue. You can use that for making asserts
@@ -92,7 +37,7 @@ module TestDsl
92
37
  # byebug
93
38
  # puts 'hello'
94
39
  # end
95
- # debug_proc(code) { state.line.must_equal 4 }
40
+ # debug_proc(code) { assert_equal 4, state.line }
96
41
  #
97
42
  def debug_proc(program, &block)
98
43
  Byebug.stubs(:run_init_script)
@@ -120,19 +65,19 @@ module TestDsl
120
65
  interface.output_queue : args.pop
121
66
  queue_messages = queue.map(&:strip)
122
67
  messages = Array(args).map { |msg| msg.is_a?(String) ? msg.strip : msg }
123
- queue_messages.send(check_method, messages)
68
+ send(check_method, messages, queue_messages)
124
69
  end
125
70
 
126
71
  def check_error_includes(*args)
127
- check_output :must_include_in_order, *args, interface.error_queue
72
+ check_output :assert_includes_in_order, *args, interface.error_queue
128
73
  end
129
74
 
130
75
  def check_output_includes(*args)
131
- check_output :must_include_in_order, *args
76
+ check_output :assert_includes_in_order, *args
132
77
  end
133
78
 
134
79
  def check_output_doesnt_include(*args)
135
- check_output :wont_include_in_order, *args
80
+ check_output :refute_includes_in_order, *args
136
81
  end
137
82
 
138
83
  def interface
@@ -143,6 +88,14 @@ module TestDsl
143
88
  Thread.current.thread_variable_get('state')
144
89
  end
145
90
 
91
+ def first_brkpt
92
+ Byebug.breakpoints.first
93
+ end
94
+
95
+ def last_brkpt
96
+ Byebug.breakpoints.last
97
+ end
98
+
146
99
  def context
147
100
  state.context
148
101
  end