3 # Copyright 2016 Steven Watanabe
4 # Distributed under the Boost Software License, Version 1.0.
5 # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
7 # Test for the debugger
13 def split_stdin_stdout(text
):
14 """stdin is all text after the prompt up to and including
15 the next newline. Everything else is stdout. stdout
16 may contain regular expressions enclosed in {{}}."""
17 prompt
= re
.escape('(b2db) ')
18 pattern
= re
.compile('(?<=%s)(.*\n)' % prompt
)
19 text
= text
.replace("{{bjam}}", "{{.*}}b2{{(?:\\.exe)?}}")
20 stdin
= ''.join(re
.findall(pattern
, text
))
21 stdout
= re
.sub(pattern
, '', text
)
22 outside_pattern
= re
.compile(r
'(?:\A|(?<=\}\}))(?:[^\{]|(?:\{(?!\{)))*(?:(?=\{\{)|\Z)')
24 def escape_line(line
):
25 line
= re
.sub(outside_pattern
, lambda m
: re
.escape(m
.group(0)), line
)
26 return re
.sub(r
'\{\{|\}\}', '', line
)
28 stdout
= '\n'.join([escape_line(line
) for line
in stdout
.split('\n')])
32 (input,output
) = split_stdin_stdout(io
)
33 tester
.run_build_system(stdin
=input, stdout
=output
, match
=TestCmd
.match_re
)
36 return BoostBuild
.Tester(["-dconsole"], pass_toolset
=False, pass_d0
=False,
37 use_test_config
=False, ignore_toolset_requirements
=False, match
=TestCmd
.match_re
)
41 t
.write("test.jam", """\
47 Starting program: {{bjam}} -ftest.jam
48 Child {{\d+}} exited with status 0
54 def test_exit_status():
56 t
.write("test.jam", """\
61 Starting program: {{bjam}} -ftest.jam
63 Child {{\d+}} exited with status 1
70 t
.write("test.jam", """\
87 Starting program: {{bjam}} -ftest.jam
88 Breakpoint 1, f ( ) at test.jam:8
100 # Note: step doesn't need to worry about breakpoints,
101 # as it always stops at the next line executed.
105 t
.write("test.jam", """\
126 Breakpoint 1 set at f
127 (b2db) run -ftest.jam
128 Starting program: {{bjam}} -ftest.jam
129 Breakpoint 1, f ( ) at test.jam:7
143 def test_next_breakpoint():
144 """next should stop if it encounters a breakpoint.
145 If the normal end point happens to be a breakpoint,
146 then it should be reported as normal stepping."""
148 t
.write("test.jam", """\
151 if $(recurse) { f ; }
163 Breakpoint 1 set at f
165 Breakpoint 2 set at g
166 (b2db) break test.jam:4
167 Breakpoint 3 set at test.jam:4
168 (b2db) run -ftest.jam
169 Starting program: {{bjam}} -ftest.jam
170 Breakpoint 1, f ( true ) at test.jam:3
171 3 if $(recurse) { f ; }
173 Breakpoint 1, f ( ) at test.jam:3
174 3 if $(recurse) { f ; }
182 Breakpoint 2, g ( ) at test.jam:8
190 t
.write("test.jam", """\
215 Breakpoint 1 set at f
216 (b2db) run -ftest.jam
217 Starting program: {{bjam}} -ftest.jam
218 Breakpoint 1, f ( ) at test.jam:3
230 def test_finish_breakpoints():
231 """finish should stop when it reaches a breakpoint."""
233 t
.write("test.jam", """\
238 a = [ f $(recurse[2-]) ] ;
243 for local v in $(list)
252 (b2db) break test.jam:5
253 Breakpoint 1 set at test.jam:5
254 (b2db) break test.jam:12
255 Breakpoint 2 set at test.jam:12
256 (b2db) run -ftest.jam
257 Starting program: {{bjam}} -ftest.jam
258 Breakpoint 1, f ( 1 2 ) at test.jam:5
259 5 a = [ f $(recurse[2-]) ] ;
261 Breakpoint 1, f ( 2 ) at test.jam:5
262 5 a = [ f $(recurse[2-]) ] ;
264 5 a = [ f $(recurse[2-]) ] ;
268 Breakpoint 2, g ( 1 2 ) at test.jam:12
271 Breakpoint 2, g ( 1 2 ) at test.jam:12
277 def test_continue_breakpoints():
278 """continue should stop when it reaches a breakpoint"""
280 t
.write("test.jam", """\
285 a = [ f $(recurse[2-]) ] ;
290 for local v in $(list)
299 (b2db) break test.jam:5
300 Breakpoint 1 set at test.jam:5
301 (b2db) break test.jam:12
302 Breakpoint 2 set at test.jam:12
303 (b2db) run -ftest.jam
304 Starting program: {{bjam}} -ftest.jam
305 Breakpoint 1, f ( 1 2 ) at test.jam:5
306 5 a = [ f $(recurse[2-]) ] ;
308 Breakpoint 1, f ( 2 ) at test.jam:5
309 5 a = [ f $(recurse[2-]) ] ;
311 Breakpoint 1, f ( 1 2 ) at test.jam:5
312 5 a = [ f $(recurse[2-]) ] ;
314 Breakpoint 2, g ( 1 2 ) at test.jam:12
317 Breakpoint 2, g ( 1 2 ) at test.jam:12
323 def test_breakpoints():
324 """Tests the interaction between the following commands:
325 break, clear, delete, disable, enable"""
327 t
.write("test.jam", """\
348 Breakpoint 1 set at f
349 (b2db) run -ftest.jam
350 Starting program: {{bjam}} -ftest.jam
351 Breakpoint 1, f ( ) at test.jam:3
355 Breakpoint 2 set at g
357 (b2db) run -ftest.jam
358 Starting program: {{bjam}} -ftest.jam
359 Breakpoint 2, g ( ) at test.jam:7
363 (b2db) run -ftest.jam
364 Starting program: {{bjam}} -ftest.jam
365 Breakpoint 1, f ( ) at test.jam:3
369 (b2db) run -ftest.jam
370 Starting program: {{bjam}} -ftest.jam
371 Breakpoint 2, g ( ) at test.jam:7
374 (b2db) break test.jam:12
375 Breakpoint 3 set at test.jam:12
378 (b2db) run -ftest.jam
379 Starting program: {{bjam}} -ftest.jam
380 Breakpoint 3, h ( ) at test.jam:12
383 (b2db) clear test.jam:12
385 (b2db) run -ftest.jam
386 Starting program: {{bjam}} -ftest.jam
387 Child {{\d+}} exited with status 0
392 def test_breakpoints_running():
393 """Tests that breakpoints can be added and modified
394 while the program is running."""
396 t
.write("test.jam", """\
416 (b2db) break test.jam:14
417 Breakpoint 1 set at test.jam:14
418 (b2db) run -ftest.jam
419 Starting program: {{bjam}} -ftest.jam
420 Breakpoint 1, module scope at test.jam:14
423 Breakpoint 2 set at f
425 Breakpoint 2, f ( ) at test.jam:3
428 (b2db) run -ftest.jam
429 Starting program: {{bjam}} -ftest.jam
430 Breakpoint 1, module scope at test.jam:14
433 Breakpoint 3 set at g
436 Breakpoint 3, g ( ) at test.jam:7
439 (b2db) run -ftest.jam
440 Starting program: {{bjam}} -ftest.jam
441 Breakpoint 1, module scope at test.jam:14
445 Breakpoint 2, f ( ) at test.jam:3
448 (b2db) run -ftest.jam
449 Starting program: {{bjam}} -ftest.jam
450 Breakpoint 1, module scope at test.jam:14
454 Breakpoint 3, g ( ) at test.jam:7
457 (b2db) run -ftest.jam
458 Starting program: {{bjam}} -ftest.jam
459 Breakpoint 1, module scope at test.jam:14
461 (b2db) break test.jam:12
462 Breakpoint 4 set at test.jam:12
466 Breakpoint 4, h ( ) at test.jam:12
469 (b2db) run -ftest.jam
470 Starting program: {{bjam}} -ftest.jam
471 Breakpoint 1, module scope at test.jam:14
473 (b2db) clear test.jam:12
476 Child {{\d+}} exited with status 0
481 def test_backtrace():
483 t
.write("test.jam", """\
484 rule f ( x * : y * : z * )
488 rule g ( x * : y * : z * )
490 return [ f $(x) : $(y) : $(z) ] ;
496 Breakpoint 1 set at f
497 (b2db) run -ftest.jam
498 Starting program: {{bjam}} -ftest.jam
499 Breakpoint 1, f ( 1 : 2 : 3 ) at test.jam:3
502 #0 in f ( 1 : 2 : 3 ) at test.jam:3
503 #1 in g ( 1 : 2 : 3 ) at test.jam:7
504 #2 in module scope at test.jam:9
511 t
.write("test.jam", """\
522 Breakpoint 1 set at f
523 (b2db) run -ftest.jam
524 Starting program: {{bjam}} -ftest.jam
525 Breakpoint 1, f ( x ) at test.jam:3
530 Breakpoint 1, f ( x y ) at test.jam:3
542 def test_run_running():
544 t
.write("test.jam", """\
549 (b2db) break test.jam:1
550 Breakpoint 1 set at test.jam:1
551 (b2db) run -ftest.jam
552 Starting program: {{bjam}} -ftest.jam
553 Breakpoint 1, module scope at test.jam:1
555 (b2db) run -ftest.jam
556 Child {{\d+}} exited with status 0
557 Starting program: {{bjam}} -ftest.jam
558 Breakpoint 1, module scope at test.jam:1
565 def test_error_not_running():
569 The program is not being run.
571 The program is not being run.
573 The program is not being run.
575 The program is not being run.
577 The program is not being run.
579 The program is not being run.
581 The program is not being run.
587 def test_bad_arguments():
589 t
.write("test.jam", """\
594 (b2db) break test.jam:1
595 Breakpoint 1 set at test.jam:1
596 (b2db) run -ftest.jam
597 Starting program: {{bjam}} -ftest.jam
598 Breakpoint 1, module scope at test.jam:1
601 Too many arguments to continue.
603 Too many arguments to step.
605 Too many arguments to next.
607 Too many arguments to finish.
609 Missing argument to break.
611 Too many arguments to break.
613 Missing argument to disable.
615 Too many arguments to disable.
617 Invalid breakpoint number x.
619 Unknown breakpoint 2.
621 Missing argument to enable.
623 Too many arguments to enable.
625 Invalid breakpoint number x.
627 Unknown breakpoint 2.
629 Missing argument to delete.
631 Too many arguments to delete.
633 Invalid breakpoint number x.
635 Unknown breakpoint 2.
637 Missing argument to clear.
638 (b2db) clear test.jam:1 test.jam:1
639 Too many arguments to clear.
640 (b2db) clear test.jam:2
641 No breakpoint at test.jam:2.
647 def test_unknown_command():
651 Unknown command: xyzzy
653 Unknown command: gnusto
663 test_next_breakpoint()
665 test_finish_breakpoints()
666 test_continue_breakpoints()
668 test_breakpoints_running()
672 test_error_not_running()
674 test_unknown_command()