byebug 3.1.2 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
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,5 +1,5 @@
1
- module InterruptTest
2
- class Example
1
+ module Byebug
2
+ class InterruptExample
3
3
  def self.a(num)
4
4
  num += 2
5
5
  b(num)
@@ -16,49 +16,30 @@ module InterruptTest
16
16
  end
17
17
  end
18
18
 
19
- class InterruptTestCase < TestDsl::TestCase
20
- before do
19
+ class InterruptTestCase < TestCase
20
+ def setup
21
21
  @example = -> do
22
22
  byebug
23
- ex = Example.a(7)
23
+ ex = InterruptExample.a(7)
24
24
  2.times do
25
25
  ex += 1
26
26
  end
27
- Example.b(ex)
27
+ InterruptExample.b(ex)
28
28
  end
29
- end
30
-
31
- describe 'Interrupt Command' do
32
- describe 'method call behaviour' do
33
- it 'must interrupt on the next line' do
34
- enter 'interrupt', 'continue'
35
- debug_proc(@example) do
36
- state.line.must_equal 4
37
- state.file.must_equal __FILE__
38
- end
39
- end
40
-
41
- describe 'when forcestep is set' do
42
- temporary_change_hash Byebug::Setting, :forcestep, true
43
-
44
- it 'must interrupt on the next line' do
45
- enter 'interrupt', 'continue'
46
- debug_proc(@example) do
47
- state.line.must_equal 4
48
- state.file.must_equal __FILE__
49
- end
50
- end
51
29
 
52
- describe 'block behaviour' do
53
- before { enter 'break 24', 'cont' }
30
+ super
31
+ end
54
32
 
55
- it 'must step into blocks' do
56
- enter 'interrupt', 'continue'
57
- debug_proc(@example) { state.line.must_equal 25 }
58
- end
59
- end
60
- end
33
+ def test_interrupt_stops_at_the_next_statement
34
+ enter 'interrupt', 'continue'
35
+ debug_proc(@example) do
36
+ assert_equal [__FILE__, 4], [state.file, state.line]
61
37
  end
62
38
  end
39
+
40
+ def test_interrupt_steps_into_blocks
41
+ enter 'break 24', 'cont', 'interrupt', 'cont'
42
+ debug_proc(@example) { assert_equal 25, state.line }
43
+ end
63
44
  end
64
45
  end
@@ -0,0 +1,47 @@
1
+ module Byebug
2
+ class IrbTestCase < TestCase
3
+ def setup
4
+ @example = -> do
5
+ byebug
6
+ a = 2
7
+ a = 3
8
+ a = 4
9
+ a = 5
10
+ a = 6
11
+ end
12
+
13
+ super
14
+
15
+ interface.stubs(:kind_of?).with(LocalInterface).returns(true)
16
+ IRB::Irb.stubs(:new).returns(irb)
17
+ end
18
+
19
+ def irb
20
+ @irb ||= stub(context: -> {})
21
+ end
22
+
23
+ def test_irb_supports_next_command
24
+ irb.stubs(:eval_input).throws(:IRB_EXIT, :next)
25
+ enter 'irb'
26
+ debug_proc(@example) { assert_equal 7, state.line }
27
+ end
28
+
29
+ def test_irb_supports_step_command
30
+ irb.stubs(:eval_input).throws(:IRB_EXIT, :step)
31
+ enter 'irb'
32
+ debug_proc(@example) { assert_equal 7, state.line }
33
+ end
34
+
35
+ def test_irb_supports_cont_command
36
+ irb.stubs(:eval_input).throws(:IRB_EXIT, :cont)
37
+ enter 'break 8', 'irb'
38
+ debug_proc(@example) { assert_equal 8, state.line }
39
+ end
40
+
41
+ def test_autoirb_calls_irb_automatically_after_every_stop
42
+ irb.expects(:eval_input)
43
+ enter 'set autoirb', 'break 8', 'cont'
44
+ debug_proc(@example)
45
+ end
46
+ end
47
+ end
@@ -1,50 +1,50 @@
1
- module KillTest
2
- class Example
1
+ module Byebug
2
+ class KillExample
3
3
  def self.kill_me
4
4
  'dieeee'
5
5
  end
6
6
  end
7
7
 
8
- class KillTestCase < TestDsl::TestCase
9
- before do
8
+ class KillTestCase < TestCase
9
+ def setup
10
10
  @example = -> do
11
11
  byebug
12
- Example.kill_me
12
+ KillExample.kill_me
13
13
  end
14
+
15
+ super
14
16
  end
15
17
 
16
- it 'must send signal to some pid' do
18
+ def test_kill_sends_signal_to_some_pid
17
19
  Process.expects(:kill).with('USR1', Process.pid)
18
20
  enter 'kill USR1'
