2 # Copyright (C) 2007-2009, Parrot Foundation.
7 t/tools/parrot_debugger.t - test the Parrot Debugger
11 % prove t/tools/parrot_debugger.t
15 Tests the C<parrot_debugger> tool by providing it with a number of source
16 files, and running through it with various commands.
18 We never actually check the I<full> output of parrot_debugger. We simply check
19 several smaller components to avoid a test file that is far too unwieldy.
24 This test script requires you to build parrot_debugger, by typing
25 "make parrot_utils" (using a suitable make tool for your platform).
26 If this requirement has not been met, all tests will be skipped.
42 $path_to_pdb = File::Spec->catfile( ".", "parrot_debugger" );
43 my $exefile = $path_to_pdb . $PConfig{exe};
44 unless ( -f $exefile ) {
45 plan skip_all => "parrot_debugger hasn't been built. Run make parrot_utils";
52 pdb_output_like( <<PIR, "pir", "help", qr/List of commands:/, 'help page');
59 pdb_output_like( <<PIR, "pir", "r", qr/3\.14159/, 'running the program (pir)');
66 pdb_output_like( <<PASM, "pasm", "run", qr/42/, 'running the program (long,pasm)');
71 pdb_output_like( <<PASM, "pasm", "r", qr/42/, 'running the program (pasm)');
76 pdb_output_like( <<PASM, "pasm", "n", qr/one more time/, 'next instruction (pasm)');
77 print "one more time\\n"
79 pdb_output_like( <<PASM, "pasm", "next", qr/one more time/, 'next instruction (long,pasm)');
80 print "one more time\\n"
82 pdb_output_like( <<PIR, "pir", "n", qr/one more time/, 'next instruction (pir)');
84 print "one more time\\n"
87 pdb_output_like( <<PIR, "pir", "next", qr/one more time/, 'next instruction (long,pir)');
89 print "one more time\\n"
92 pdb_output_like( <<PIR, "pir", "s", qr/current instr.: 'main'/, 'show stack (pir)');
97 pdb_output_like( <<PIR, "pir", "stack", qr/current instr.: 'main'/, 'show stack (long,pir)');
102 pdb_output_like( <<PASM, "pasm", "s", qr/current instr.: '\(null\)'/, 'show stack (pasm)');
105 pdb_output_like( <<PASM, "pasm", "info", qr/Total memory allocated =/, 'info (pasm)');
108 pdb_output_like( <<PASM, "pasm", "b", qr/Breakpoint 1 at.*pos 0/, 'set breakpoint');
111 pdb_output_like( <<PASM, "pasm", "b\nb\nL", qr/Breakpoint 1 at pos 0\nBreakpoint 2 at pos 0/, 'list breakpoints');
115 pdb_output_like( <<PIR, "pir", "b\nb\nL", qr/Breakpoint 1 at pos 0\nBreakpoint 2 at pos 0/, 'list breakpoints (pir)');
121 pdb_output_like( <<PASM, "pasm", "t", qr/set I0, 242/, 'trace');
125 pdb_output_like( <<PIR, "pir", "t", qr/set I0, 242/, 'trace (pir)');
131 pdb_output_like( <<PASM, "pasm", "t 2", qr/\d+ set I0, 242\s*I0=-?\d+\s*\d+ set I1, 1982/, 'trace multiple statements');
136 pdb_output_like( <<PIR, "pir", "t 2", qr/\d+ set I0, 242\s*I0=-?\d+\s*\d+ set I1, 1982/, 'trace multiple statements (pir)');
143 pdb_output_like( <<PASM, "pasm", "t\np I0", qr/^242/m, 'print an integer register');
147 pdb_output_like( <<PIR, "pir", "t\np I0", qr/^242/m, 'print an integer register (pir)');
153 pdb_output_like( <<PASM, "pasm", "t\np N0", qr/^3.14159/m, 'print a numeric register');
157 pdb_output_like( <<PIR, "pir", "t\np N0", qr/^3.14159/m, 'print a numeric register (pir)');
163 pdb_output_like( <<PASM, "pasm", "t\np P0", qr/^ResizablePMCArray/m, 'print a PMC register');
164 new P0, 'ResizablePMCArray'
167 pdb_output_like( <<PIR, "pir", "t\np P0", qr/^ResizablePMCArray=PMC/m, 'print a PMC register (pir)');
169 \$P0 = new 'ResizablePMCArray'
173 pdb_output_like( <<PASM, "pasm", "t\np S0", qr/^ceiling cat/m, 'print a string register');
174 set S0, "ceiling cat"
177 pdb_output_like( <<PIR, "pir", "t\np S0", qr/^ceiling cat/m, 'print a string register (pir)');
183 pdb_output_like( <<PASM, "pasm", "t 2\np I", qr/I0 = 242\s*I1 = 1982/, 'print all integer registers');
188 pdb_output_like( <<PIR, "pir","t 2\np I", qr/I0 = 242\s*I1 = 1982/, 'print all integer registers (pir)');
195 pdb_output_like( <<PASM, "pasm", "b\n d 1", qr/Breakpoint 1 deleted/, 'Delete a breakpoint');
199 pdb_output_like( <<PIR, "pir", "b\nd 1", qr/Breakpoint 1 deleted/, 'Delete a breakpoint (pir)');
205 pdb_output_like( <<PIR, "pir", "l", qr/\.sub main :main/, 'list source');
211 pdb_output_like( <<PIR, "pir", "l 2", qr/N4 = 6.28/, 'list source with start line');
219 pdb_output_like( <<PIR, "pir", "d 42", qr/No breakpoint number 42/, 'delete invalid breakpoint');
227 local $TODO = 'eval support functions deprecated, TT #872, pending eval reworking';
229 pdb_output_like( <<PIR, "pir", "e ", qr/Must give a command to eval/, 'eval nothing');
237 pdb_output_like( <<PIR, "pir", "t\na I0 17", qr/I0 = 17/, 'assign to an integer register');
243 pdb_output_like( <<PIR, "pir", "t\na i0 17", qr/I0 = 17/, 'assign to an integer register (lowercase)');
249 pdb_output_like( <<PIR, "pir", "a Z0 42", qr/Invalid register type Z/, 'assign to an invalid register');
255 pdb_output_like( <<PIR, "pir", "a foo", qr/Must give a register number and value to assign/, 'invalid assignment command');
261 pdb_output_like( <<PIR, "pir", "t\na N0 3.14", qr/N0 = 3.14/, 'assign to a numeric register');
267 pdb_output_like( <<PIR, "pir", "t\np S", qr/S0 = foobar/, 'print string registers');
273 pdb_output_like( <<PIR, "pir", "t\na S0 foobar", qr/S0 = no such register/, 'print string registers when none exist');
275 new \$P0, 'ResizableIntegerArray'
279 pdb_output_like( <<PIR, "pir", "r", qr/great job!/, 'run code');
287 local $TODO = 'arguments do not seem to populate $P0';
288 pdb_output_like( <<PIR, "pir", "r gomer", qr/gomer/, 'run code with args');
296 pdb_output_like( <<PIR, "pir", "t\nw I0 == 2\nt", qr/Adding watchpoint/, 'watchpoint');
304 BEGIN { $tests += 45 }
306 BEGIN { plan tests => $tests; }
308 =head1 HELPER SUBROUTINES
310 =head2 pdb_output_like
312 pdb_output_like(<<PASM, "pasm", 'r', "some output", "running $file");
314 Takes 4 arguments: a file to run, the filename-extension of the file
315 (probably "pir" or "pasm"), the command or commands to provide to
316 parrot_debugger as script file, and a regex string to match within
317 parrot_debugger's output.
323 sub pdb_output_like {
324 my ( $file, $ext, $input, $check, $diag ) = @_;
326 my $codefn = "$0.$testno.$ext";
327 my $stdinfn = "$0.$testno.stdin";
328 my $stdoutfn = "$0.$testno.stdout";
329 my $f = IO::File->new(">$codefn");
332 $f = IO::File->new(">$stdinfn");
334 $f->print("\nquit\n");
336 system("$path_to_pdb --script $stdinfn $codefn >$stdoutfn 2>&1");
337 $f = IO::File->new($stdoutfn);
339 my $output = join( '', <$f> );
341 local $Test::Builder::Level = $Test::Builder::Level + 1;
342 unlink ($codefn, $stdinfn, $stdoutfn);
343 like( $output, $check, $diag );
352 Flesh it out. This is a bare bones proof of concept.
353 Add tests for all of the commands.
361 # cperl-indent-level: 4
364 # vim: expandtab shiftwidth=4: