byebug 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/GUIDE.md +2 -2
  4. data/LICENSE +3 -3
  5. data/README.md +5 -4
  6. data/byebug.gemspec +1 -1
  7. data/ext/byebug/byebug.c +20 -19
  8. data/lib/byebug.rb +2 -53
  9. data/lib/byebug/command.rb +9 -109
  10. data/lib/byebug/commands/breakpoints.rb +1 -1
  11. data/lib/byebug/commands/control.rb +20 -21
  12. data/lib/byebug/commands/display.rb +2 -3
  13. data/lib/byebug/commands/eval.rb +6 -16
  14. data/lib/byebug/commands/finish.rb +1 -1
  15. data/lib/byebug/commands/frame.rb +9 -9
  16. data/lib/byebug/commands/help.rb +2 -3
  17. data/lib/byebug/commands/history.rb +28 -0
  18. data/lib/byebug/commands/info.rb +3 -3
  19. data/lib/byebug/commands/list.rb +2 -13
  20. data/lib/byebug/commands/method.rb +5 -45
  21. data/lib/byebug/commands/reload.rb +1 -12
  22. data/lib/byebug/commands/repl.rb +6 -15
  23. data/lib/byebug/commands/save.rb +2 -7
  24. data/lib/byebug/commands/set.rb +45 -116
  25. data/lib/byebug/commands/show.rb +22 -126
  26. data/lib/byebug/commands/stepping.rb +1 -1
  27. data/lib/byebug/commands/trace.rb +14 -25
  28. data/lib/byebug/commands/variables.rb +3 -41
  29. data/lib/byebug/helper.rb +11 -42
  30. data/lib/byebug/history.rb +5 -13
  31. data/lib/byebug/processors/command_processor.rb +6 -6
  32. data/lib/byebug/setting.rb +82 -0
  33. data/lib/byebug/settings/autoeval.rb +20 -0
  34. data/lib/byebug/settings/autoirb.rb +19 -0
  35. data/lib/byebug/settings/autolist.rb +19 -0
  36. data/lib/byebug/settings/autoreload.rb +11 -0
  37. data/lib/byebug/settings/autosave.rb +11 -0
  38. data/lib/byebug/settings/basename.rb +7 -0
  39. data/lib/byebug/settings/callstyle.rb +15 -0
  40. data/lib/byebug/settings/forcestep.rb +11 -0
  41. data/lib/byebug/settings/fullpath.rb +11 -0
  42. data/lib/byebug/settings/histfile.rb +16 -0
  43. data/lib/byebug/settings/histsize.rb +18 -0
  44. data/lib/byebug/settings/linetrace.rb +15 -0
  45. data/lib/byebug/settings/listsize.rb +15 -0
  46. data/lib/byebug/settings/post_mortem.rb +15 -0
  47. data/lib/byebug/settings/stack_on_error.rb +7 -0
  48. data/lib/byebug/settings/testing.rb +7 -0
  49. data/lib/byebug/settings/tracing_plus.rb +7 -0
  50. data/lib/byebug/settings/verbose.rb +7 -0
  51. data/lib/byebug/settings/width.rb +29 -0
  52. data/lib/byebug/version.rb +1 -1
  53. data/test/breakpoints_test.rb +345 -324
  54. data/test/conditions_test.rb +61 -48
  55. data/test/continue_test.rb +38 -27
  56. data/test/debugger_alias_test.rb +5 -3
  57. data/test/display_test.rb +103 -92
  58. data/test/edit_test.rb +42 -34
  59. data/test/eval_test.rb +91 -75
  60. data/test/finish_test.rb +51 -40
  61. data/test/frame_test.rb +197 -184
  62. data/test/help_test.rb +47 -38
  63. data/test/history_test.rb +54 -0
  64. data/test/info_test.rb +306 -293
  65. data/test/interrupt_test.rb +44 -38
  66. data/test/kill_test.rb +40 -31
  67. data/test/list_test.rb +166 -133
  68. data/test/method_test.rb +67 -60
  69. data/test/post_mortem_test.rb +56 -48
  70. data/test/quit_test.rb +44 -35
  71. data/test/reload_test.rb +36 -24
  72. data/test/repl_test.rb +57 -47
  73. data/test/restart_test.rb +56 -69
  74. data/test/save_test.rb +62 -53
  75. data/test/set_test.rb +140 -118
  76. data/test/show_test.rb +68 -201
  77. data/test/source_test.rb +39 -29
  78. data/test/stepping_test.rb +163 -136
  79. data/test/support/test_dsl.rb +9 -11
  80. data/test/test_helper.rb +2 -7
  81. data/test/thread_test.rb +121 -107
  82. data/test/trace_test.rb +86 -83
  83. data/test/variables_test.rb +104 -98
  84. metadata +27 -86
  85. data/test/examples/breakpoint.rb +0 -6
  86. data/test/examples/breakpoint_deep.rb +0 -4
  87. data/test/examples/conditions.rb +0 -4
  88. data/test/examples/continue.rb +0 -5
  89. data/test/examples/display.rb +0 -5
  90. data/test/examples/edit.rb +0 -4
  91. data/test/examples/eval.rb +0 -4
  92. data/test/examples/finish.rb +0 -3
  93. data/test/examples/frame.rb +0 -4
  94. data/test/examples/frame_deep.rb +0 -1
  95. data/test/examples/gcd.rb +0 -15
  96. data/test/examples/hanoi.rb +0 -34
  97. data/test/examples/help.rb +0 -1
  98. data/test/examples/info.rb +0 -6
  99. data/test/examples/info2.rb +0 -3
  100. data/test/examples/interrupt.rb +0 -8
  101. data/test/examples/kill.rb +0 -2
  102. data/test/examples/list.rb +0 -23
  103. data/test/examples/method.rb +0 -4
  104. data/test/examples/post_mortem.rb +0 -4
  105. data/test/examples/primes.rb +0 -25
  106. data/test/examples/quit.rb +0 -2
  107. data/test/examples/reload.rb +0 -6
  108. data/test/examples/repl.rb +0 -6
  109. data/test/examples/restart.rb +0 -6
  110. data/test/examples/save.rb +0 -3
  111. data/test/examples/set.rb +0 -3
  112. data/test/examples/settings.rb +0 -1
  113. data/test/examples/show.rb +0 -1
  114. data/test/examples/source.rb +0 -3
  115. data/test/examples/stepping.rb +0 -8
  116. data/test/examples/stepping_raise_from_c_method.rb +0 -3
  117. data/test/examples/stepping_raise_from_ruby_method.rb +0 -3
  118. data/test/examples/test-triangle.rb +0 -14
  119. data/test/examples/thread.rb +0 -5
  120. data/test/examples/tmate.rb +0 -10
  121. data/test/examples/trace.rb +0 -8
  122. data/test/examples/tri3.rb +0 -6
  123. data/test/examples/triangle.rb +0 -13
  124. data/test/examples/variables.rb +0 -4
  125. data/test/timeout_test.rb +0 -9
@@ -1,50 +1,59 @@
1
- class TestHelp < TestDsl::TestCase
2
- include Columnize
1
+ module HelpTest
2
+ class HelpTestCase < TestDsl::TestCase
3
+ include Columnize
3
4
 
4
- let(:available_commands) {
5
- Byebug::Command.commands.map(&:names).flatten.uniq.sort }
6
-
7
- describe 'when typed alone' do
8
- temporary_change_hash Byebug.settings, :width, 50
9
-
10
- it 'must show self help when typed alone' do
11
- enter 'help'
12
- debug_file 'help'
13
- check_output_includes \
14
- 'Type "help <command-name>" for help on a specific command',
15
- 'Available commands:', columnize(available_commands, 50)
5
+ before do
6
+ @example = -> do
7
+ byebug
8
+ end
16
9
  end
17
10
 
18
- it 'must work when shortcut used' do
19
- enter 'h'
20
- debug_file 'help'
21
- check_output_includes \
22
- 'Type "help <command-name>" for help on a specific command'
11
+ let(:available_cmds) do
12
+ Byebug::Command.commands.map(&:names).flatten.uniq.sort
23
13
  end
24
- end
25
14
 
26
- describe 'when typed with a command' do
27
- it 'must show an error if an undefined command is specified' do
28
- enter 'help foobar'
29
- debug_file 'help'
30
- check_error_includes 'Undefined command: "foobar". Try "help".'
15
+ describe 'when typed alone' do
16
+ temporary_change_hash Byebug::Setting, :width, 50
17
+
18
+ it 'must show self help when typed alone' do
19
+ enter 'help'
20
+ debug_proc(@example)
21
+ check_output_includes \
22
+ 'Type "help <command-name>" for help on a specific command',
23
+ 'Available commands:', columnize(available_cmds, 50)
24
+ end
25
+
26
+ it 'must work when shortcut used' do
27
+ enter 'h'
28
+ debug_proc(@example)
29
+ check_output_includes \
30
+ 'Type "help <command-name>" for help on a specific command'
31
+ end
31
32
  end