19
21
  debug_proc(@example)
20
22
  end
21
23
 
22
- it 'must close interface when sending KILL signal explicitly' do
24
+ def test_kill_closes_interface_when_sending_KILL_signal_explicitly
23
25
  Process.stubs(:kill).with('KILL', Process.pid)
24
26
  interface.expects(:close)
25
27
  enter 'kill KILL'
26
28
  debug_proc(@example)
27
29
  end
28
30
 
29
- it 'must ask confirmation when sending KILL implicitly' do
31
+ def test_kill_asks_confirmation_when_sending_kill_implicitly
30
32
  Process.expects(:kill).with('KILL', Process.pid)
31
33
  enter 'kill', 'y'
32
34
  debug_proc(@example)
33
35
  check_output_includes 'Really kill? (y/n)', interface.confirm_queue
34
36
  end
35
37
 
36
- describe 'unknown signal' do
37
- it 'must not send the signal' do
38
- Process.expects(:kill).with('BLA', Process.pid).never
39
- enter 'kill BLA'
40
- debug_proc(@example)
41
- end
38
+ def test_kill_does_not_send_an_unknown_signal
39
+ Process.expects(:kill).with('BLA', Process.pid).never
40
+ enter 'kill BLA'
41
+ debug_proc(@example)
42
+ end
42
43
 
43
- it 'must show an error' do
44
- enter 'kill BLA'
45
- debug_proc(@example)
46
- check_error_includes 'signal name BLA is not a signal I know about'
47
- end
44
+ def test_kill_shows_an_error_when_the_signal_in_unknown
45
+ enter 'kill BLA'
46
+ debug_proc(@example)
47
+ check_error_includes 'signal name BLA is not a signal I know about'
48
48
  end
49
49
  end
50
50
  end
@@ -1,6 +1,6 @@
1
- module ListTest
2
- class ListTestCase < TestDsl::TestCase
3
- before do
1
+ module Byebug
2
+ class ListTestCase < TestCase
3
+ def setup
4
4
  @example = -> do
5
5
  byebug
6
6
  a = 6
@@ -25,6 +25,8 @@ module ListTest
25
25
  a = 25
26
26
  a = '%26'
27
27
  end
28
+
29
+ super
28
30
  end
29
31
 
30
32
  def lines_between(min, max, mark_current = true)
@@ -38,167 +40,158 @@ module ListTest
38
40
  output
39
41
  end
40
42
 
