forked from ruby/debug
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig_test.rb
More file actions
508 lines (457 loc) · 10.6 KB
/
config_test.rb
File metadata and controls
508 lines (457 loc) · 10.6 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
# frozen_string_literal: true
require_relative '../support/console_test_case'
module DEBUGGER__
class SetTest < ConsoleTestCase
def program
<<~RUBY
1| def foo
2| bar
3| end
4| def bar
5| p :bar
6| end
7| foo
RUBY
end
def test_config_show
debug_code(program) do
type 'config'
# show all configurations with descriptions
assert_line_text([
/show_src_lines = \d+/,
/show_frames = \d+/
])
# only show this configuration
type 'config show_frames'
assert_no_line_text(/show_src_lines/)
assert_line_text([
/show_frames = \d+/
])
type 'kill!'
end
end
def test_config_show_frames_set_with_eq
debug_code(program) do
type 'config show_frames=1'
assert_line_text([
/show_frames = 1/
])
type 'b 5'
type 'c'
assert_line_num 5
# only show 1 frame, and 2 frames are left.
assert_line_text([
/ # and 2 frames \(use `bt' command for all frames\)/,
])
type 'kill!'
end
end
def test_config_show_frames_set
debug_code(program) do
type 'config set show_frames 1'
assert_line_text([
/show_frames = 1/
])
type 'b 5'
type 'c'
assert_line_num 5
# only show 1 frame, and 2 frames are left.
assert_line_text([
/ # and 2 frames \(use `bt' command for all frames\)/,
])
type 'kill!'
end
end
end
class ShowSrcLinesTest < ConsoleTestCase
def program
<<~RUBY
1| p 1
2| p 2
3| p 3
4| p 4
5| p 5
6| p 6
7| p 7
8| p 8
9| p 9
10| binding.b
11| p 11
12| p 12
13| p 13
14| p 14
15| p 15
RUBY
end
def test_show_src_lines_control_the_lines_displayed_on_breakpoint
debug_code(program) do
type 'config set show_src_lines 2'
type 'continue'
assert_line_text([
/9| p 9/,
/=> 10| binding.b/
])
assert_no_line_text(/p 11/)
type 'continue'
end
end
end
class ShowSrcLinesFrameTest < ConsoleTestCase
def program
<<~RUBY
1| class Foo
2| def self.a
3| p 1
4| p 2
5| p 3
6| p 3
7| p 5
8| p 6
9| p 7
10| p 8
11| p 9
12| p 10
13| b
14| end
15|
16| def self.b
17| binding.b
18| p 11
19| end
20| end
21|
22| Foo.a
RUBY
end
def test_show_src_lines_control_the_lines_displayed_on_up
debug_code(program) do
type 'config set show_src_lines_frame 2'
type 'continue'
type 'up'
assert_line_text([
/12\| p 10/,
/=> 13\| b/,
])
assert_no_line_text(/11\|/)
assert_no_line_text(/14\|/)
type 'continue'
end
end
def test_show_src_lines_control_the_lines_displayed_on_down
debug_code(program) do
type 'config set show_src_lines_frame 2'
type 'continue'
type 'up'
type 'down'
assert_line_text([
/16\| def self\.b/,
/=> 17\| binding\.b/
])
assert_no_line_text(/15\|/)
assert_no_line_text(/18\|/)
type 'continue'
end
end
def test_show_src_lines_control_the_lines_displayed_on_set
debug_code(program) do
type 'config set show_src_lines_frame 2'
type 'continue'
type 'frame'
assert_line_text([
/16\| def self\.b/,
/=> 17\| binding\.b/
])
assert_no_line_text(/15\|/)
assert_no_line_text(/18\|/)
type 'continue'
end
end
end
class ShowOrigSrcTest < ConsoleTestCase
def program
<<~RUBY
1| binding.eval <<RUBY, __FILE__, 10
2| a = 111
3| b = 222
4| c = 333
5| d = 444
6| e = 555
7| f = 666
8| RUBY
9|
10| a = 777
11| b = 888
12| c = 999
RUBY
end
def test_show_evaledsrc_false_defalt
debug_code program do
type 's'
assert_line_num 10
assert_line_text(/a = 777/) # see file's 10th line
type 'c'
end
end
def test_show_evaledsrc_true
debug_code program do
type 'config show_evaledsrc = true'
type 's'
assert_line_num 10
assert_line_text(/a = 111/) # see eval'ed 10t line
type 'c'
end
end
end
class ShowFramesTest < ConsoleTestCase
def program
<<~RUBY
1| def m1
2| m2
3| end
4|
5| def m2
6| m3
7| end
8|
9| def m3
10| foo
11| end
12|
13| def foo
14| binding.b
15| end
16|
17| m1
RUBY
end
def test_show_frames_control_the_frames_displayed_on_breakpoint
debug_code(program) do
type 'config set show_frames 2'
type 'continue'
assert_line_text([
/Object#foo at/,
/Object#m3 at/
])
assert_no_line_text(/Object#m2/)
type 'continue'
end
end
end
class SkipPathTest < ConsoleTestCase
def lib_file
<<~RUBY
def lib_m1
yield
end
def lib_m2
2
end
begin
raise "raised in lib_file"
rescue => e
# rescue
end
RUBY
end
TEMPFILE_BASENAME = __FILE__.hash.abs.to_s(16)
def program(lib_file)
<<~RUBY
1|
2|
3| load "#{lib_file.path}"
4|
5| def foo
6| 1
7| end
8|
9| result = lib_m1 do
10| foo + lib_m2
11| end
12|
13| binding.b
RUBY
end
def with_tempfile
t = Tempfile.create([TEMPFILE_BASENAME, '.rb']).tap do |f|
f.write(lib_file)
f.close
end
yield t
ensure
File.unlink t if t
end
def debug_code
with_tempfile do |lib_file|
super program(lib_file)
end
end
def test_skip_path_skip_frames_that_match_the_path
debug_code do
type "config set skip_path /#{TEMPFILE_BASENAME}/"
type 'b 9'
type 'continue'
type 's'
# skip definition of lib_m1
assert_line_text(/foo \+ lib_m2/)
assert_no_line_text(/def lib_m1/)
# don't display frame that matches skip_path
assert_line_text([
/#0\s+block in <main> at/,
/#2\s+<main> at/
])
assert_no_line_text(/#1/)
type 'c'
# make sure the debugger and program can proceed normally
type 'p "result: #{result.to_s}"'
assert_line_text(/result: 3/)
type 'c'
end
end
def test_skip_path_skip_tracer_output
debug_code do
type "config set skip_path /#{TEMPFILE_BASENAME}/"
type 'trace line'
type 'c'
assert_no_line_text(/#{TEMPFILE_BASENAME}.*\.rb/)
type 'c'
end
end
def test_skip_path_skip_recording_the_frames
debug_code do
type "config set skip_path /#{TEMPFILE_BASENAME}/"
type 'record on'
type 'c'
type 'record'
assert_line_text(/5 records/)
type 's back'
type 's back'
type 's back'
type 's back'
type 's back'
assert_line_text(/foo \+ lib_m2/)
assert_no_line_text(/def lib_m1/)
type 'c'
end
end
def test_skip_path_skip_catch_breakpoint
# without skip_path
debug_code do
type 'catch RuntimeError'
type 'c'
assert_line_text(/RuntimeError/)
type 'c'
type 'c'
end
# with skip_path
debug_code do
type "config set skip_path /#{TEMPFILE_BASENAME}/"
type 'catch RuntimeError'
type 'c'
assert_no_line_text(/RuntimeError/)
type 'c'
end
end
end
class ConfigSetAppend < ConsoleTestCase
def program
<<~RUBY
1| a = 1
RUBY
end
def test_set_append
debug_code program do
type 'config set skip_path foo'
assert_line_text(/foo/)
type 'config set skip_path bar'
assert_no_line_text(/foo/)
assert_line_text(/bar/)
type 'config skip_path = foo'
assert_no_line_text(/bar/)
assert_line_text(/foo/)
type 'config append skip_path bar'
assert_line_text(/foo.+bar/)
type 'config skip_path << baz'
assert_line_text(/foo.+bar.+baz/)
type 'c'
end
end
end
class ConfigKeepAllocSiteTest < ConsoleTestCase
def program
<<~RUBY
1| a = Object.new
2| p a
RUBY
end
def test_p_with_keep_alloc_site
debug_code(program) do
type 'config set keep_alloc_site true'
assert_line_text([
/keep_alloc_site = true/
])
type 's'
assert_line_num 2
type 'p a'
assert_line_text([
/allocated at/
])
type 'pp a'
assert_line_text([
/allocated at/
])
type 'kill!'
end
end
end
class LogLevelTest < ConsoleTestCase
def program
<<~RUBY
1| a = 1
RUBY
end
def test_debugger_takes_log_level_config_from_env_var
# default WARN level doesn't report threads creation
debug_code(program, remote: false) do
type 'Thread.new {}.join'
assert_no_line_text(/Thread #\d+ is created/)
type 'c'
end
ENV["RUBY_DEBUG_LOG_LEVEL"] = "INFO"
debug_code(program, remote: false) do
type 'Thread.new {}.join'
assert_line_text(/DEBUGGER \(INFO\): Thread #\d+ is created/)
type 'c'
end
ensure
ENV["RUBY_DEBUG_LOG_LEVEL"] = nil
end
def test_debugger_takes_log_level_config_from_config_option
# default WARN level doesn't report threads creation
debug_code(program, remote: false) do
type 'Thread.new {}.join'
assert_no_line_text(/Thread #\d+ is created/)
type 'config set log_level INFO'
type 'Thread.new {}.join'
assert_line_text(/DEBUGGER \(INFO\): Thread #\d+ is created/)
type 'c'
end
end
end
class NoLinenoTest < ConsoleTestCase
def program
<<~RUBY
1| a = :a
2| b = :b
3| c = :c
RUBY
end
def test_no_lineno
debug_code(program) do
type 'config set no_lineno true'
type 'list'
assert_no_line_text(/^\s*\d/)
type 'c'
end
end
end
end