32
33
 
33
- it "must show a command's help" do
34
- enter 'help break'
35
- debug_file 'help'
36
- check_output_includes \
37
- "b[reak] file:line [if expr]\n" \
38
- "b[reak] class(.|#)method [if expr]\n\n" \
39
- "Set breakpoint to some position, (optionally) if expr == true\n"
34
+ describe 'when typed with a command' do
35
+ it 'must show an error if an undefined command is specified' do
36
+ enter 'help foobar'
37
+ debug_proc(@example)
38
+ check_error_includes 'Undefined command: "foobar". Try "help".'
39
+ end
40
+
41
+ it "must show a command's help" do
42
+ enter 'help break'
43
+ debug_proc(@example)
44
+ check_output_includes \
45
+ "b[reak] file:line [if expr]\n" \
46
+ "b[reak] class(.|#)method [if expr]\n\n" \
47
+ "Set breakpoint to some position, (optionally) if expr == true\n"
48
+ end
40
49
  end
41
- end
42
50
 
43
- describe 'when typed with command and subcommand' do
44
- it "must show subcommand's help" do
45
- enter 'help info breakpoints'
46
- debug_file 'help'
47
- check_output_includes "Status of user-settable breakpoints.\n"
51
+ describe 'when typed with command and subcommand' do
52
+ it "must show subcommand's help" do
53
+ enter 'help info breakpoints'
54
+ debug_proc(@example)
55
+ check_output_includes "Status of user-settable breakpoints.\n"
56
+ end
48
57
  end
49
58
  end
50
59
  end
