byebug 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/GUIDE.md +231 -0
  4. data/README.md +195 -7
  5. data/bin/byebug +1 -5
  6. data/byebug.gemspec +34 -35
  7. data/lib/byebug.rb +2 -5
  8. data/lib/byebug/command.rb +13 -13
  9. data/lib/byebug/commands/breakpoints.rb +1 -1
  10. data/lib/byebug/commands/control.rb +1 -1
  11. data/lib/byebug/commands/frame.rb +1 -1
  12. data/lib/byebug/commands/info.rb +1 -1
  13. data/lib/byebug/commands/list.rb +5 -5
  14. data/lib/byebug/commands/reload.rb +7 -10
  15. data/lib/byebug/commands/{irb.rb → repl.rb} +49 -13
  16. data/lib/byebug/commands/set.rb +10 -6
  17. data/lib/byebug/commands/show.rb +4 -7
  18. data/lib/byebug/commands/trace.rb +2 -2
  19. data/lib/byebug/context.rb +3 -5
  20. data/lib/byebug/helper.rb +2 -2
  21. data/lib/byebug/interface.rb +3 -0
  22. data/lib/byebug/processor.rb +2 -2
  23. data/lib/byebug/version.rb +1 -1
  24. data/old_doc/byebug.1 +1 -2
  25. data/old_doc/byebug.texi +125 -126
  26. data/old_doc/hanoi.rb +2 -3
  27. data/old_doc/triangle.rb +6 -7
  28. data/test/breakpoints_test.rb +43 -33
  29. data/test/display_test.rb +1 -1
  30. data/test/edit_test.rb +20 -15
  31. data/test/eval_test.rb +32 -26
  32. data/test/examples/list.rb +12 -1
  33. data/test/frame_test.rb +56 -43
  34. data/test/help_test.rb +11 -8
  35. data/test/info_test.rb +18 -13
  36. data/test/list_test.rb +74 -80
  37. data/test/method_test.rb +1 -3
  38. data/test/reload_test.rb +3 -3
  39. data/test/repl_test.rb +112 -0
  40. data/test/restart_test.rb +72 -70
  41. data/test/set_test.rb +43 -27
  42. data/test/show_test.rb +97 -102
  43. data/test/source_test.rb +6 -10
  44. data/test/stepping_test.rb +45 -49
  45. data/test/support/test_dsl.rb +47 -55
  46. data/test/test_helper.rb +2 -2
  47. data/test/trace_test.rb +4 -4
  48. data/test/variables_test.rb +10 -8
  49. metadata +9 -10
  50. data/old_doc/Makefile +0 -20
  51. data/test/examples/edit2.rb +0 -3
  52. data/test/irb_test.rb +0 -85
@@ -5,8 +5,10 @@ describe 'Info Command' do
5
5
  include Columnize
6
6
 
7
7
  describe 'Args info' do
8
+ temporary_change_hash Byebug::Command.settings, :width, 15
9
+
8
10
  it 'must show info about all args' do
9
- enter 'set width 15', 'break 3', 'cont', 'info args'
11
+ enter 'break 3', 'cont', 'info args'
10
12
  debug_file 'info'
11
13
  check_output_includes 'a = "aaaaaaa...', 'b = "b"'
12
14
  end
@@ -91,14 +93,14 @@ describe 'Info Command' do
91
93
  end
92
94
 
93
95
  describe 'File info' do
94
- let(:file) { fullpath('info') }
96
+ let(:file) { fullpath('info') }
95
97
  let(:filename) { "File #{file}" }
96
- let(:lines) { "#{LineCache.size(file)} lines" }
97
- let(:mtime) { LineCache.stat(file).mtime.to_s }
98
- let(:sha1) { LineCache.sha1(file) }
98
+ let(:lines) { "#{LineCache.size(file)} lines" }
99
+ let(:mtime) { LineCache.stat(file).mtime.to_s }
100
+ let(:sha1) { LineCache.sha1(file) }
99
101
  let(:breakpoint_line_numbers) {
100
102
  columnize(LineCache.trace_line_numbers(file).to_a.sort,
101
- Byebug::InfoCommand.settings[:width]) }
103
+ Byebug::Command.settings[:width]) }
102
104
 
103
105
  it 'must show basic info about the file' do
104
106
  enter "info file #{file} basic"
@@ -175,14 +177,16 @@ describe 'Info Command' do
175
177
  end
176
178
 
177
179
  describe 'Locals info' do
180
+ temporary_change_hash Byebug::Command.settings, :width, 21
181
+
178
182
  it 'must show the current local variables' do
179
- enter 'set width 12', 'break 21', 'cont', 'info locals'
183
+ enter 'break 21', 'cont', 'info locals'
180
184
  debug_file 'info'
181
- check_output_includes 'a = "1111...', 'b = 2'
185
+ check_output_includes 'a = "1111111111111...', 'b = 2'
182
186
  end
183
187
 
184
188
  it 'must fail if local variable doesn\'t respond to #to_s or to #inspect' do
185
- enter 'set width 21', 'break 26', 'cont', 'info locals'
189
+ enter 'break 26', 'cont', 'info locals'
186
190
  debug_file 'info'
187
191
  check_output_includes '*Error in evaluation*'
188
192
  end
@@ -227,11 +231,12 @@ describe 'Info Command' do
227
231
  end
228
232
 
229
233
  describe 'Stack info' do
230
- let(:width) { " #2 <main> at #{fullpath('info')}:36".size }
234
+ # XXX: Calculate magic number dinamically, like
235
+ # "longest_string_in_test_output".size
236
+ temporary_change_hash Byebug::Command.settings, :width, 87
231
237
 
232
238
  it 'must show stack info' do
233
- enter 'set fullpath', ->{ "set width #{width}"}, 'break 20', 'cont',
234
- 'info stack'
239
+ enter 'set fullpath', 'break 20', 'cont', 'info stack'
235
240
  debug_file 'info'
236
241
  check_output_includes "--> #0 A.a at #{fullpath('info')}:20",
237
242
  " #1 A.b at #{fullpath('info')}:30",
@@ -248,7 +253,7 @@ describe 'Info Command' do
248
253
  end
249
254
 
250
255
  describe 'Variables info' do
251
- before { Byebug::Command.settings[:width] = 30 }
256
+ temporary_change_hash Byebug::Command.settings, :width, 30
252
257
 
253
258
  it 'must show all variables' do
254
259
  enter 'break 21', 'cont', 'info variables'
@@ -3,123 +3,105 @@ require_relative 'test_helper'
3
3
  describe 'List Command' do
4
4
  include TestDsl
5
5
 
6
- def after_setup
7
- LineCache.clear_file_cache
8
- Byebug::Command.settings[:listsize] = 3
9
- Byebug::Command.settings[:autolist] = 0
10
- end
11
-
12
6
  describe 'listsize' do
13
7
  it 'must show lines according to :listsize setting' do
14
- enter 'set listsize 4', 'break 5', 'cont', 'list'
8
+ enter 'break 5', 'cont'
15
9
  debug_file 'list'
16
- check_output_includes "[3, 6] in #{fullpath('list')}"
10
+ check_output_includes "[1, 10] in #{fullpath('list')}"
17
11
  end
18
12
 
19
13
  it 'must not set it if the param is not an integer' do
20
- enter 'set listsize 4.0', 'break 5', 'cont', 'list'
14
+ enter 'set listsize 4.0', 'break 5', 'cont'
21
15
  debug_file 'list'
22
- check_output_includes "[4, 6] in #{fullpath('list')}"
16
+ check_output_includes "[1, 10] in #{fullpath('list')}"
23
17
  end
24
18
 