41
- describe 'listsize' do
42
- it 'must show lines according to :listsize setting' do
43
- debug_proc(@example)
44
- check_output_includes "[1, 10] in #{__FILE__}"
45
- end
46
-
47
- it 'must not set it if the param is not an integer' do
48
- enter 'set listsize 4.0', 'list'
49
- debug_proc(@example)
50
- check_output_includes "[1, 10] in #{__FILE__}"
51
- end
52
-
53
- describe 'when it goes before beginning of file' do
54
- temporary_change_hash Byebug::Setting, :listsize, 12
55
-
56
- it 'must move range up' do
57
- enter 'list'
58
- debug_proc(@example)
59
- check_output_includes "[1, 12] in #{__FILE__}"
60
- end
61
- end
62
-
63
- describe 'when it goes after the end of file' do
64
- it 'must move range down' do
65
- skip "Can't test this with the current setup"
66
- end
67
- end
68
-
69
- describe 'very large' do
70
- temporary_change_hash Byebug::Setting, :listsize, 1000
71
-
72
- it 'must list whole file if number of lines is smaller than listsize' do
73
- n_lines = %x{wc -l #{__FILE__}}.split.first.to_i
74
- debug_proc(@example)
75
- check_output_includes "[1, #{n_lines}] in #{__FILE__}"
76
- end
77
- end
43
+ def test_lists_source_code_lines
44
+ Setting[:listsize] = 10
45
+ enter 'list'
46
+ debug_proc(@example)
47
+ check_output_includes "[1, 10] in #{__FILE__}"
78
48
  end
79
49
 
80
- describe 'without arguments' do
81
- it 'must show surrounding lines with the first call' do
82
- enter 'break 8', 'cont'
83
- debug_proc(@example)
84
- check_output_includes("[3, 12] in #{__FILE__}", *lines_between(3, 12))
85
- end
86
-
87
- it 'must list forward after second call' do
88
- enter 'break 8', 'cont', 'list'
89
- debug_proc(@example)
90
- check_output_includes("[13, 22] in #{__FILE__}",
91
- *lines_between(13, 22, false))
92
- end
50
+ def test_listsize_is_not_set_if_parameter_is_not_an_integer
51
+ enter 'set listsize 15.0', 'list'
52
+ debug_proc(@example)
53
+ check_output_doesnt_include "[1, 15] in #{__FILE__}"
93
54
  end
94
55
 
95
- describe 'list backwards' do
96
- temporary_change_hash Byebug::Setting, :autolist, false
97
-
98
- it 'must show surrounding lines with the first call' do
99
- enter 'break 18', 'cont', 'list -'
100
- debug_proc(@example)
101
- check_output_includes("[13, 22] in #{__FILE__}", *lines_between(13, 22))
102
- end
56
+ def test_moves_range_up_when_it_goes_before_beginning_of_file
57
+ Setting[:listsize] = 12
58
+ enter 'list'
59
+ debug_proc(@example)
60
+ check_output_includes "[1, 12] in #{__FILE__}"
61
+ end
103
62
 
104
- it 'must list backward after second call' do
105
- enter 'break 18', 'cont', 'list -', 'list -'
106
- debug_proc(@example)
107
- check_output_includes("[3, 12] in #{__FILE__}",
108
- *lines_between(3, 12, false))
109
- end
63
+ def test_moves_range_down_when_it_goes_after_the_end_of_file
64
+ skip "Can't test this with the current setup"
110
65
  end
111
66
 
112
- describe 'list surrounding' do
113
- temporary_change_hash Byebug::Setting, :autolist, false
67
+ def test_lists_the_whole_file_if_number_of_lines_is_smaller_than_listsize
68
+ Setting[:listsize] = 1000
69
+ n_lines = %x{wc -l #{__FILE__}}.split.first.to_i
70
+ enter 'list'
71
+ debug_proc(@example)
72
+ check_output_includes "[1, #{n_lines}] in #{__FILE__}"
73
+ end
114
74
 
115
- it 'must show the surrounding lines with =' do
116
- enter 'break 8', 'cont', 'list ='
117
- debug_proc(@example)
118
- check_output_includes("[3, 12] in #{__FILE__}", *lines_between(3, 12))
119
- end
75
+ def test_lists_surrounding_lines_after_the_first_call_to_list
76
+ enter 'break 8', 'cont', 'list'
77
+ debug_proc(@example)
78
+ check_output_includes("[3, 12] in #{__FILE__}", *lines_between(3, 12))
120
79
  end
121
80
 
122
- describe 'specific range' do
123
- it 'must show with mm-nn' do
124
- enter 'list 7-9'
125
- debug_proc(@example)
126
- check_output_includes("[7, 9] in #{__FILE__}",
127
- *lines_between(7, 9, false))
128
- end
81
+ def test_lists_forwards_after_the_second_call_to_list
82
+ enter 'break 8', 'cont', 'list', 'list'
83
+ debug_proc(@example)
84
+ check_output_includes("[13, 22] in #{__FILE__}",
85
+ *lines_between(13, 22, false))
86
+ end
129
87
 
130
- it 'must show with mm,nn' do
131
- enter 'list 7,9'
132
- debug_proc(@example)
133
- check_output_includes("[7, 9] in #{__FILE__}",
134
- *lines_between(7, 9, false))
135
- end
88
+ def test_lists_surrounding_lines_after_the_first_call_to_list_minus
89
+ enter 'break 18', 'cont', 'list -'
90
+ debug_proc(@example)
91
+ check_output_includes("[13, 22] in #{__FILE__}", *lines_between(13, 22))
92
+ end
136
93
 
137
- it 'must show nothing if there is no such lines' do
138
- enter 'list 500,505'
139
- debug_proc(@example)
140
- check_error_includes 'Invalid line range'
141
- check_output_doesnt_include "[500, 505] in #{__FILE__}"
142
- check_output_doesnt_include(/^500 \S/)
143
- end
94
+ def test_lists_backwards_after_the_second_call_to_list_minus
95
+ enter 'break 18', 'cont', 'list -', 'list -'
96
+ debug_proc(@example)
97
+ check_output_includes("[3, 12] in #{__FILE__}",
98
+ *lines_between(3, 12, false))
99
+ end
144
100
 
145
- it 'must show nothing if range is incorrect' do
146
- enter 'list 5,4'
147
- debug_proc(@example)
148
- check_output_includes "[5, 4] in #{__FILE__}"
149
- end
101
+ def test_lists_surrounding_lines_when_list_equals_is_called
102
+ enter 'break 8', 'cont', 'list ='
103
+ debug_proc(@example)
104
+ check_output_includes("[3, 12] in #{__FILE__}", *lines_between(3, 12))
150
105
  end
151
106
 
152
- describe 'arround specific line' do
153
- it 'must show surroundings with mm-' do
154
- enter 'list 17-'
155
- debug_proc(@example)
156
- check_output_includes("[12, 21] in #{__FILE__}",
157
- *lines_between(12, 21, false))
158
- end
107
+ def test_lists_specific_range_when_requested_in_hyphen_format
108
+ enter 'list 7-9'
109
+ debug_proc(@example)
110
+ check_output_includes("[7, 9] in #{__FILE__}",
111
+ *lines_between(7, 9, false))
112
+ end
159
113
 
160
- it 'must show surroundings with mm,' do
161
- enter 'list 17,'
162
- debug_proc(@example)
163
- check_output_includes("[12, 21] in #{__FILE__}",
164
- *lines_between(12, 21, false))
165
- end
114
+ def test_lists_specific_range_when_requested_in_comma_format
115
+ enter 'list 7,9'
116
+ debug_proc(@example)
117
+ check_output_includes("[7, 9] in #{__FILE__}",
118
+ *lines_between(7, 9, false))
166
119
  end
167
120
 
168
- describe 'reload source' do
169
- after { change_line_in_file(__FILE__, 7, ' a = 7') }
121
+ def test_lists_nothing_if_unexistent_range_is_specified
122
+ enter 'list 500,505'
123
+ debug_proc(@example)
124
+ check_error_includes 'Invalid line range'
125
+ check_output_doesnt_include "[500, 505] in #{__FILE__}"
126
+ check_output_doesnt_include(/^500 \S/)
127
+ end
170
128
 
171
- describe 'when autoreload is false' do
172
- temporary_change_hash Byebug::Setting, :autoreload, false
129
+ def test_lists_nothing_if_invalid_range_is_specified
130
+ enter 'list 5,4'
131
+ debug_proc(@example)
132
+ check_output_includes "[5, 4] in #{__FILE__}"
133
+ end
173
134
 
174
- it 'must not reload listing with file changes' do
175
- enter -> { change_line_in_file __FILE__, 7, ' a = 100' ;
176
- 'list 7-7' }
177
- debug_proc(@example)
178
- check_output_includes(/7:\s+a = 7/)
179
- end
180
- end
135
+ def test_list_proper_lines_when_range_around_specific_line_with_hyphen
136
+ enter 'list 17-'
137
+ debug_proc(@example)
138
+ check_output_includes("[12, 21] in #{__FILE__}",
139
+ *lines_between(12, 21, false))
140
+ end
181
141
 
182
- describe 'when autoreload is true' do
183
- it 'must reload listing with file changes' do
184
- enter -> { change_line_in_file __FILE__, 7, ' a = 100' ;
185
- 'list 7-7' }
186
- debug_proc(@example)
187
- check_output_includes(/7:\s+a = 100/)
188
- end
189
- end
142
+ def test_list_proper_lines_when_range_around_specific_line_with_comma
143
+ enter 'list 17,'
144
+ debug_proc(@example)
145
+ check_output_includes("[12, 21] in #{__FILE__}",
146
+ *lines_between(12, 21, false))
190
147
  end
191
148
 
192
- it 'must show an error when there is no such file' do
149
+ def test_shows_an_error_when_the_file_to_list_does_not_exist
193
150
  enter -> { state.file = 'blabla'; 'list 7-7' }
194
151
  debug_proc(@example)
195
152
  check_error_includes 'No sourcefile available for blabla'
196
153
  end
197
154
 
198
- it 'must correctly print lines containing % sign' do
155
+ def test_correctly_print_lines_containing_the_percentage_symbol
199
156
  enter 'list 26'
200
157
  debug_proc(@example)
201
158
  check_output_includes "26: a = '%26'"
202
159
  end
203
160
  end
161
+
162
+ class ListTestCaseAutoreload < ListTestCase
163
+ def setup
164
+ super
165
+ Setting[:autoreload] = true
166
+ enter 'list' # force first reading of file
167
+ end
168
+
169
+ def test_lists_file_changes_with_autoreload_enabled
170
+ enter -> do
171
+ change_line_in_file(__FILE__, 7, ' a = 100')
172
+ 'list 7-7'
173
+ end
174
+ debug_proc(@example)
175
+ check_output_includes(/7:\s+a = 100/)
176
+ change_line_in_file(__FILE__, 7, ' a = 7')
177
+ end
178
+ end
179
+
180
+ class ListTestCaseNoAutoreload < ListTestCase
181
+ def setup
182
+ super
183
+ Setting[:autoreload] = false
184
+ enter 'list' # force first reading of file
185
+ end
186
+
187
+ def test_does_not_list_file_changes_with_autoreload_disabled
188
+ enter -> do
189
+ change_line_in_file(__FILE__, 7, ' a = 100')
190
+ 'list 7-7'
191
+ end
192
+ debug_proc(@example)
193
+ check_output_doesnt_include(/7:\s+a = 100/)
194
+ change_line_in_file(__FILE__, 7, ' a = 7')
195
+ end
196
+ end
204
197
  end