@@ -0,0 +1,54 @@
1
+ module HistoryTest
2
+ class HistoryTestCase < TestDsl::TestCase
3
+ before do
4
+ @example = -> do
5
+ byebug
6
+ end
7
+ end
8
+
9
+ describe 'history command' do
10
+ temporary_change_const Readline, 'HISTORY', %w(aaa bbb ccc ddd)
11
+
12
+ describe 'with autosave disabled' do
13
+ temporary_change_hash Byebug::Setting, :autosave, false
14
+
15
+ it 'must not show records from readline' do
16
+ enter 'history'
17
+ debug_proc(@example)
18
+ check_error_includes "Not currently saving history. " \
19
+ 'Enable it with "set autosave"'
20
+ end
21
+ end
22
+
23
+ describe 'with autosave enabled' do
24
+ temporary_change_hash Byebug::Setting, :autosave, true
25
+
26
+ describe 'must show records from readline' do
27
+ it 'displays last max_size records from readline history' do
28
+ enter 'set histsize 3', 'history'
29
+ debug_proc(@example)
30
+ check_output_includes(/2 bbb\n 3 ccc\n 4 ddd/)
31
+ check_output_doesnt_include(/1 aaa/)
32
+ end
33
+ end
34
+
35
+ describe 'max records' do
36
+ it 'displays whole history if max_size is bigger than Readline::HISTORY' do
37
+ enter 'set histsize 7', 'history'
38
+ debug_proc(@example)
39
+ check_output_includes(/1 aaa\n 2 bbb\n 3 ccc\n 4 ddd/)
40
+ end
41
+ end
42
+
43
+ describe 'with specified size' do
44
+ it 'displays the specified number of entries most recent first' do
45
+ enter 'history 2'
46
+ debug_proc(@example)
47
+ check_output_includes(/3 ccc\n 4 ddd/)
48
+ check_output_doesnt_include(/1 aaa\n 2 bbb/)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -1,307 +1,320 @@
1
- class InfoExample
2
- def initialize
3
- @foo = "bar"
4
- @bla = "blabla"
5
- end
6
-
7
- def a(y, z)
8
- w = "1" * 30
9
- x = 2
10
- w + x.to_s + y + z + @foo
11
- end
12
-
13
- def c
14
- a = BasicObject.new
15
- a
16
- end
17
-
18
- def b
19
- a('a', 'b')
20
- e = "%.2f"
21
- e
22
- end
23
-
24
- def d
25
- raise "bang"
26
- rescue
27
- end
28
- end
29
-
30
- class TestInfo < TestDsl::TestCase
31
- include Columnize
32
-
33
- describe 'Args info' do
34
- it 'must show info about all args' do
35
- enter "break #{__FILE__}:10", 'cont', 'info args'
36
- debug_file 'info'
37
- check_output_includes 'y = "a"', 'z = "b"'
38
- end
39
- end
40
-
41
- describe 'Breakpoints info' do
42
- it 'must show info about all breakpoints' do
43
- enter 'break 4', 'break 5 if y == z', 'info breakpoints'
44
- debug_file 'info'
45
- check_output_includes 'Num Enb What',
46
- /\d+ +y at #{fullpath('info')}:4/,
47
- /\d+ +y at #{fullpath('info')}:5 if y == z/
48
- end
49
-
50
- it 'must show info about specific breakpoint' do
51
- enter 'break 4', 'break 5',
52
- ->{ "info breakpoints #{Byebug.breakpoints.first.id}" }
53
- debug_file 'info'
54
- check_output_includes 'Num Enb What', /\d+ +y at #{fullpath('info')}:4/
55
- check_output_doesnt_include(/\d+ +y at #{fullpath('info')}:5/)
56
- end
57
-
58
- it 'must show an error if no breakpoints are found' do
59
- enter 'info breakpoints'
60
- debug_file 'info'
61
- check_output_includes 'No breakpoints.'
62
- end
63
-
64
- it 'must show an error if no breakpoints are found' do
65
- enter 'break 4', 'info breakpoints 123'
66
- debug_file 'info'
67
- check_error_includes 'No breakpoints found among list given.'
68
- end
69
-
70
- it 'must show hit count' do
71
- enter 'break 5', 'cont', 'info breakpoints'
72
- debug_file 'info'
73
- check_output_includes(
74
- /\d+ +y at #{fullpath('info')}:5/, 'breakpoint already hit 1 time')
75
- end
76
- end
77
-
78
- describe 'Display info' do
79
- it 'must show all display expressions' do
80
- enter 'display 3 + 3', 'display a + b', 'info display'
81
- debug_file 'info'
82
- check_output_includes "Auto-display expressions now in effect:\n" \
83
- 'Num Enb Expression',
84
- '1: y 3 + 3',
85
- '2: y a + b'
86
- end
87
-
88
- it 'must show a message if there are no display expressions created' do
89
- enter 'info display'
90
- debug_file 'info'
91
- check_output_includes 'There are no auto-display expressions now.'
92
- end
93
- end
94
-
95
- describe 'Files info' do
96
- let(:files) { SCRIPT_LINES__.keys.uniq.sort }
97
-
98
- it 'must show all files read in' do
99
- enter 'info files'
100
- debug_file 'info'
101
- check_output_includes files.map { |f| "File #{f}" }
102
- end
103
-
104
- it 'must show all files read in using "info file" too' do
105
- enter 'info file'
106
- debug_file 'info'
107
- check_output_includes files.map { |f| "File #{f}" }
108
- end
109
-
110
- it 'must show explicitly loaded files' do
111
- enter 'info files stat'
112
- debug_file 'info'
113
- check_output_includes "File #{fullpath('info')}",
114
- LineCache.stat(fullpath('info')).mtime.to_s
115
- end
116
- end
117
-
118
- describe 'File info' do
119
- let(:file) { fullpath('info') }
120
- let(:filename) { "File #{file}" }
121
- let(:lines) { "#{LineCache.size(file)} lines" }
122
- let(:mtime) { LineCache.stat(file).mtime.to_s }
123
- let(:sha1) { LineCache.sha1(file) }
124
- let(:breakpoint_line_numbers) {
125
- columnize(LineCache.trace_line_numbers(file).to_a.sort,
126
- Byebug.settings[:width]) }
127
-
128
- it 'must show basic info about the file' do
129
- enter "info file #{file} basic"
130
- debug_file 'info'
131
- check_output_includes filename, lines
132
- check_output_doesnt_include breakpoint_line_numbers, mtime, sha1
133
- end
134
-
135
- it 'must show number of lines' do
136
- enter "info file #{file} lines"
137
- debug_file 'info'
138
- check_output_includes filename, lines
139
- check_output_doesnt_include breakpoint_line_numbers, mtime, sha1
1
+ module InfoTest
2
+ class Example
3
+ def initialize
4
+ @foo = 'bar'
5
+ @bla = 'blabla'
140
6
  end
141
7
 
142
- it 'must show mtime of the file' do
143
- enter "info file #{file} mtime"
144
- debug_file 'info'
145
- check_output_includes filename, mtime
146
- check_output_doesnt_include lines, breakpoint_line_numbers, sha1
8
+ def a(y, z)
9
+ w = '1' * 30
10
+ x = 2
11
+ w + x.to_s + y + z + @foo
147
12
  end
148
13
 
149
- it 'must show sha1 of the file' do
150
- enter "info file #{file} sha1"
151
- debug_file 'info'
152
- check_output_includes filename, sha1
153
- check_output_doesnt_include lines, breakpoint_line_numbers, mtime
154
- end
155
-
156
- it 'must show breakpoints in the file' do
157
- enter 'break 4', 'break 5', "info file #{file} breakpoints"
158
- debug_file 'info'
159
- check_output_includes(/Created breakpoint \d+ at #{file}:4/,
160
- /Created breakpoint \d+ at #{file}:5/,
161
- filename,
162
- 'breakpoint line numbers:', breakpoint_line_numbers)
163
- check_output_doesnt_include lines, mtime, sha1
164
- end
165
-
166
- it 'must show all info about the file' do
167
- enter "info file #{file} all"
168
- debug_file 'info'
169
- check_output_includes \
170
- filename, lines, breakpoint_line_numbers, mtime, sha1
171
- end
172
-
173
- it 'must not show any info if the parameter is invalid' do
174
- enter "info file #{file} blabla"
175
- debug_file 'info'
176
- check_error_includes 'Invalid parameter blabla'
177
- end
178
- end
179
-
180
- describe 'Instance variables info' do
181
- it 'must show instance variables' do
182
- enter "break #{__FILE__}:10", 'cont', 'info instance_variables'
183
- debug_file 'info'
184
- check_output_includes '@bla = "blabla"', '@foo = "bar"'
185
- end
186
- end
187
-
188
- describe 'Line info' do
189
- it 'must show the current line' do
190
- enter "break #{__FILE__}:10", 'cont', 'info line'
191
- debug_file 'info'
192
- check_output_includes "Line 10 of \"#{__FILE__}\""
193
- end
194
- end
195
-
196
- describe 'Locals info' do
197
- temporary_change_hash Byebug.settings, :width, 28
198
-
199
- it 'must show the current local variables' do
200
- enter "break #{__FILE__}:10", 'cont', 'info locals'
201
- debug_file 'info'
202
- check_output_includes 'w = "11111111111111111111...', 'x = 2'
203
- end
204
-
205
- it 'must fail if local variable doesn\'t respond to #to_s or to #inspect' do
206
- enter "break #{__FILE__}:15", 'cont', 'info locals'
207
- debug_file 'info'
208
- check_output_includes 'a = *Error in evaluation*'
209
- end
210
- end
211
-
212
- describe 'Program info' do
213
- it 'must show the initial stop reason' do
214
- enter 'info program'
215
- debug_file 'info'
216
- check_output_includes \
217
- 'It stopped after stepping, next\'ing or initial start.'
218
- end
219
-
220
- it 'must show the step stop reason' do
221
- enter 'step', 'info program'
222
- debug_file 'info'
223
- check_output_includes \
224
- 'Program stopped.',
225
- 'It stopped after stepping, next\'ing or initial start.'
226
- end
227
-
228
- it 'must show the breakpoint stop reason' do
229
- enter 'break 4', 'cont', 'info program'
230
- debug_file 'info'
231
- check_output_includes 'Program stopped.', 'It stopped at a breakpoint.'
232
- end
233
-
234
- it 'must show the catchpoint stop reason' do
235
- enter 'catch Exception', 'cont', 'info program'
236
- debug_file 'info'
237
- check_output_includes 'Program stopped.', 'It stopped at a catchpoint.'
238
- end
239
-
240
- it 'must show the unknown stop reason' do
241
- enter 'break 5', 'cont',
242
- ->{ context.stubs(:stop_reason).returns('blabla'); 'info program' }
243
- debug_file 'info'
244
- check_output_includes 'Program stopped.', 'unknown reason: blabla'
245
- end
246
-
247
- it 'must show an error if the program is crashed' do
248
- skip('TODO')
249
- end
250
- end
251
-
252
- describe 'Stack info' do
253
- it 'must show stack info' do
254
- enter 'set fullpath', "break #{__FILE__}:8", 'cont', 'info stack'
255
- debug_file 'info'
256
- check_output_includes(
257
- /--> #0 InfoExample.a\(y\#String, z\#String\)\s+at #{__FILE__}:8/,
258
- /#1 InfoExample.b\s+at #{__FILE__}:19/,
259
- /#2 <top \(required\)>\s+at #{fullpath('info')}:4/)
260
- end
261
- end
262
-
263
- describe 'Global Variables info' do
264
- it 'must show global variables' do
265
- enter 'info global_variables'
266
- debug_file 'info'
267
- check_output_includes "$$ = #{Process.pid}"
268
- end
269
- end
270
-
271
- describe 'Variables info' do
272
- temporary_change_hash Byebug.settings, :width, 30
273
-
274
- it 'must show all variables' do
275
- enter "break #{__FILE__}:10", 'cont', 'info variables'
276
- debug_file 'info'
277
- check_output_includes(/self = #<InfoExample:\S+.../,
278
- 'w = "1111111111111111111111...',
279
- 'x = 2',
280
- '@bla = "blabla"',
281
- '@foo = "bar"')
14
+ def c
15
+ a = BasicObject.new
16
+ a
282
17
  end
283
18
 
284
- it 'must fail if the variable doesn\'t respond to #to_s or to #inspect' do
285
- enter "break #{__FILE__}:15", 'cont', 'info variables'
286
- debug_file 'info'
287
- check_output_includes 'a = *Error in evaluation*',
288
- /self = #<InfoExample:\S+.../,
289
- '@bla = "blabla"',
290
- '@foo = "bar"'
19
+ def b
20
+ a('a', 'b')
21
+ e = "%.2f"
22
+ e
291
23
  end
292
24
 
293
- it 'must correctly print variables containing % sign' do
294
- enter "break #{__FILE__}:21", 'cont', 'info variables'
295
- debug_file 'info'
296
- check_output_includes 'e = "%.2f"'
25
+ def d
26
+ raise 'bang'
27
+ rescue
297
28
  end
298
29
  end
299
30
 
300
- describe 'Help' do
301
- it 'must show help when typing just "info"' do
302
- enter 'info', 'cont'
303
- debug_file 'info'
304
- check_output_includes(/List of "info" subcommands:/)
31
+ class InfoTestCase < TestDsl::TestCase
32
+ include Columnize
33
+
34
+ before do
35
+ @example = -> do
36
+ byebug
37
+ i = Example.new
38
+ i.b
39
+ i.c
40
+ i.d
41
+ end
42
+ end
43
+
44
+ describe 'Args info' do
45
+ it 'must show info about all args' do
46
+ enter 'break 11', 'cont', 'info args'
47
+ debug_proc(@example)
48
+ check_output_includes 'y = "a"', 'z = "b"'
49
+ end
50
+ end
51
+
52
+ describe 'Breakpoints info' do
53
+ it 'must show info about all breakpoints' do
54
+ enter 'break 38', 'break 39 if y == z', 'info breakpoints'
55
+ debug_proc(@example)
56
+ check_output_includes 'Num Enb What',
57
+ /\d+ +y at #{__FILE__}:38/,
58
+ /\d+ +y at #{__FILE__}:39 if y == z/
59
+ end
60
+
61
+ it 'must show info about specific breakpoint' do
62
+ enter 'break 38', 'break 39',
63
+ -> { "info breakpoints #{Byebug.breakpoints.first.id}" }
64
+ debug_proc(@example)
65
+ check_output_includes 'Num Enb What', /\d+ +y at #{__FILE__}:38/
66
+ check_output_doesnt_include(/\d+ +y at #{__FILE__}:39/)
67
+ end
68
+
69
+ it 'must show an error if no breakpoints are found' do
70
+ enter 'info breakpoints'
71
+ debug_proc(@example)
72
+ check_output_includes 'No breakpoints.'
73
+ end
74
+
75
+ it 'must show an error if no breakpoints are found' do
76
+ enter 'break 38', 'info breakpoints 100'
77
+ debug_proc(@example)
78
+ check_error_includes 'No breakpoints found among list given.'
79
+ end
80
+
81
+ it 'must show hit count' do
82
+ enter 'break 39', 'cont', 'info breakpoints'
83
+ debug_proc(@example)
84
+ check_output_includes(
85
+ /\d+ +y at #{__FILE__}:39/, 'breakpoint already hit 1 time')
86
+ end
87
+ end
88
+
89
+ describe 'Display info' do
90
+ it 'must show all display expressions' do
91
+ enter 'display 3 + 3', 'display a + b', 'info display'
92
+ debug_proc(@example)
93
+ check_output_includes "Auto-display expressions now in effect:\n" \
94
+ 'Num Enb Expression',
95
+ '1: y 3 + 3',
96
+ '2: y a + b'
97
+ end
98
+
99
+ it 'must show a message if there are no display expressions created' do
100
+ enter 'info display'
101
+ debug_proc(@example)
102
+ check_output_includes 'There are no auto-display expressions now.'
103
+ end
104
+ end
105
+
106
+ describe 'Files info' do
107
+ let(:files) { SCRIPT_LINES__.keys.uniq.sort }
108
+
109
+ it 'must show all files read in' do
110
+ enter 'info files'
111
+ debug_proc(@example)
112
+ check_output_includes files.map { |f| "File #{f}" }
113
+ end
114
+
115
+ it 'must show all files read in using "info file" too' do
116
+ enter 'info file'
117
+ debug_proc(@example)
118
+ check_output_includes files.map { |f| "File #{f}" }
119
+ end
120
+
121
+ it 'must show explicitly loaded files' do
122
+ enter 'info files stat'
123
+ debug_proc(@example)
124
+ check_output_includes "File #{__FILE__}",
125
+ LineCache.stat(__FILE__).mtime.to_s
126
+ end
127
+ end
128
+
129
+ describe 'File info' do
130
+ let(:file) { __FILE__ }
131
+ let(:filename) { "File #{file}" }
132
+ let(:lines) { "#{LineCache.size(file)} lines" }
133
+ let(:mtime) { LineCache.stat(file).mtime.to_s }
134
+ let(:sha1) { LineCache.sha1(file) }
135
+ let(:breakpoint_line_numbers) {
136
+ columnize(LineCache.trace_line_numbers(file).to_a.sort,
137
+ Byebug::Setting[:width]) }
138
+
139
+ it 'must show basic info about the file' do
140
+ enter "info file #{file} basic"
141
+ debug_proc(@example)
142
+ check_output_includes filename, lines
143
+ check_output_doesnt_include breakpoint_line_numbers, mtime, sha1
144
+ end
145
+
146
+ it 'must show number of lines' do
147
+ enter "info file #{file} lines"
148
+ debug_proc(@example)
149
+ check_output_includes filename, lines
150
+ check_output_doesnt_include breakpoint_line_numbers, mtime, sha1
151
+ end
152
+
153
+ it 'must show mtime of the file' do
154
+ enter "info file #{file} mtime"
155
+ debug_proc(@example)
156
+ check_output_includes filename, mtime
157
+ check_output_doesnt_include lines, breakpoint_line_numbers, sha1
158
+ end
159
+
160
+ it 'must show sha1 of the file' do
161
+ enter "info file #{file} sha1"
162
+ debug_proc(@example)
163
+ check_output_includes filename, sha1
164
+ check_output_doesnt_include lines, breakpoint_line_numbers, mtime
165
+ end
166
+
167
+ it 'must show breakpoints in the file' do
168
+ enter 'break 38', 'break 39', "info file #{file} breakpoints"
169
+ debug_proc(@example)
170
+ check_output_includes(/Created breakpoint \d+ at #{file}:38/,
171
+ /Created breakpoint \d+ at #{file}:39/,
172
+ filename,
173
+ 'breakpoint line numbers:', breakpoint_line_numbers)
174
+ check_output_doesnt_include lines, mtime, sha1
175
+ end
176
+
177
+ it 'must show all info about the file' do
178
+ enter "info file #{file} all"
179
+ debug_proc(@example)
180
+ check_output_includes \
181
+ filename, lines, breakpoint_line_numbers, mtime, sha1
182
+ end
183
+
184
+ it 'must not show any info if the parameter is invalid' do
185
+ enter "info file #{file} blabla"
186
+ debug_proc(@example)
187
+ check_error_includes 'Invalid parameter blabla'
188
+ end
189
+ end
190
+
191
+ describe 'Instance variables info' do
192
+ it 'must show instance variables' do
193
+ enter 'break 11', 'cont', 'info instance_variables'
194
+ debug_proc(@example)
195
+ check_output_includes '@bla = "blabla"', '@foo = "bar"'
196
+ end
197
+ end
198
+
199
+ describe 'Line info' do
200
+ it 'must show the current line' do
201
+ enter 'break 11', 'cont', 'info line'
202
+ debug_proc(@example)
203
+ check_output_includes "Line 11 of \"#{__FILE__}\""
204
+ end
205
+ end
206
+
207
+ describe 'Locals info' do
208
+ temporary_change_hash Byebug::Setting, :width, 28
209
+
210
+ it 'must show the current local variables' do
211
+ enter 'break 11', 'cont', 'info locals'
212
+ debug_proc(@example)
213
+ check_output_includes 'w = "11111111111111111111...', 'x = 2'
214
+ end
215
+
216
+ it 'must fail if local variable doesn\'t respond to #to_s or to #inspect' do
217
+ enter 'break 16', 'cont', 'info locals'
218
+ debug_proc(@example)
219
+ check_output_includes 'a = *Error in evaluation*'
220
+ end
221
+ end
222
+
223
+ describe 'Program info' do
224
+ it 'must show the initial stop reason' do
225
+ enter 'info program'
226
+ debug_proc(@example)
227
+ check_output_includes \
228
+ "It stopped after stepping, next'ing or initial start."
229
+ end
230
+
231
+ it 'must show the step stop reason' do
232
+ enter 'step', 'info program'
233
+ debug_proc(@example)
234
+ check_output_includes \
235
+ 'Program stopped.',
236
+ "It stopped after stepping, next'ing or initial start."
237
+ end
238
+
239
+ it 'must show the breakpoint stop reason' do
240
+ enter 'break 38', 'cont', 'info program'
241
+ debug_proc(@example)
242
+ check_output_includes 'Program stopped.', 'It stopped at a breakpoint.'
243
+ end
244
+
245
+ it 'must show the catchpoint stop reason' do
246
+ enter 'catch Exception', 'cont', 'info program'
247
+ debug_proc(@example)
248
+ check_output_includes 'Program stopped.', 'It stopped at a catchpoint.'
249
+ end
250
+
251
+ it 'must show the unknown stop reason' do
252
+ enter 'break 39', 'cont',
253
+ ->{ context.stubs(:stop_reason).returns('blabla'); 'info program' }
254
+ debug_proc(@example)
255
+ check_output_includes 'Program stopped.', 'unknown reason: blabla'
256
+ end
257
+
258
+ it 'must show an error if the program is crashed' do
259
+ skip('TODO')
260
+ end
261
+ end
262
+
263
+ describe 'Stack info' do
264
+ it 'must show stack info' do
265
+ file = __FILE__
266
+ enter 'set fullpath', 'break 9', 'cont', 'info stack'
267
+ debug_proc(@example)
268
+ check_output_includes(
269
+ /--> #0 InfoTest::Example.a\(y#String, z#String\)\s+at #{file}:9/,
270
+ /#1 InfoTest::Example.b\s+at #{file}:20/,
271
+ /#2 block \(2 levels\) in <class:InfoTestCase>\s+at #{file}:38/)
272
+ end
273
+ end
274
+
275
+ describe 'Global Variables info' do
276
+ it 'must show global variables' do
277
+ enter 'info global_variables'
278
+ debug_proc(@example)
279
+ check_output_includes "$$ = #{Process.pid}"
280
+ end
281
+ end
282
+
283
+ describe 'Variables info' do
284
+ temporary_change_hash Byebug::Setting, :width, 30
285
+
286
+ it 'must show all variables' do
287
+ enter 'break 11', 'cont', 'info variables'
288
+ debug_proc(@example)
289
+ check_output_includes(/self = #<InfoTest::Example:\S*.../,
290
+ 'w = "1111111111111111111111...',
291
+ 'x = 2',
292
+ '@bla = "blabla"',
293
+ '@foo = "bar"')
294
+ end
295
+
296
+ it 'must fail if the variable doesn\'t respond to #to_s or to #inspect' do
297
+ enter 'break 16', 'cont', 'info variables'
298
+ debug_proc(@example)
299
+ check_output_includes 'a = *Error in evaluation*',
300
+ /self = #<InfoTest::Example:\S*.../,
301
+ '@bla = "blabla"',
302
+ '@foo = "bar"'
303
+ end
304
+
305
+ it 'must correctly print variables containing % sign' do
306
+ enter 'break 22', 'cont', 'info variables'
307
+ debug_proc(@example)
308
+ check_output_includes 'e = "%.2f"'
309
+ end
310
+ end
311
+
312
+ describe 'Help' do
313
+ it 'must show help when typing just "info"' do
314
+ enter 'info', 'cont'
315
+ debug_proc(@example)
316
+ check_output_includes(/List of "info" subcommands:/)
317
+ end
305
318
  end
306
319
  end
307
320
  end