25
19
  it 'must move range up when it goes before begining of file' do
26
- enter 'set listsize 10', 'break 3', 'cont', 'list'
20
+ enter 'break 3', 'cont'
27
21
  debug_file 'list'
28
22
  check_output_includes "[1, 10] in #{fullpath('list')}"
29
23
  end
30
24
 
31
25
  it 'must move range down when it goes after end of file' do
32
- enter 'set listsize 10', 'break 10', 'cont', 'list'
26
+ enter 'break 10', 'cont'
33
27
  debug_file 'list'
34
- check_output_includes "[3, 12] in #{fullpath('list')}"
28
+ check_output_includes "[5, 14] in #{fullpath('list')}"
35
29
  end
36
30
 
37
- it 'must list whole file if number of lines is smaller than listsize' do
38
- enter 'set listsize 13', 'list'
39
- debug_file 'list'
40
- check_output_includes "[1, 12] in #{fullpath('list')}"
41
- end
31
+ describe 'very large' do
32
+ temporary_change_hash Byebug::Command.settings, :listsize, 50
42
33
 
34
+ it 'must list whole file if number of lines is smaller than listsize' do
35
+ enter 'break 3', 'cont'
36
+ debug_file 'list'
37
+ check_output_includes "[1, 23] in #{fullpath('list')}"
38
+ end
39
+ end
43
40
  end
44
41
 
45
42
  describe 'without arguments' do
46
43
  it 'must show surrounding lines with the first call' do
47
- enter 'break 5', 'cont', 'list'
44
+ enter 'break 5', 'cont'
48
45
  debug_file 'list'
49
- check_output_includes \
50
- "[4, 6] in #{fullpath('list')}", '4 4', '=> 5 5', '6 6'
46
+ check_output_includes "[1, 10] in #{fullpath('list')}", '1: byebug',
47
+ '2: 2', '3: 3', '4: 4', '=> 5: 5', '6: 6', '7: 7', '8: 8', '9: 9',
48
+ '10: 10'
51
49
  end
52
50
 
53
51
  it 'must list forward after second call' do
54
- enter 'break 5', 'cont', 'list', 'list'
52
+ enter 'break 5', 'cont', 'list'
55
53
  debug_file 'list'
56
- check_output_includes \
57
- "[7, 9] in #{fullpath('list')}", '7 7', '8 8', '9 9'
54
+ check_output_includes "[11, 20] in #{fullpath('list')}", '11: 11',
55
+ '12: 12', '13: 13', '14: 14', '15: 15', '16: 16', '17: 17', '18: 18',
56
+ '19: 19', '20: 20'
58
57
  end
59
58
  end
60
59
 
61
60
  describe 'list backward' do
61
+ temporary_change_hash Byebug::Command.settings, :autolist, 0
62
+
62
63
  it 'must show surrounding lines with the first call' do
63
- enter 'break 5', 'cont', 'list -'
64
+ enter 'break 15', 'cont', 'list -'
64
65
  debug_file 'list'
65
- check_output_includes \
66
- "[4, 6] in #{fullpath('list')}", '4 4', '=> 5 5', '6 6'
66
+ check_output_includes "[10, 19] in #{fullpath('list')}", '10: 10',
67
+ '11: 11', '12: 12', '13: 13', '14: 14', '=> 15: 15', '16: 16', '17: 17',
68
+ '18: 18', '19: 19'
67
69
  end
68
70
 
69
71
  it 'must list backward after second call' do
70
- enter 'break 5', 'cont', 'list -', 'list -'
72
+ enter 'break 15', 'cont', 'list -', 'list -'
71
73
  debug_file 'list'
72
- check_output_includes \
73
- "[1, 3] in #{fullpath('list')}", '1 byebug', '2 2', '3 3'
74
+ check_output_includes "[1, 10] in #{fullpath('list')}", '1: byebug',
75
+ '2: 2', '3: 3', '4: 4', '5: 5', '6: 6', '7: 7', '8: 8', '9: 9',
76
+ '10: 10'
74
77
  end
