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}}", "{{.*}}bjam{{(?:\\.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
102 t
.write("test.jam", """\
123 Breakpoint 1 set at f
124 (b2db) run -ftest.jam
125 Starting program: {{bjam}} -ftest.jam
126 Breakpoint 1, f ( ) at test.jam:7
142 t
.write("test.jam", """\
167 Breakpoint 1 set at f
168 (b2db) run -ftest.jam
169 Starting program: {{bjam}} -ftest.jam
170 Breakpoint 1, f ( ) at test.jam:3
182 def test_breakpoints():
183 """Tests the interaction between the following commands:
184 break, clear, delete, disable, enable"""
186 t
.write("test.jam", """\
207 Breakpoint 1 set at f
208 (b2db) run -ftest.jam
209 Starting program: {{bjam}} -ftest.jam
210 Breakpoint 1, f ( ) at test.jam:3
214 Breakpoint 2 set at g
216 (b2db) run -ftest.jam
217 Starting program: {{bjam}} -ftest.jam
218 Breakpoint 2, g ( ) at test.jam:7
222 (b2db) run -ftest.jam
223 Starting program: {{bjam}} -ftest.jam
224 Breakpoint 1, f ( ) at test.jam:3
228 (b2db) run -ftest.jam
229 Starting program: {{bjam}} -ftest.jam
230 Breakpoint 2, g ( ) at test.jam:7
233 (b2db) break test.jam:12
234 Breakpoint 3 set at test.jam:12
237 (b2db) run -ftest.jam
238 Starting program: {{bjam}} -ftest.jam
239 Breakpoint 3, h ( ) at test.jam:12
242 (b2db) clear test.jam:12
244 (b2db) run -ftest.jam
245 Starting program: {{bjam}} -ftest.jam
246 Child {{\d+}} exited with status 0
251 def test_breakpoints_running():
252 """Tests that breakpoints can be added and modified
253 while the program is running."""
255 t
.write("test.jam", """\
275 (b2db) break test.jam:14
276 Breakpoint 1 set at test.jam:14
277 (b2db) run -ftest.jam
278 Starting program: {{bjam}} -ftest.jam
279 Breakpoint 1, module scope at test.jam:14
282 Breakpoint 2 set at f
284 Breakpoint 2, f ( ) at test.jam:3
287 (b2db) run -ftest.jam
288 Starting program: {{bjam}} -ftest.jam
289 Breakpoint 1, module scope at test.jam:14
292 Breakpoint 3 set at g
295 Breakpoint 3, g ( ) at test.jam:7
298 (b2db) run -ftest.jam
299 Starting program: {{bjam}} -ftest.jam
300 Breakpoint 1, module scope at test.jam:14
304 Breakpoint 2, f ( ) at test.jam:3
307 (b2db) run -ftest.jam
308 Starting program: {{bjam}} -ftest.jam
309 Breakpoint 1, module scope at test.jam:14
313 Breakpoint 3, g ( ) at test.jam:7
316 (b2db) run -ftest.jam
317 Starting program: {{bjam}} -ftest.jam
318 Breakpoint 1, module scope at test.jam:14
320 (b2db) break test.jam:12
321 Breakpoint 4 set at test.jam:12
325 Breakpoint 4, h ( ) at test.jam:12
328 (b2db) run -ftest.jam
329 Starting program: {{bjam}} -ftest.jam
330 Breakpoint 1, module scope at test.jam:14
332 (b2db) clear test.jam:12
335 Child {{\d+}} exited with status 0
340 def test_backtrace():
342 t
.write("test.jam", """\
343 rule f ( x * : y * : z * )
347 rule g ( x * : y * : z * )
349 return [ f $(x) : $(y) : $(z) ] ;
355 Breakpoint 1 set at f
356 (b2db) run -ftest.jam
357 Starting program: {{bjam}} -ftest.jam
358 Breakpoint 1, f ( 1 : 2 : 3 ) at test.jam:3
361 #0 in f ( 1 : 2 : 3 ) at test.jam:3
362 #1 in g ( 1 : 2 : 3 ) at test.jam:7
363 #2 in module scope at test.jam:9
370 t
.write("test.jam", """\
381 Breakpoint 1 set at f
382 (b2db) run -ftest.jam
383 Starting program: {{bjam}} -ftest.jam
384 Breakpoint 1, f ( x ) at test.jam:3
389 Breakpoint 1, f ( x y ) at test.jam:3
401 def test_run_running():
403 t
.write("test.jam", """\
408 (b2db) break test.jam:1
409 Breakpoint 1 set at test.jam:1
410 (b2db) run -ftest.jam
411 Starting program: {{bjam}} -ftest.jam
412 Breakpoint 1, module scope at test.jam:1
414 (b2db) run -ftest.jam
415 Child {{\d+}} exited with status 0
416 Starting program: {{bjam}} -ftest.jam
417 Breakpoint 1, module scope at test.jam:1
424 def test_error_not_running():
428 The program is not being run.
430 The program is not being run.
432 The program is not being run.
434 The program is not being run.
436 The program is not being run.
438 The program is not being run.
440 The program is not being run.
446 def test_bad_arguments():
448 t
.write("test.jam", """\
453 (b2db) break test.jam:1
454 Breakpoint 1 set at test.jam:1
455 (b2db) run -ftest.jam
456 Starting program: {{bjam}} -ftest.jam
457 Breakpoint 1, module scope at test.jam:1
460 Too many arguments to continue.
462 Too many arguments to step.
464 Too many arguments to next.
466 Too many arguments to finish.
468 Missing argument to break.
470 Too many arguments to break.
472 Missing argument to disable.
474 Too many arguments to disable.
476 Invalid breakpoint number x.
478 Unknown breakpoint 2.
480 Missing argument to enable.
482 Too many arguments to enable.
484 Invalid breakpoint number x.
486 Unknown breakpoint 2.
488 Missing argument to delete.
490 Too many arguments to delete.
492 Invalid breakpoint number x.
494 Unknown breakpoint 2.
496 Missing argument to clear.
497 (b2db) clear test.jam:1 test.jam:1
498 Too many arguments to clear.
499 (b2db) clear test.jam:2
500 No breakpoint at test.jam:2.
506 def test_unknown_command():
510 Unknown command: xyzzy
512 Unknown command: gnusto
524 test_breakpoints_running()
528 test_error_not_running()
530 test_unknown_command()