14 if (! -c "/dev/null") {
15 print "1..0 # Skip: no /dev/null\n";
19 my $dev_tty = '/dev/tty';
20 $dev_tty = 'TT:' if ($^O eq 'VMS');
22 print "1..0 # Skip: no $dev_tty\n";
26 print "1..0 # Skip: \$ENV{PERL5DB} is already set to '$ENV{PERL5DB}'\n";
29 $ENV{PERL_RL} = 'Perl'; # Suppress system Term::ReadLine::Gnu
34 my $rc_filename = '.perldb';
37 open my $rc_fh, '>', $rc_filename
42 # overly permissive perms gives "Must not source insecure rcfile"
43 # and hangs at the DB(1> prompt
44 chmod 0644, $rc_filename;
51 open my $in, '<', $filename
52 or die "Cannot open '$filename' for slurping - $!";
62 my $out_fn = 'db.out';
66 return _slurp($out_fn);
70 # Test for Proxy constants
75 &parse_options("NonStop=0 ReadLine=0 TTY=db.out");
87 my $output = runperl(switches => [ '-d' ], stderr => 1, progfile => '../lib/perl5db/t/proxy-constants');
88 is($output, "", "proxy constant subroutines");
91 # [perl #66110] Call a subroutine inside a regex
93 local $ENV{PERLDB_OPTS} = "ReadLine=0 NonStop=1";
94 my $output = runperl(switches => [ '-d' ], stderr => 1, progfile => '../lib/perl5db/t/rt-66110');
95 like($output, "All tests successful.", "[perl #66110]");
97 # [ perl #116769] Frame=2
99 local $ENV{PERLDB_OPTS} = "frame=2 nonstop";
100 my $output = runperl( switches => [ '-d' ], prog => 'print q{success}' );
101 is( $?, 0, '[perl #116769] frame=2 does not crash debugger, exit == 0' );
102 like( $output, 'success' , '[perl #116769] code is run' );
104 # [ perl #116771] autotrace
106 local $ENV{PERLDB_OPTS} = "autotrace nonstop";
107 my $output = runperl( switches => [ '-d' ], prog => 'print q{success}' );
108 is( $?, 0, '[perl #116771] autotrace does not crash debugger, exit == 0' );
109 like( $output, 'success' , '[perl #116771] code is run' );
111 # [ perl #41461] Frame=2 noTTY
113 local $ENV{PERLDB_OPTS} = "frame=2 noTTY nonstop";
115 my $output = runperl( switches => [ '-d' ], prog => 'print q{success}' );
116 is( $?, 0, '[perl #41461] frame=2 noTTY does not crash debugger, exit == 0' );
117 like( $output, 'success' , '[perl #41461] code is run' );
125 my $self = bless {}, $class;
136 $self->{_cmds} = shift;
139 return $self->{_cmds};
146 $self->{_prog} = shift;
149 return $self->{_prog};
156 $self->{_output} = shift;
159 return $self->{_output};
168 $self->{_include_t} = shift;
171 return $self->{_include_t};
180 $self->{_stderr_val} = shift;
183 return $self->{_stderr_val};
192 $self->{field} = shift;
195 return $self->{field};
204 $self->{_switches} = shift;
207 return $self->{_switches};
216 $self->{_contents} = shift;
219 return $self->{_contents};
224 my ($self, $args) = @_;
226 my $cmds = $args->{cmds};
228 if (ref($cmds) ne 'ARRAY') {
229 die "cmds must be an array of commands.";
234 my $prog = $args->{prog};
236 if (ref($prog) ne '' or !defined($prog)) {
237 die "prog should be a path to a program file.";
242 $self->_include_t($args->{include_t} ? 1 : 0);
244 $self->_stderr_val(exists($args->{stderr}) ? $args->{stderr} : 1);
246 if (exists($args->{switches}))
248 $self->_switches($args->{switches});
258 my ($self, $str) = @_;
260 $str =~ s/(["\@\$\\])/\\$1/g;
270 my $rc = qq{&parse_options("NonStop=0 TTY=db.out");\n};
275 q#push (@DB::typeahead,#,
276 (map { $self->_quote($_) . "," } @{$self->_cmds()}),
282 # I guess two objects like that cannot be used at the same time.
290 ($self->_switches ? (@{$self->_switches()}) : ('-d')),
291 ($self->_include_t ? ('-I', '../lib/perl5db/t') : ())
293 (defined($self->_stderr_val())
294 ? (stderr => $self->_stderr_val())
297 progfile => $self->_prog()
300 $self->_output($output);
302 $self->_contents(::_out_contents());
309 return shift->_output();
313 my ($self, $re, $msg) = @_;
315 local $::Level = $::Level + 1;
316 ::like($self->_output(), $re, $msg);
320 my ($self, $re, $msg) = @_;
322 local $::Level = $::Level + 1;
323 ::unlike($self->_output(), $re, $msg);
327 my ($self, $re, $msg) = @_;
329 local $::Level = $::Level + 1;
330 ::like($self->_contents(), $re, $msg);
333 sub contents_unlike {
334 my ($self, $re, $msg) = @_;
336 local $::Level = $::Level + 1;
337 ::unlike($self->_contents(), $re, $msg);
343 local $ENV{PERLDB_OPTS} = "ReadLine=0";
344 my $target = '../lib/perl5db/t/eval-line-bug';
345 my $wrapper = DebugWrap->new(
355 "p \@{'main::_<$target'}",
361 $wrapper->contents_like(
363 'The ${main::_<filename} variable in the debugger was not destroyed',
367 sub _calc_generic_wrapper
371 my $extra_opts = delete($args->{extra_opts});
373 local $ENV{PERLDB_OPTS} = "ReadLine=0" . $extra_opts;
374 return DebugWrap->new(
376 cmds => delete($args->{cmds}),
377 prog => delete($args->{prog}),
383 sub _calc_new_var_wrapper
386 return _calc_generic_wrapper(
393 'x "new_var = <$new_var>\\n"',
401 sub _calc_threads_wrapper
405 return _calc_new_var_wrapper(
407 switches => [ '-dt', ],
415 _calc_new_var_wrapper({ prog => '../lib/perl5db/t/eval-line-bug'})
418 "no strict 'vars' in evaluated lines.",
423 _calc_new_var_wrapper(
425 prog => '../lib/perl5db/t/lvalue-bug',
430 'lvalue subs work in the debugger',
435 _calc_new_var_wrapper(
437 prog => '../lib/perl5db/t/symbol-table-bug',
438 extra_opts => "NonStop=1",
442 qr/Undefined symbols 0/,
443 'there are no undefined values in the symbol table',
449 if ( $Config{usethreads} ) {
450 skip('This perl has threads, skipping non-threaded debugger tests');
453 my $error = 'This Perl not built to support threads';
454 _calc_threads_wrapper(
456 prog => '../lib/perl5db/t/eval-line-bug',
460 'Perl debugger correctly complains that it was not built with threads',
467 if ( $Config{usethreads} ) {
468 _calc_threads_wrapper(
470 prog => '../lib/perl5db/t/symbol-table-bug',
473 qr/Undefined symbols 0/,
474 'there are no undefined values in the symbol table when running with thread support',
478 skip("This perl is not threaded, skipping threaded debugger tests");
484 local $ENV{PERLDB_OPTS};
485 my $wrapper = DebugWrap->new(
492 prog => '../lib/perl5db/t/rt-61222',
496 $wrapper->contents_unlike(qr/INCORRECT/, "[perl #61222]");
499 sub _calc_trace_wrapper
503 return _calc_generic_wrapper(
516 # [perl 104168] level option for tracing
518 my $wrapper = _calc_trace_wrapper({ prog => '../lib/perl5db/t/rt-104168' });
519 $wrapper->contents_like(qr/level 2/, "[perl #104168] - level 2 appears");
520 $wrapper->contents_unlike(qr/baz/, "[perl #104168] - no 'baz'");
525 my $wrapper = _calc_trace_wrapper(
527 prog => '../lib/perl5db/t/taint',
528 extra_opts => ' NonStop=1',
529 switches => [ '-d', '-T', ],
533 my $output = $wrapper->get_output();
534 chomp $output if $^O eq 'VMS'; # newline guaranteed at EOF
535 is($output, '[$^X][done]', "taint");
538 # Testing that we can set a line in the middle of the file.
540 my $wrapper = DebugWrap->new(
544 'b ../lib/perl5db/t/MyModule.pm:12',
546 q/do { use IO::Handle; STDOUT->autoflush(1); print "Var=$var\n"; }/,
551 prog => '../lib/perl5db/t/filename-line-breakpoint'
555 $wrapper->output_like(qr/
563 "Can set breakpoint in a line in the middle of the file.");
566 # Testing that we can set a breakpoint
568 my $wrapper = DebugWrap->new(
570 prog => '../lib/perl5db/t/breakpoint-bug',
575 q/do { use IO::Handle; STDOUT->autoflush(1); print "X={$x}\n"; }/,
582 $wrapper->output_like(
584 "Can set breakpoint in a line."
588 # Testing that we can disable a breakpoint at a numeric line.
590 my $wrapper = DebugWrap->new(
592 prog => '../lib/perl5db/t/disable-breakpoints-1',
599 q/print "X={$x}\n";/,
606 $wrapper->output_like(qr/X=\{SecondVal\}/ms,
607 "Can set breakpoint in a line.");
610 # Testing that we can re-enable a breakpoint at a numeric line.
612 my $wrapper = DebugWrap->new(
614 prog => '../lib/perl5db/t/disable-breakpoints-2',
623 q/print "X={$x}\n";/,
630 $wrapper->output_like(
632 X=\{SecondValOneHundred\}
634 "Can set breakpoint in a line."
639 # Disable and enable for breakpoints on outer files.
641 my $wrapper = DebugWrap->new(
646 'b ../lib/perl5db/t/EnableModule.pm:14',
647 'disable ../lib/perl5db/t/EnableModule.pm:14',
649 'enable ../lib/perl5db/t/EnableModule.pm:14',
651 q/print "X={$x}\n";/,
655 prog => '../lib/perl5db/t/disable-breakpoints-3',
660 $wrapper->output_like(qr/
661 X=\{SecondValTwoHundred\}
663 "Can set breakpoint in a line.");
666 # Testing that the prompt with the information appears.
668 my $wrapper = DebugWrap->new(
671 prog => '../lib/perl5db/t/disable-breakpoints-1',
675 $wrapper->contents_like(qr/
676 ^main::\([^\)]*\bdisable-breakpoints-1:2\):\n
677 2:\s+my\ \$x\ =\ "One";\n
679 "Prompt should display the first line of code.");
682 # Testing that R (restart) and "B *" work.
684 my $wrapper = DebugWrap->new(
694 q/print "X={$x};dummy={$dummy}\n";/,
697 prog => '../lib/perl5db/t/disable-breakpoints-1',
701 $wrapper->output_like(qr/
702 X=\{FirstVal\};dummy=\{1\}
704 "Restart and delete all breakpoints work properly.");
708 my $wrapper = DebugWrap->new(
713 q/print "X={$x}\n";/,
717 prog => '../lib/perl5db/t/disable-breakpoints-1',
721 $wrapper->output_like(qr/
724 "'c line_num' is working properly.");
728 my $wrapper = DebugWrap->new(
736 q/print "Exp={$exp}\n";/,
739 prog => '../lib/perl5db/t/break-on-dot',
743 $wrapper->output_like(qr/
746 "'b .' is working correctly.");
749 # Testing that the prompt with the information appears inside a subroutine call.
750 # See https://rt.perl.org/rt3/Ticket/Display.html?id=104820
752 my $wrapper = DebugWrap->new(
759 prog => '../lib/perl5db/t/with-subroutine',
763 $wrapper->contents_like(
765 ^main::back\([^\)\n]*\bwith-subroutine:15\):[\ \t]*\n
766 ^15:\s*print\ "hello\ back\\n";
768 "Prompt should display the line of code inside a subroutine.");
771 # Checking that the p command works.
773 my $wrapper = DebugWrap->new(
777 'p "<<<" . (4*6) . ">>>"',
780 prog => '../lib/perl5db/t/with-subroutine',
784 $wrapper->contents_like(
791 my $wrapper = DebugWrap->new(
798 prog => '../lib/perl5db/t/with-subroutine',
802 $wrapper->contents_like(
803 # qr/^0\s+HASH\([^\)]+\)\n\s+500 => 600\n/,
804 qr/^0\s+HASH\([^\)]+\)\n\s+500 => 600\n/ms,
809 # Tests for x with @_
811 my $wrapper = DebugWrap->new(
820 prog => '../lib/perl5db/t/test-passing-at-underscore-to-x-etc',
824 $wrapper->contents_like(
825 # qr/^0\s+HASH\([^\)]+\)\n\s+500 => 600\n/,
826 qr/Arg1.*?Capsula.*GreekHumor.*Socrates/ms,
827 q/x command test with '@_'./,
831 # Tests for mutating @_
833 my $wrapper = DebugWrap->new(
840 'print "\n\n\n(((" . join(",", @_) . ")))\n\n\n"',
843 prog => '../lib/perl5db/t/test-passing-at-underscore-to-x-etc',
847 $wrapper->output_like(
848 qr/^\(\(\(Capsula,GreekHumor,Socrates\)\)\)$/ms,
853 # Tests for x with AutoTrace=1.
855 my $wrapper = DebugWrap->new(
866 prog => '../lib/perl5db/t/with-subroutine',
870 $wrapper->contents_like(
871 # qr/^0\s+HASH\([^\)]+\)\n\s+500 => 600\n/,
872 qr/^0\s+SCALAR\([^\)]+\)\n\s+-> 'hello world'\n/ms,
873 "x after AutoTrace=1 command is working."
877 # Tests for "T" (stack trace).
879 my $prog_fn = '../lib/perl5db/t/rt-104168';
880 my $wrapper = DebugWrap->new(
891 my $re_text = join('',
894 "%s = %s\\(\\) called from file " .
895 "'" . quotemeta($prog_fn) . "' line %s\\n",
896 (map { quotemeta($_) } @$_)
900 ['.', 'main::baz', 14,],
901 ['.', 'main::bar', 9,],
902 ['.', 'main::foo', 6],
905 $wrapper->contents_like(
906 # qr/^0\s+HASH\([^\)]+\)\n\s+500 => 600\n/,
914 my $wrapper = DebugWrap->new(
921 q/print "X={$x};dummy={$dummy}\n";/,
924 prog => '../lib/perl5db/t/disable-breakpoints-1'
928 $wrapper->output_like(qr/
929 X=\{SecondVal\};dummy=\{1\}
931 'test for s - single step',
936 my $wrapper = DebugWrap->new(
944 q/print "Exp={$exp}\n";/,
947 prog => '../lib/perl5db/t/break-on-dot'
951 $wrapper->output_like(qr/
954 "'b .' is working correctly.");
958 my $prog_fn = '../lib/perl5db/t/rt-104168';
959 my $wrapper = DebugWrap->new(
970 $wrapper->contents_like(
972 ^main::foo\([^\)\n]*\brt-104168:9\):[\ \t]*\n
975 'Test for the s command.',
980 my $wrapper = DebugWrap->new(
984 's uncalled_subroutine()',
989 prog => '../lib/perl5db/t/uncalled-subroutine'}
992 $wrapper->output_like(
994 'uncalled_subroutine was called after s EXPR()',
999 my $wrapper = DebugWrap->new(
1003 'n uncalled_subroutine()',
1007 prog => '../lib/perl5db/t/uncalled-subroutine',
1011 $wrapper->output_like(
1013 'uncalled_subroutine was called after n EXPR()',
1018 my $wrapper = DebugWrap->new(
1030 prog => '../lib/perl5db/t/fact',
1034 $wrapper->output_like(
1036 'b subroutine works fine',
1040 # Test for n with lvalue subs
1044 'n', 'print "<$x>\n"',
1045 'n', 'print "<$x>\n"',
1048 prog => '../lib/perl5db/t/lsub-n',
1051 'n steps over lvalue subs',
1054 # Test for 'M' (module list).
1056 my $wrapper = DebugWrap->new(
1063 prog => '../lib/perl5db/t/load-modules'
1067 $wrapper->contents_like(
1068 qr[Scalar/Util\.pm],
1069 'M (module list) works fine',
1074 my $wrapper = DebugWrap->new(
1082 'print "Var=$var\n";',
1085 prog => '../lib/perl5db/t/test-r-statement',
1089 $wrapper->output_like(
1097 'r statement is working properly.',
1102 my $wrapper = DebugWrap->new(
1109 prog => '../lib/perl5db/t/test-l-statement-1',
1113 $wrapper->contents_like(
1115 ^1==>\s+\$x\ =\ 1;\n
1116 2:\s+print\ "1\\n";\n
1119 5:\s+print\ "2\\n";\n
1121 'l statement is working properly (test No. 1).',
1126 my $wrapper = DebugWrap->new(
1138 prog => '../lib/perl5db/t/test-l-statement-1',
1142 my $first_l_out = qr/
1144 2:\s+print\ "1\\n";\n
1147 5:\s+print\ "2\\n";\n
1150 8:\s+print\ "3\\n";\n
1155 my $second_l_out = qr/
1156 11:\s+print\ "4\\n";\n
1159 14:\s+print\ "5\\n";\n
1162 17:\s+print\ "6\\n";\n
1165 20:\s+print\ "7\\n";\n
1167 $wrapper->contents_like(
1170 [^\n]*?DB<\d+>\ \#\ After\ l\ 1\n
1172 [^\n]*?DB<\d+>\ l\s*\n
1174 [^\n]*?DB<\d+>\ \#\ After\ l\ 2\n
1176 [^\n]*?DB<\d+>\ -\s*\n
1178 [^\n]*?DB<\d+>\ \#\ After\ -\n
1180 'l followed by l and then followed by -',
1185 my $wrapper = DebugWrap->new(
1192 prog => '../lib/perl5db/t/test-l-statement-2',
1196 my $first_l_out = qr/
1198 7:\s+my\ \$n\ =\ shift;\n
1199 8:\s+if\ \(\$n\ >\ 1\)\ \{\n
1200 9:\s+return\ \$n\ \*\ fact\(\$n\ -\ 1\);
1203 $wrapper->contents_like(
1208 'l subroutine_name',
1213 my $wrapper = DebugWrap->new(
1219 # Repeat several times to avoid @typeahead problems.
1226 prog => '../lib/perl5db/t/test-l-statement-2',
1231 ^main::fact\([^\n]*?:7\):\n
1232 ^7:\s+my\ \$n\ =\ shift;\n
1235 $wrapper->contents_like(
1238 auto\(-\d+\)\s+DB<\d+>\s+\.\n
1241 'Test the "." command',
1245 # Testing that the f command works.
1247 my $wrapper = DebugWrap->new(
1251 'f ../lib/perl5db/t/MyModule.pm',
1254 q/do { use IO::Handle; STDOUT->autoflush(1); print "Var=$var\n"; }/,
1259 prog => '../lib/perl5db/t/filename-line-breakpoint'
1263 $wrapper->output_like(qr/
1271 "f command is working.",
1275 # We broke the /pattern/ command because apparently the CORE::eval-s inside
1276 # lib/perl5db.pl cannot handle lexical variable properly. So we now fix this
1281 # 1. Go over the rest of the "eval"s in lib/perl5db.t and see if they cause
1284 my $wrapper = DebugWrap->new(
1291 prog => '../lib/perl5db/t/eval-line-bug',
1295 $wrapper->contents_like(
1296 qr/12: \s* for\ my\ \$q\ \(1\ \.\.\ 10\)\ \{/msx,
1297 "/pat/ command is working and found a match.",
1302 my $wrapper = DebugWrap->new(
1311 prog => '../lib/perl5db/t/eval-line-bug',
1315 $wrapper->contents_like(
1316 qr/12: \s* for\ my\ \$q\ \(1\ \.\.\ 10\)\ \{/msx,
1317 "?pat? command is working and found a match.",
1321 # Test the L command.
1323 my $wrapper = DebugWrap->new(
1332 prog => '../lib/perl5db/t/eval-line-bug',
1336 $wrapper->contents_like(
1338 ^\S*?eval-line-bug:\n
1339 \s*6:\s*my\ \$i\ =\ 5;\n
1340 \s*break\ if\ \(1\)\n
1341 \s*13:\s*\$i\ \+=\ \$q;\n
1342 \s*break\ if\ \(\(\$q\ ==\ 5\)\)\n
1344 "L command is listing breakpoints",
1348 # Test the L command for watch expressions.
1350 my $wrapper = DebugWrap->new(
1358 prog => '../lib/perl5db/t/eval-line-bug',
1362 $wrapper->contents_like(
1364 ^Watch-expressions:\n
1367 "L command is listing watch expressions",
1372 my $wrapper = DebugWrap->new(
1382 prog => '../lib/perl5db/t/eval-line-bug',
1386 $wrapper->contents_like(
1388 ^Watch-expressions:\n
1392 "L command is not listing deleted watch expressions",
1396 # Test the L command.
1398 my $wrapper = DebugWrap->new(
1407 prog => '../lib/perl5db/t/eval-line-bug',
1411 $wrapper->contents_like(
1413 ^\S*?eval-line-bug:\n
1414 \s*6:\s*my\ \$i\ =\ 5;\n
1415 \s*break\ if\ \(1\)\n
1416 \s*13:\s*\$i\ \+=\ \$q;\n
1417 \s*action:\s+print\ \$i\n
1419 "L command is listing actions and breakpoints",
1424 my $wrapper = DebugWrap->new(
1431 prog => '../lib/perl5db/t/rt-104168',
1435 $wrapper->contents_like(
1446 my $wrapper = DebugWrap->new(
1453 prog => '../lib/perl5db/t/rt-104168',
1457 $wrapper->contents_like(
1463 "S command with regex",
1468 my $wrapper = DebugWrap->new(
1475 prog => '../lib/perl5db/t/rt-104168',
1479 $wrapper->contents_unlike(
1483 "S command with negative regex",
1486 $wrapper->contents_like(
1490 "S command with negative regex - what it still matches",
1494 # Test the 'a' command.
1496 my $wrapper = DebugWrap->new(
1500 'a 13 print "\nVar<Q>=$q\n"',
1504 prog => '../lib/perl5db/t/eval-line-bug',
1508 $wrapper->output_like(qr#
1513 "a command is working",
1517 # Test the 'a' command with no line number.
1519 my $wrapper = DebugWrap->new(
1524 q/a print "Hello " . (3 * 4) . "\n";/,
1528 prog => '../lib/perl5db/t/test-a-statement-1',
1532 $wrapper->output_like(qr#
1533 (?:^Hello\ 12\n.*?){4}
1535 "a command with no line number is working",
1539 # Test the 'A' command
1541 my $wrapper = DebugWrap->new(
1545 'a 13 print "\nVar<Q>=$q\n"',
1550 prog => '../lib/perl5db/t/eval-line-bug',
1554 $wrapper->output_like(
1555 qr#\A\z#msx, # The empty string.
1556 "A command (for removing actions) is working",
1560 # Test the 'A *' command
1562 my $wrapper = DebugWrap->new(
1566 'a 6 print "\nFail!\n"',
1567 'a 13 print "\nVar<Q>=$q\n"',
1572 prog => '../lib/perl5db/t/eval-line-bug',
1576 $wrapper->output_like(
1577 qr#\A\z#msx, # The empty string.
1578 "'A *' command (for removing all actions) is working",
1583 my $wrapper = DebugWrap->new(
1590 'print "\nIDX=<$idx>\n"',
1593 prog => '../lib/perl5db/t/test-w-statement-1',
1598 $wrapper->contents_like(qr#
1600 \s+old\ value:\s+'1'\n
1601 \s+new\ value:\s+'2'\n
1603 'w command - watchpoint changed',
1605 $wrapper->output_like(qr#
1608 "w command - correct output from IDX",
1613 my $wrapper = DebugWrap->new(
1621 'print "\nIDX=<$idx>\n"',
1624 prog => '../lib/perl5db/t/test-w-statement-1',
1628 $wrapper->contents_unlike(qr#
1631 'W command - watchpoint was deleted',
1634 $wrapper->output_like(qr#
1637 "W command - stopped at end.",
1641 # Test the W * command.
1643 my $wrapper = DebugWrap->new(
1652 'print "\nIDX=<$idx>\n"',
1655 prog => '../lib/perl5db/t/test-w-statement-1',
1659 $wrapper->contents_unlike(qr#
1662 '"W *" command - watchpoint was deleted',
1665 $wrapper->output_like(qr#
1668 '"W *" command - stopped at end.',
1672 # Test the 'o' command (without further arguments).
1674 my $wrapper = DebugWrap->new(
1681 prog => '../lib/perl5db/t/test-w-statement-1',
1685 $wrapper->contents_like(qr#
1686 ^\s*warnLevel\ =\ '1'\n
1688 q#"o" command (without arguments) displays warnLevel#,
1691 $wrapper->contents_like(qr#
1692 ^\s*signalLevel\ =\ '1'\n
1694 q#"o" command (without arguments) displays signalLevel#,
1697 $wrapper->contents_like(qr#
1698 ^\s*dieLevel\ =\ '1'\n
1700 q#"o" command (without arguments) displays dieLevel#,
1703 $wrapper->contents_like(qr#
1704 ^\s*hashDepth\ =\ 'N/A'\n
1706 q#"o" command (without arguments) displays hashDepth#,
1710 # Test the 'o' query command.
1712 my $wrapper = DebugWrap->new(
1716 'o hashDepth? signalLevel?',
1719 prog => '../lib/perl5db/t/test-w-statement-1',
1723 $wrapper->contents_unlike(qr#warnLevel#,
1724 q#"o" query command does not display warnLevel#,
1727 $wrapper->contents_like(qr#
1728 ^\s*signalLevel\ =\ '1'\n
1730 q#"o" query command displays signalLevel#,
1733 $wrapper->contents_unlike(qr#dieLevel#,
1734 q#"o" query command does not display dieLevel#,
1737 $wrapper->contents_like(qr#
1738 ^\s*hashDepth\ =\ 'N/A'\n
1740 q#"o" query command displays hashDepth#,
1744 # Test the 'o' set command.
1746 my $wrapper = DebugWrap->new(
1754 prog => '../lib/perl5db/t/test-w-statement-1',
1758 $wrapper->contents_like(qr/
1759 ^\s*(signalLevel\ =\ '0'\n)
1763 q#o set command works#,
1766 $wrapper->contents_like(qr#
1767 ^\s*hashDepth\ =\ 'N/A'\n
1769 q#o set command - hashDepth#,
1773 # Test the '<' and "< ?" commands.
1775 my $wrapper = DebugWrap->new(
1779 q/< print "\nX=<$x>\n"/,
1785 prog => '../lib/perl5db/t/disable-breakpoints-1',
1789 $wrapper->contents_like(qr/
1790 ^pre-perl\ commands:\n
1791 \s*<\ --\ print\ "\\nX=<\$x>\\n"\n
1793 q#Test < and < ? commands - contents.#,
1796 $wrapper->output_like(qr#
1799 q#Test < and < ? commands - output.#,
1803 # Test the '< *' command.
1805 my $wrapper = DebugWrap->new(
1809 q/< print "\nX=<$x>\n"/,
1815 prog => '../lib/perl5db/t/disable-breakpoints-1',
1819 $wrapper->output_unlike(qr/FirstVal/,
1820 q#Test the '< *' command.#,
1824 # Test the '>' and "> ?" commands.
1826 my $wrapper = DebugWrap->new(
1831 q/> print "\nFOO=<$::foo>\n"/,
1837 prog => '../lib/perl5db/t/disable-breakpoints-1',
1841 $wrapper->contents_like(qr/
1842 ^post-perl\ commands:\n
1843 \s*>\ --\ print\ "\\nFOO=<\$::foo>\\n"\n
1845 q#Test > and > ? commands - contents.#,
1848 $wrapper->output_like(qr#
1851 q#Test > and > ? commands - output.#,
1855 # Test the '> *' command.
1857 my $wrapper = DebugWrap->new(
1861 q/> print "\nFOO=<$::foo>\n"/,
1867 prog => '../lib/perl5db/t/disable-breakpoints-1',
1871 $wrapper->output_unlike(qr/FOO=/,
1872 q#Test the '> *' command.#,
1876 # Test the < and > commands together
1878 my $wrapper = DebugWrap->new(
1883 q/< $::lorem += 10;/,
1884 q/> print "\nLOREM=<$::lorem>\n"/,
1891 prog => '../lib/perl5db/t/disable-breakpoints-1',
1895 $wrapper->output_like(qr#
1898 q#Test < and > commands. #,
1902 # Test the { ? and { [command] commands.
1904 my $wrapper = DebugWrap->new(
1915 prog => '../lib/perl5db/t/disable-breakpoints-1',
1919 $wrapper->contents_like(qr#
1920 ^No\ pre-debugger\ actions\.\n
1922 ^pre-debugger\ commands:\n
1925 ^5==>b\s+\$x\ =\ "FirstVal";\n
1929 9:\s+\$x\ =\ "SecondVal";\n
1932 'Test the pre-prompt debugger commands',
1936 # Test the { * command.
1938 my $wrapper = DebugWrap->new(
1946 q/print (("One" x 5), "\n");/,
1949 prog => '../lib/perl5db/t/disable-breakpoints-1',
1953 $wrapper->contents_like(qr#
1954 ^All\ \{\ actions\ cleared\.\n
1956 'Test the { * command',
1959 $wrapper->output_like(qr/OneOneOneOneOne/,
1960 '{ * test - output is OK.',
1964 # Test the ! command.
1966 my $wrapper = DebugWrap->new(
1974 prog => '../lib/perl5db/t/disable-breakpoints-1',
1978 $wrapper->contents_like(qr#
1979 (^3:\s+my\ \$dummy\ =\ 0;\n
1981 5:\s+\$x\ =\ "FirstVal";)\n
1986 'Test the ! command (along with l 3-5)',
1990 # Test the ! -number command.
1992 my $wrapper = DebugWrap->new(
2001 prog => '../lib/perl5db/t/disable-breakpoints-1',
2005 $wrapper->contents_like(qr#
2006 (^3:\s+my\ \$dummy\ =\ 0;\n
2008 5:\s+\$x\ =\ "FirstVal";)\n
2010 ^2==\>\s+my\ \$x\ =\ "One";\n
2015 'Test the ! -n command (along with l)',
2019 # Test the 'source' command.
2021 my $wrapper = DebugWrap->new(
2025 'source ../lib/perl5db/t/source-cmd-test.perldb',
2026 # If we have a 'q' here, then the typeahead will override the
2027 # input, and so it won't be reached - solution:
2028 # put a q inside the .perldb commands.
2029 # ( This may be a bug or a misfeature. )
2031 prog => '../lib/perl5db/t/disable-breakpoints-1',
2035 $wrapper->contents_like(qr#
2036 ^3:\s+my\ \$dummy\ =\ 0;\n
2038 5:\s+\$x\ =\ "FirstVal";\n
2042 9:\s+\$x\ =\ "SecondVal";\n
2045 'Test the source command (along with l)',
2049 # Test the 'source' command being traversed from withing typeahead.
2051 my $wrapper = DebugWrap->new(
2055 'source ../lib/perl5db/t/source-cmd-test-no-q.perldb',
2058 prog => '../lib/perl5db/t/disable-breakpoints-1',
2062 $wrapper->contents_like(qr#
2063 ^3:\s+my\ \$dummy\ =\ 0;\n
2065 5:\s+\$x\ =\ "FirstVal";\n
2069 9:\s+\$x\ =\ "SecondVal";\n
2072 'Test the source command inside a typeahead',
2076 # Test the 'H -number' command.
2078 my $wrapper = DebugWrap->new(
2091 prog => '../lib/perl5db/t/disable-breakpoints-1',
2095 $wrapper->contents_like(qr#
2097 \d+:\s+x\ \(20\+4\)\n
2100 \d+:\s+x\ "Hello\ World"\n
2104 'Test the H -num command',
2108 # Add a test for H (without arguments)
2110 my $wrapper = DebugWrap->new(
2123 prog => '../lib/perl5db/t/disable-breakpoints-1',
2127 $wrapper->contents_like(qr#
2128 ^\d+:\s+x\ \(20\+4\)\n
2131 \d+:\s+x\ "Hello\ World"\n
2135 'Test the H command (without a number.)',
2140 my $wrapper = DebugWrap->new(
2149 prog => '../lib/perl5db/t/test-l-statement-1',
2153 $wrapper->contents_like(
2155 ^1==>\s+\$x\ =\ 1;\n
2156 2:\s+print\ "1\\n";\n
2159 5:\s+print\ "2\\n";\n
2161 'Test the = (command alias) command.',
2165 # Test the m statement.
2167 my $wrapper = DebugWrap->new(
2174 prog => '../lib/perl5db/t/disable-breakpoints-1',
2178 $wrapper->contents_like(qr#
2179 ^via\ UNIVERSAL:\ DOES$
2181 "Test m for main - 1",
2184 $wrapper->contents_like(qr#
2185 ^via\ UNIVERSAL:\ can$
2187 "Test m for main - 2",
2191 # Test the m statement.
2193 my $wrapper = DebugWrap->new(
2202 prog => '../lib/perl5db/t/test-m-statement-1',
2206 $wrapper->contents_like(qr#^greet$#ms,
2207 "Test m for obj - 1",
2210 $wrapper->contents_like(qr#^via UNIVERSAL: can$#ms,
2211 "Test m for obj - 1",
2215 # Test the M command.
2217 my $wrapper = DebugWrap->new(
2224 prog => '../lib/perl5db/t/test-m-statement-1',
2228 $wrapper->contents_like(qr#
2229 ^'strict\.pm'\ =>\ '\d+\.\d+\ from
2236 # Test the recallCommand option.
2238 my $wrapper = DebugWrap->new(
2242 'o recallCommand=%',
2248 prog => '../lib/perl5db/t/disable-breakpoints-1',
2252 $wrapper->contents_like(qr#
2253 (^3:\s+my\ \$dummy\ =\ 0;\n
2255 5:\s+\$x\ =\ "FirstVal";)\n
2257 ^2==\>\s+my\ \$x\ =\ "One";\n
2262 'Test the o recallCommand option',
2266 # Test the dieLevel option
2268 my $wrapper = DebugWrap->new(
2276 prog => '../lib/perl5db/t/test-dieLevel-option-1',
2280 $wrapper->output_like(qr#
2281 ^This\ program\ dies\.\ at\ \S+\ line\ 18\.\n
2283 ^\s+main::baz\(\)\ called\ at\ \S+\ line\ 13\n
2284 \s+main::bar\(\)\ called\ at\ \S+\ line\ 7\n
2285 \s+main::foo\(\)\ called\ at\ \S+\ line\ 21\n
2287 'Test the o dieLevel option',
2291 # Test the warnLevel option
2293 my $wrapper = DebugWrap->new(
2301 prog => '../lib/perl5db/t/test-warnLevel-option-1',
2305 $wrapper->contents_like(qr#
2306 ^This\ is\ not\ a\ warning\.\ at\ \S+\ line\ 18\.\n
2308 ^\s+main::baz\(\)\ called\ at\ \S+\ line\ 13\n
2309 \s+main::bar\(\)\ called\ at\ \S+\ line\ 25\n
2310 \s+main::myfunc\(\)\ called\ at\ \S+\ line\ 28\n
2312 'Test the o warnLevel option',
2316 # Test the t command
2318 my $wrapper = DebugWrap->new(
2326 prog => '../lib/perl5db/t/disable-breakpoints-1',
2330 $wrapper->contents_like(qr/
2331 ^main::\([^:]+:15\):\n
2332 15:\s+\$dummy\+\+;\n
2333 main::\([^:]+:17\):\n
2334 17:\s+\$x\ =\ "FourthVal";\n
2336 'Test the t command (without a number.)',
2340 # Test the o AutoTrace command
2342 my $wrapper = DebugWrap->new(
2350 prog => '../lib/perl5db/t/disable-breakpoints-1',
2354 $wrapper->contents_like(qr/
2355 ^main::\([^:]+:15\):\n
2356 15:\s+\$dummy\+\+;\n
2357 main::\([^:]+:17\):\n
2358 17:\s+\$x\ =\ "FourthVal";\n
2360 'Test the o AutoTrace command',
2364 # Test the t command with function calls
2366 my $wrapper = DebugWrap->new(
2377 prog => '../lib/perl5db/t/test-warnLevel-option-1',
2381 $wrapper->contents_like(qr/
2382 ^main::\([^:]+:28\):\n
2384 auto\(-\d+\)\s+DB<1>\s+t\n
2386 auto\(-\d+\)\s+DB<1>\s+b\ 18\n
2387 auto\(-\d+\)\s+DB<2>\s+c\n
2388 main::myfunc\([^:]+:25\):\n
2391 'Test the t command with function calls.',
2395 # Test the o AutoTrace command with function calls
2397 my $wrapper = DebugWrap->new(
2408 prog => '../lib/perl5db/t/test-warnLevel-option-1',
2412 $wrapper->contents_like(qr/
2413 ^main::\([^:]+:28\):\n
2415 auto\(-\d+\)\s+DB<1>\s+o\ AutoTrace\n
2416 \s+AutoTrace\s+=\s+'1'\n
2417 auto\(-\d+\)\s+DB<2>\s+b\ 18\n
2418 auto\(-\d+\)\s+DB<3>\s+c\n
2419 main::myfunc\([^:]+:25\):\n
2422 'Test the o AutoTrace command with function calls.',
2426 # Test the final message.
2428 my $wrapper = DebugWrap->new(
2435 prog => '../lib/perl5db/t/test-warnLevel-option-1',
2439 $wrapper->contents_like(qr/
2440 ^Debugged\ program\ terminated\.
2442 'Test the final "Debugged program terminated" message.',
2446 # Test the o inhibit_exit=0 command
2448 my $wrapper = DebugWrap->new(
2459 prog => '../lib/perl5db/t/test-warnLevel-option-1',
2463 $wrapper->contents_unlike(qr/
2464 ^Debugged\ program\ terminated\.
2466 'Test the o inhibit_exit=0 command.',
2470 # Test the o PrintRet=1 option
2472 my $wrapper = DebugWrap->new(
2485 prog => '../lib/perl5db/t/test-PrintRet-option-1',
2489 $wrapper->contents_like(
2490 qr/scalar context return from main::return_scalar: 20024/,
2491 "Test o PrintRet=1",
2495 # Test the o PrintRet=0 option
2497 my $wrapper = DebugWrap->new(
2510 prog => '../lib/perl5db/t/test-PrintRet-option-1',
2514 $wrapper->contents_unlike(
2516 "Test o PrintRet=0",
2520 # Test the o PrintRet=1 option in list context
2522 my $wrapper = DebugWrap->new(
2535 prog => '../lib/perl5db/t/test-PrintRet-option-1',
2539 $wrapper->contents_like(
2540 qr/list context return from main::return_list:\n0\s*'Foo'\n1\s*'Bar'\n2\s*'Baz'\n/,
2541 "Test o PrintRet=1 in list context",
2545 # Test the o PrintRet=0 option in list context
2547 my $wrapper = DebugWrap->new(
2560 prog => '../lib/perl5db/t/test-PrintRet-option-1',
2564 $wrapper->contents_unlike(
2566 "Test o PrintRet=0 in list context",
2570 # Test the o PrintRet=1 option in void context
2572 my $wrapper = DebugWrap->new(
2585 prog => '../lib/perl5db/t/test-PrintRet-option-1',
2589 $wrapper->contents_like(
2590 qr/void context return from main::return_void/,
2591 "Test o PrintRet=1 in void context",
2595 # Test the o PrintRet=1 option in void context
2597 my $wrapper = DebugWrap->new(
2610 prog => '../lib/perl5db/t/test-PrintRet-option-1',
2614 $wrapper->contents_unlike(
2616 "Test o PrintRet=0 in void context",
2620 # Test the o frame option.
2622 my $wrapper = DebugWrap->new(
2626 # This is to avoid getting the "Debugger program terminated"
2627 # junk that interferes with the normal output.
2635 prog => '../lib/perl5db/t/test-frame-option-1',
2639 $wrapper->contents_like(
2641 in\s*\.=main::my_other_func\(3,\ 1200\)\ from.*?
2642 out\s*\.=main::my_other_func\(3,\ 1200\)\ from
2644 "Test o PrintRet=0 in void context",
2649 my $wrapper = DebugWrap->new(
2653 # This is to avoid getting the "Debugger program terminated"
2654 # junk that interferes with the normal output.
2659 prog => '../lib/perl5db/t/fact',
2663 $wrapper->contents_like(
2665 (?:^main::fact.*return\ \$n\ \*\ fact\(\$n\ -\ 1\);.*)
2671 # Test the w for lexical variables expression.
2673 my $wrapper = DebugWrap->new(
2677 # This is to avoid getting the "Debugger program terminated"
2678 # junk that interferes with the normal output.
2686 prog => '../lib/perl5db/t/break-on-dot',
2690 $wrapper->contents_like(
2692 \s+old\ value:\s+'1'\n
2693 \s+new\ value:\s+'2'\n
2695 "Test w for lexical values.",
2699 # Test the perldoc command
2700 # We don't actually run the program, but we need to provide one to the wrapper.
2704 or skip "man errors aren't especially portable", 1;
2706 or skip "man command seems to be missing", 1;
2707 local $ENV{LANG} = "C";
2708 local $ENV{LC_MESSAGES} = "C";
2709 local $ENV{LC_ALL} = "C";
2710 my $wrapper = DebugWrap->new(
2714 'perldoc perlrules',
2717 prog => '../lib/perl5db/t/fact',
2721 $wrapper->output_like(
2722 qr/No manual entry for perlrules/,
2723 'perldoc command works fine',
2728 1 while unlink ($rc_filename, $out_fn);