75
78
  end
76
79
 
77
-
78
80
  describe 'list surrounding' do
81
+ temporary_change_hash Byebug::Command.settings, :autolist, 0
82
+
79
83
  it 'must show the surrounding lines with =' do
80
84
  enter 'break 5', 'cont', 'list ='
81
85
  debug_file 'list'
82
- check_output_includes \
83
- "[4, 6] in #{fullpath('list')}", '4 4', '=> 5 5', '6 6'
86
+ check_output_includes "[1, 10] in #{fullpath('list')}", '1: byebug',
87
+ '2: 2', '3: 3', '4: 4', '=> 5: 5', '6: 6', '7: 7', '8: 8', '9: 9',
88
+ '10: 10'
84
89
  end
85
90
  end
86
91
 
87
- describe 'autolist' do
88
- it 'must show the surronding lines after stop if autolist is enabled' do
89
- enter 'set autolist', 'break 5', 'cont'
90
- debug_file 'list'
91
- check_output_includes \
92
- "[4, 6] in #{fullpath('list')}", '4 4', '=> 5 5', '6 6'
93
- end
94
- end
95
-
96
- describe 'specified lines' do
92
+ describe 'specific range' do
97
93
  it 'must show with mm-nn' do
98
94
  enter 'list 4-6'
99
95
  debug_file 'list'
100
96
  check_output_includes \
101
- "[4, 6] in #{fullpath('list')}", '4 4', '5 5', '6 6'
97
+ "[4, 6] in #{fullpath('list')}", '4: 4', '5: 5', '6: 6'
102
98
  end
103
99
 
104
100
  it 'must show with mm,nn' do
105
101
  enter 'list 4,6'
106
102
  debug_file 'list'
107
103
  check_output_includes \
108
- "[4, 6] in #{fullpath('list')}", '4 4', '5 5', '6 6'
109
- end
110
-
111
- it 'must show surroundings with mm-' do
112
- enter 'list 4-'
113
- debug_file 'list'
114
- check_output_includes \
115
- "[3, 5] in #{fullpath('list')}", '3 3', '4 4', '5 5'
116
- end
117
-
118
- it 'must show surroundings with mm,' do
119
- enter 'list 4,'
120
- debug_file 'list'
121
- check_output_includes \
122
- "[3, 5] in #{fullpath('list')}", '3 3', '4 4', '5 5'
104
+ "[4, 6] in #{fullpath('list')}", '4: 4', '5: 5', '6: 6'
123
105
  end
124
106
 
125
107
  it 'must show nothing if there is no such lines' do
@@ -134,33 +116,46 @@ describe 'List Command' do
134
116
  enter 'list 5,4'
135
117
  debug_file 'list'
136
118
  check_output_includes "[5, 4] in #{fullpath('list')}"
137
- check_output_doesnt_include '5 5'
138
- check_output_doesnt_include '4 4'
139
119
  end
140
120
  end
141
121
 
142
- describe 'reload source' do
143
- after do
144
- change_line_in_file(fullpath('list'), 4, '4')
145
- Byebug::Command.settings[:reload_source_on_change] = true
122
+ describe 'arround specific line' do
123
+ it 'must show surroundings with mm-' do
124
+ enter 'list 14-'
125
+ debug_file 'list'
126
+ check_output_includes "[9, 18] in #{fullpath('list')}", '9: 9', '10: 10',
127
+ '11: 11', '12: 12', '13: 13', '14: 14', '15: 15', '16: 16', '17: 17',
128
+ '18: 18'
146
129
  end
147
130
 
148
- it 'must not reload if setting is false' do
149
- enter 'set noautoreload', -> do
150
- change_line_in_file(fullpath('list'), 4, '100')
151
- 'list 4-4'
152
- end
131
+ it 'must show surroundings with mm,' do
132
+ enter 'list 14,'
153
133
  debug_file 'list'
154
- check_output_includes '4 4'
134
+ check_output_includes "[9, 18] in #{fullpath('list')}", '9: 9', '10: 10',
135
+ '11: 11', '12: 12', '13: 13', '14: 14', '15: 15', '16: 16', '17: 17',
136
+ '18: 18'
155
137
  end
138
+ end
139
+
140
+ describe 'reload source' do
141
+ after { change_line_in_file(fullpath('list'), 4, '4') }
142
+
143
+ describe 'when autoreload is false' do
144
+ temporary_change_hash Byebug::Command.settings, :autoreload, false
156
145
 
157
- it 'must reload if setting is true' do
158
- enter 'set autoreload', -> do
159
- change_line_in_file(fullpath('list'), 4, '100')
160
- 'list 4-4'
146
+ it 'must not reload listing with file changes' do
147
+ enter -> { change_line_in_file fullpath('list'), 4, '100' ; 'list 4-4' }
148
+ debug_file 'list'
149
+ check_output_includes '4: 4'
150
+ end
151
+ end
152
+
153
+ describe 'when autoreload is true' do
154
+ it 'must reload listing with file changes' do
155
+ enter -> { change_line_in_file fullpath('list'), 4, '100' ; 'list 4-4' }
156
+ debug_file 'list'
157
+ check_output_includes '4: 100'
161
158
  end
162
- debug_file 'list'
163
- check_output_includes '4 100'
164
159
  end
165
160
  end
166
161
 
@@ -173,10 +168,9 @@ describe 'List Command' do
173
168
 
174
169
  describe 'Post Mortem' do
175
170
  it 'must work in post-mortem mode' do
176
- enter 'cont', 'list'
171
+ enter 'cont'
177
172
  debug_file 'post_mortem'
178
- check_output_includes "[7, 9] in #{fullpath('post_mortem')}"
173
+ check_output_includes "[3, 12] in #{fullpath('post_mortem')}"
179
174
  end
180
175
  end
181
-
182
176
  end
@@ -3,9 +3,7 @@ require_relative 'test_helper'
3
3
  describe 'Method Command' do
4
4
  include TestDsl
5
5
 
6
- def after_setup
7
- Byebug::Command.settings[:autolist] = 0
8
- end
6
+ temporary_change_hash Byebug::Command.settings, :autolist, 0
9
7
 
10
8
  describe 'show instance method of a class' do
11
9
  it 'must show using full command name' do
@@ -4,7 +4,7 @@ describe 'Reload Command' do
4
4
  include TestDsl
5
5
 
6
6
  describe 'autoreloading' do
7
- after { Byebug::Command.settings[:reload_source_on_change] = true }
7
+ after { Byebug::Command.settings[:autoreload] = true }
8
8
 
9
9
  it 'must notify that automatic reloading is on by default' do
10
10
  enter 'reload'
@@ -29,7 +29,7 @@ describe 'Reload Command' do
29
29
  'reload'
30
30
  end, 'l 4-4'
31
31
  debug_file 'reload'
32
- check_output_includes '4 100'
32
+ check_output_includes '4: 100'
33
33
  end
34
34
  end
35
35
 
@@ -42,7 +42,7 @@ describe 'Reload Command' do
42
42
  'reload'
43
43
  end, 'l 7-7'
44
44
  debug_file 'post_mortem'
45
- check_output_includes '7 z = 100'
45
+ check_output_includes '7: z = 100'
46
46
  end
47
47
  end
48
48
 
@@ -0,0 +1,112 @@
1
+ require_relative 'test_helper'
2
+
3
+ describe 'Repl commands' do
4
+ include TestDsl
5
+
6
+ describe 'Irb Command' do
7
+ before do
8
+ interface.stubs(:kind_of?).with(Byebug::LocalInterface).returns(true)
9
+ IRB::Irb.stubs(:new).returns(irb)
10
+ end
11
+
12
+ let(:irb) { stub(context: ->{}) }
13
+
14
+ it 'must support next command' do
15
+ irb.stubs(:eval_input).throws(:IRB_EXIT, :next)
16
+ enter 'irb'
17
+ debug_file('irb') { state.line.must_equal 3 }
18
+ end
19
+
20
+ it 'must support step command' do
21
+ irb.stubs(:eval_input).throws(:IRB_EXIT, :step)
22
+ enter 'irb'
23
+ debug_file('irb') { state.line.must_equal 3 }
24
+ end
25
+
26
+ it 'must support cont command' do
27
+ irb.stubs(:eval_input).throws(:IRB_EXIT, :cont)
28
+ enter 'break 4', 'irb'
29
+ debug_file('irb') { state.line.must_equal 4 }
30
+ end
31
+
32
+ describe 'autoirb' do
33
+ it 'must call irb automatically after breakpoint' do
34
+ irb.expects(:eval_input)
35
+ enter 'set autoirb', 'break 4', 'cont', 'set noautoirb'
36
+ debug_file 'irb'
37
+ end
38
+ end
39
+
40
+ describe 'setting context to $byebug_state' do
41
+ temporary_change_hash Byebug::Command.settings, :testing, false
42
+
43
+ it 'must set $byebug_state if irb is in the debug mode' do
44
+ byebug_state = nil
45
+ irb.stubs(:eval_input).calls { byebug_state = $byebug_state }
46
+ enter 'irb -d'
47
+ debug_file 'irb'
48
+ byebug_state.must_be_kind_of Byebug::CommandProcessor::State
49
+ end
50
+
51
+ it 'must not set $byebug_state if irb is not in the debug mode' do
52
+ byebug_state = nil
53
+ irb.stubs(:eval_input).calls { byebug_state = $byebug_state }
54
+ enter 'irb'
55
+ debug_file 'irb'
56
+ byebug_state.must_be_nil
57
+ end
58
+ end
59
+
60
+ describe 'Post Mortem' do
61
+ it 'must work in post-mortem mode' do
62
+ irb.stubs(:eval_input).throws(:IRB_EXIT, :cont)
63
+ enter 'cont', 'break 12', 'irb'
64
+ debug_file('post_mortem') { state.line.must_equal 12 }
65
+ end
66
+ end
67
+ end
68
+
69
+ @has_pry = false
70
+ describe 'Pry command' do
71
+ before do
72
+ interface.stubs(:kind_of?).with(Byebug::LocalInterface).returns(true)
73
+ Byebug::PryCommand.any_instance.expects(:pry)
74
+ end
75
+
76
+ it 'must support step command' do
77
+ skip 'TODO'
78
+ end
79
+
80
+ it 'must support cont command' do
81
+ skip 'TODO'
82
+ end
83
+
84
+ describe 'autopry' do
85
+ it 'must call pry automatically after breakpoint' do
86
+ skip 'TODO'
87
+ end
88
+ end
89
+
90
+ describe 'setting context to $byebug_state' do
91
+ temporary_change_hash Byebug::Command.settings, :testing, false
92
+
93
+ it 'must set $byebug_state if irb is in the debug mode' do
94
+ enter 'pry -d'
95
+ debug_file 'irb'
96
+ $byebug_state.must_be_kind_of Byebug::CommandProcessor::State
97
+ end
98
+
99
+ it 'must not set $byebug_state if irb is not in the debug mode' do
100
+ enter 'pry'
101
+ debug_file 'pry'
102
+ $byebug_state.must_be_nil
103
+ end
104
+ end
105
+
106
+ describe 'Post Mortem' do
107
+ it 'must work in post-mortem mode' do
108
+ skip 'TODO'
109
+ end
110
+ end
111
+ end if @has_pry
112
+ end