1*0Sstevel@tonic-gate#!./perl -Tw 2*0Sstevel@tonic-gate 3*0Sstevel@tonic-gateBEGIN { 4*0Sstevel@tonic-gate chdir 't' if -d 't'; 5*0Sstevel@tonic-gate @INC = '../lib'; 6*0Sstevel@tonic-gate} 7*0Sstevel@tonic-gate 8*0Sstevel@tonic-gate# symbolic references used later 9*0Sstevel@tonic-gateuse strict qw( vars subs ); 10*0Sstevel@tonic-gate 11*0Sstevel@tonic-gate# @DB::dbline values have both integer and string components (Benjamin Goldberg) 12*0Sstevel@tonic-gateuse Scalar::Util qw( dualvar ); 13*0Sstevel@tonic-gatemy $dualfalse = dualvar(0, 'false'); 14*0Sstevel@tonic-gatemy $dualtrue = dualvar(1, 'true'); 15*0Sstevel@tonic-gate 16*0Sstevel@tonic-gateuse Test::More tests => 106; 17*0Sstevel@tonic-gate 18*0Sstevel@tonic-gate# must happen at compile time for DB:: package variable localizations to work 19*0Sstevel@tonic-gateBEGIN { 20*0Sstevel@tonic-gate use_ok( 'DB' ); 21*0Sstevel@tonic-gate} 22*0Sstevel@tonic-gate 23*0Sstevel@tonic-gate# test DB::sub() 24*0Sstevel@tonic-gate{ 25*0Sstevel@tonic-gate my $callflag = 0; 26*0Sstevel@tonic-gate local $DB::sub = sub { 27*0Sstevel@tonic-gate $callflag += shift || 1; 28*0Sstevel@tonic-gate my @vals = (1, 4, 9); 29*0Sstevel@tonic-gate return @vals; 30*0Sstevel@tonic-gate }; 31*0Sstevel@tonic-gate my $ret = DB::sub; 32*0Sstevel@tonic-gate is( $ret, 3, 'DB::sub() should handle scalar context' ); 33*0Sstevel@tonic-gate is( $callflag, 1, '... should call $DB::sub contents' ); 34*0Sstevel@tonic-gate $ret = join(' ', DB::sub(2)); 35*0Sstevel@tonic-gate is( $ret, '1 4 9', '... should handle scalar context' ); 36*0Sstevel@tonic-gate is( $callflag, 3, '... should pass along arguments to the sub' ); 37*0Sstevel@tonic-gate ok( defined($DB::ret),'$DB::ret should be defined after successful return'); 38*0Sstevel@tonic-gate DB::sub; 39*0Sstevel@tonic-gate ok( !defined($DB::ret), '... should respect void context' ); 40*0Sstevel@tonic-gate $DB::sub = '::DESTROY'; 41*0Sstevel@tonic-gate ok( !defined($DB::ret), '... should return undef for DESTROY()' ); 42*0Sstevel@tonic-gate} 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate# test DB::DB() 45*0Sstevel@tonic-gate{ 46*0Sstevel@tonic-gate ok( ! defined DB::DB(), 47*0Sstevel@tonic-gate 'DB::DB() should return undef if $DB::ready is false'); 48*0Sstevel@tonic-gate is( DB::catch(), 1, 'DB::catch() should work' ); 49*0Sstevel@tonic-gate is( DB->skippkg('foo'), 1, 'DB->skippkg() should push args' ); 50*0Sstevel@tonic-gate 51*0Sstevel@tonic-gate # change packages to mess with caller() 52*0Sstevel@tonic-gate package foo; 53*0Sstevel@tonic-gate ::ok( ! defined DB::DB(), 'DB::DB() should skip skippable packages' ); 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate package main; 56*0Sstevel@tonic-gate is( $DB::filename, $0, '... should set $DB::filename' ); 57*0Sstevel@tonic-gate is( $DB::lineno, __LINE__ - 4, '... should set $DB::lineno' ); 58*0Sstevel@tonic-gate 59*0Sstevel@tonic-gate DB::DB(); 60*0Sstevel@tonic-gate # stops at line 94 61*0Sstevel@tonic-gate} 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate# test DB::save() 64*0Sstevel@tonic-gate{ 65*0Sstevel@tonic-gate no warnings 'uninitialized'; 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate # assigning a number to $! seems to produce an error message, when read 68*0Sstevel@tonic-gate local ($@, $,, $/, $\, $^W, $!) = (1 .. 5); 69*0Sstevel@tonic-gate DB::save(); 70*0Sstevel@tonic-gate is( "$@$!$,$/$\$^W", "1\n0", 'DB::save() should reset punctuation vars' ); 71*0Sstevel@tonic-gate} 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate# test DB::catch() 74*0Sstevel@tonic-gate{ 75*0Sstevel@tonic-gate local $DB::signal; 76*0Sstevel@tonic-gate DB::catch(); 77*0Sstevel@tonic-gate ok( $DB::signal, 'DB::catch() should set $DB::signal' ); 78*0Sstevel@tonic-gate # add clients and test to see if they are awakened 79*0Sstevel@tonic-gate} 80*0Sstevel@tonic-gate 81*0Sstevel@tonic-gate# test DB::_clientname() 82*0Sstevel@tonic-gateis( DB::_clientname('foo=A(1)'), 'foo', 83*0Sstevel@tonic-gate 'DB::_clientname should return refname'); 84*0Sstevel@tonic-gatecmp_ok( DB::_clientname('bar'), 'eq', '', 85*0Sstevel@tonic-gate 'DB::_clientname should not return non refname'); 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate# test DB::next() and DB::step() 88*0Sstevel@tonic-gate{ 89*0Sstevel@tonic-gate local $DB::single; 90*0Sstevel@tonic-gate DB->next(); 91*0Sstevel@tonic-gate is( $DB::single, 2, 'DB->next() should set $DB::single to 2' ); 92*0Sstevel@tonic-gate DB->step(); 93*0Sstevel@tonic-gate is( $DB::single, 1, 'DB->step() should set $DB::single to 1' ); 94*0Sstevel@tonic-gate} 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate# test DB::cont() 97*0Sstevel@tonic-gate{ 98*0Sstevel@tonic-gate # cannot test @stack 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate local $DB::single = 1; 101*0Sstevel@tonic-gate my $fdb = FakeDB->new(); 102*0Sstevel@tonic-gate DB::cont($fdb, 2); 103*0Sstevel@tonic-gate is( $fdb->{tbreak}, 2, 'DB::cont() should set tbreak in object' ); 104*0Sstevel@tonic-gate is( $DB::single, 0, '... should set $DB::single to 0' ); 105*0Sstevel@tonic-gate} 106*0Sstevel@tonic-gate 107*0Sstevel@tonic-gate# test DB::ret() 108*0Sstevel@tonic-gate{ 109*0Sstevel@tonic-gate # cannot test @stack 110*0Sstevel@tonic-gate 111*0Sstevel@tonic-gate local $DB::single = 1; 112*0Sstevel@tonic-gate DB::ret(); 113*0Sstevel@tonic-gate is( $DB::single, 0, 'DB::ret() should set $DB::single to 0' ); 114*0Sstevel@tonic-gate} 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate# test DB::backtrace() 117*0Sstevel@tonic-gate{ 118*0Sstevel@tonic-gate local (@DB::args, $DB::signal); 119*0Sstevel@tonic-gate 120*0Sstevel@tonic-gate my $line = __LINE__ + 1; 121*0Sstevel@tonic-gate my @ret = eval { DB->backtrace() }; 122*0Sstevel@tonic-gate like( $ret[0], qr/file.+\Q$0\E/, 'DB::backtrace() should report current file'); 123*0Sstevel@tonic-gate like( $ret[0], qr/line $line/, '... should report calling line number' ); 124*0Sstevel@tonic-gate like( $ret[0], qr/eval {...}/, '... should catch eval BLOCK' ); 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate @ret = eval "one(2)"; 127*0Sstevel@tonic-gate is( scalar @ret, 1, '... should report from provided stack frame number' ); 128*0Sstevel@tonic-gate like( $ret[0], qr/\@ = &eval \'one.+?2\)\'/, #' 129*0Sstevel@tonic-gate '... should find eval STRING construct'); 130*0Sstevel@tonic-gate $ret[0] = check_context(1); 131*0Sstevel@tonic-gate like( $ret[0], qr/\$ = &main::check_context/, 132*0Sstevel@tonic-gate '... should respect context of calling construct'); 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate $DB::signal = 1; 135*0Sstevel@tonic-gate @DB::args = (1, 7); 136*0Sstevel@tonic-gate @ret = three(1); 137*0Sstevel@tonic-gate is( scalar @ret, 1, '... should end loop if $DB::signal is true' ); 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate # does not check 'require' or @DB::args mangling 140*0Sstevel@tonic-gate} 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gatesub check_context { 143*0Sstevel@tonic-gate return (eval "one($_[0])")[-1]; 144*0Sstevel@tonic-gate} 145*0Sstevel@tonic-gatesub one { DB->backtrace(@_) } 146*0Sstevel@tonic-gatesub two { one(@_) } 147*0Sstevel@tonic-gatesub three { two(@_) } 148*0Sstevel@tonic-gate 149*0Sstevel@tonic-gate# test DB::trace_toggle 150*0Sstevel@tonic-gate{ 151*0Sstevel@tonic-gate local $DB::trace = 0; 152*0Sstevel@tonic-gate DB->trace_toggle; 153*0Sstevel@tonic-gate ok( $DB::trace, 'DB::trace_toggle() should toggle $DB::trace' ); 154*0Sstevel@tonic-gate DB->trace_toggle; 155*0Sstevel@tonic-gate ok( !$DB::trace, '... should toggle $DB::trace (back)' ); 156*0Sstevel@tonic-gate} 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate# test DB::subs() 159*0Sstevel@tonic-gate{ 160*0Sstevel@tonic-gate local %DB::sub; 161*0Sstevel@tonic-gate my $subs = DB->subs; 162*0Sstevel@tonic-gate is( $subs, 0, 'DB::subs() should return keys of %DB::subs' ); 163*0Sstevel@tonic-gate %DB::sub = ( foo => 'foo:23-45' , bar => 'ba:r:7-890' ); 164*0Sstevel@tonic-gate $subs = DB->subs; 165*0Sstevel@tonic-gate is( $subs, 2, '... same song, different key' ); 166*0Sstevel@tonic-gate my @subs = DB->subs( 'foo', 'boo', 'bar' ); 167*0Sstevel@tonic-gate is( scalar @subs, 2, '... should report only for requested subs' ); 168*0Sstevel@tonic-gate my @expected = ( [ 'foo', 23, 45 ], [ 'ba:r', 7, 890 ] ); 169*0Sstevel@tonic-gate ok( eq_array( \@subs, \@expected ), '... find file, start, end for subs' ); 170*0Sstevel@tonic-gate} 171*0Sstevel@tonic-gate 172*0Sstevel@tonic-gate# test DB::filesubs() 173*0Sstevel@tonic-gate{ 174*0Sstevel@tonic-gate local ($DB::filename, %DB::sub); 175*0Sstevel@tonic-gate $DB::filename = 'baz'; 176*0Sstevel@tonic-gate %DB::sub = map { $_ => $_ } qw( bazbar bazboo boobar booboo boobaz ); 177*0Sstevel@tonic-gate my @ret = DB->filesubs(); 178*0Sstevel@tonic-gate is( scalar @ret, 2, 'DB::filesubs() should use $DB::filename with no args'); 179*0Sstevel@tonic-gate @ret = grep { /^baz/ } @ret; 180*0Sstevel@tonic-gate is( scalar @ret, 2, '... should pick up subs in proper file' ); 181*0Sstevel@tonic-gate @ret = DB->filesubs('boo'); 182*0Sstevel@tonic-gate is( scalar @ret, 3, '... should use argument to find subs' ); 183*0Sstevel@tonic-gate @ret = grep { /^boo/ } @ret; 184*0Sstevel@tonic-gate is( scalar @ret, 3, '... should pick up subs in proper file with argument'); 185*0Sstevel@tonic-gate} 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate# test DB::files() 188*0Sstevel@tonic-gate{ 189*0Sstevel@tonic-gate my $dbf = () = DB::files(); 190*0Sstevel@tonic-gate my $main = () = grep ( m!^_<!, keys %main:: ); 191*0Sstevel@tonic-gate is( $dbf, $main, 'DB::files() should pick up filenames from %main::' ); 192*0Sstevel@tonic-gate} 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate# test DB::lines() 195*0Sstevel@tonic-gate{ 196*0Sstevel@tonic-gate local @DB::dbline = ( 'foo' ); 197*0Sstevel@tonic-gate is( DB->lines->[0], 'foo', 'DB::lines() should return ref to @DB::dbline' ); 198*0Sstevel@tonic-gate} 199*0Sstevel@tonic-gate 200*0Sstevel@tonic-gate# test DB::loadfile() 201*0Sstevel@tonic-gateSKIP: { 202*0Sstevel@tonic-gate local (*DB::dbline, $DB::filename); 203*0Sstevel@tonic-gate ok( ! defined DB->loadfile('notafile'), 204*0Sstevel@tonic-gate 'DB::loadfile() should not find unloaded file' ); 205*0Sstevel@tonic-gate my $file = (grep { m|^_<.+\.pm| } keys %main:: )[0]; 206*0Sstevel@tonic-gate skip('cannot find loaded file', 3) unless $file; 207*0Sstevel@tonic-gate $file =~ s/^_<..//; 208*0Sstevel@tonic-gate 209*0Sstevel@tonic-gate my $db = DB->loadfile($file); 210*0Sstevel@tonic-gate like( $db, qr!$file\z!, '... should find loaded file from partial name'); 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate is( *DB::dbline, *{ "_<$db" } , 213*0Sstevel@tonic-gate '... should set *DB::dbline to associated glob'); 214*0Sstevel@tonic-gate is( $DB::filename, $db, '... should set $DB::filename to file name' ); 215*0Sstevel@tonic-gate 216*0Sstevel@tonic-gate # test clients 217*0Sstevel@tonic-gate} 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate# test DB::lineevents() 220*0Sstevel@tonic-gate{ 221*0Sstevel@tonic-gate use vars qw( *baz ); 222*0Sstevel@tonic-gate 223*0Sstevel@tonic-gate local $DB::filename = 'baz'; 224*0Sstevel@tonic-gate local *baz = *{ "main::_<baz" }; 225*0Sstevel@tonic-gate 226*0Sstevel@tonic-gate @baz = map { dualvar(1, $_) } qw( one two three four five ); 227*0Sstevel@tonic-gate %baz = ( 228*0Sstevel@tonic-gate 1 => "foo\0bar", 229*0Sstevel@tonic-gate 3 => "boo\0far", 230*0Sstevel@tonic-gate 4 => "fazbaz", 231*0Sstevel@tonic-gate ); 232*0Sstevel@tonic-gate my %ret = DB->lineevents(); 233*0Sstevel@tonic-gate is( scalar keys %ret, 3, 'DB::lineevents() should pick up defined lines' ); 234*0Sstevel@tonic-gate 235*0Sstevel@tonic-gate # array access in DB::lineevents() starts at element 1, not 0 236*0Sstevel@tonic-gate is( join(' ', @{ $ret{1} }), 'two foo bar', '... should stash data in hash'); 237*0Sstevel@tonic-gate} 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate# test DB::set_break() 240*0Sstevel@tonic-gate{ 241*0Sstevel@tonic-gate local ($DB::lineno, *DB::dbline, $DB::package); 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate %DB::dbline = ( 244*0Sstevel@tonic-gate 1 => "\0", 245*0Sstevel@tonic-gate 2 => undef, 246*0Sstevel@tonic-gate 3 => "123\0\0\0abc", 247*0Sstevel@tonic-gate 4 => "\0abc", 248*0Sstevel@tonic-gate ); 249*0Sstevel@tonic-gate 250*0Sstevel@tonic-gate *DB::dbline = [ $dualfalse, $dualtrue, $dualfalse, $dualfalse, $dualtrue ]; 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate local %DB::sub = ( 253*0Sstevel@tonic-gate 'main::foo' => 'foo:1-4', 254*0Sstevel@tonic-gate ); 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gate DB->set_break(1, 'foo'); 257*0Sstevel@tonic-gate is( $DB::dbline{1}, "foo\0", 'DB::set_break() should set break condition' ); 258*0Sstevel@tonic-gate 259*0Sstevel@tonic-gate $DB::lineno = 1; 260*0Sstevel@tonic-gate DB->set_break(undef, 'bar'); 261*0Sstevel@tonic-gate is( $DB::dbline{1}, "bar\0", 262*0Sstevel@tonic-gate '... should use $DB::lineno without specified line' ); 263*0Sstevel@tonic-gate 264*0Sstevel@tonic-gate DB->set_break(4); 265*0Sstevel@tonic-gate is( $DB::dbline{4}, "1\0abc", '... should use default condition if needed'); 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate local %DB::sub = ( 268*0Sstevel@tonic-gate 'main::foo' => 'foo:1-4', 269*0Sstevel@tonic-gate ); 270*0Sstevel@tonic-gate DB->set_break('foo', 'baz'); 271*0Sstevel@tonic-gate is( $DB::dbline{4}, "baz\0abc", 272*0Sstevel@tonic-gate '... should use _find_subline() to resolve subname' ); 273*0Sstevel@tonic-gate 274*0Sstevel@tonic-gate my $db = FakeDB->new(); 275*0Sstevel@tonic-gate DB::set_break($db, 2); 276*0Sstevel@tonic-gate like( $db->{output}, qr/2 not break/, '... should respect @DB::dbline' ); 277*0Sstevel@tonic-gate 278*0Sstevel@tonic-gate DB::set_break($db, 'nonfoo'); 279*0Sstevel@tonic-gate like( $db->{output}, qr/not found/, '... should warn on unfound sub' ); 280*0Sstevel@tonic-gate} 281*0Sstevel@tonic-gate 282*0Sstevel@tonic-gate# test DB::set_tbreak() 283*0Sstevel@tonic-gate{ 284*0Sstevel@tonic-gate local ($DB::lineno, *DB::dbline, $DB::package); 285*0Sstevel@tonic-gate *DB::dbline = [ $dualfalse, $dualtrue, $dualfalse, $dualfalse, $dualtrue ]; 286*0Sstevel@tonic-gate 287*0Sstevel@tonic-gate DB->set_tbreak(1); 288*0Sstevel@tonic-gate is( $DB::dbline{1}, ';9', 'DB::set_tbreak() should set tbreak condition' ); 289*0Sstevel@tonic-gate 290*0Sstevel@tonic-gate local %DB::sub = ( 291*0Sstevel@tonic-gate 'main::foo' => 'foo:1-4', 292*0Sstevel@tonic-gate ); 293*0Sstevel@tonic-gate DB->set_tbreak('foo', 'baz'); 294*0Sstevel@tonic-gate is( $DB::dbline{4}, ';9', 295*0Sstevel@tonic-gate '... should use _find_subline() to resolve subname' ); 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate my $db = FakeDB->new(); 298*0Sstevel@tonic-gate DB::set_tbreak($db, 2); 299*0Sstevel@tonic-gate like( $db->{output}, qr/2 not break/, '... should respect @DB::dbline' ); 300*0Sstevel@tonic-gate 301*0Sstevel@tonic-gate DB::set_break($db, 'nonfoo'); 302*0Sstevel@tonic-gate like( $db->{output}, qr/not found/, '... should warn on unfound sub' ); 303*0Sstevel@tonic-gate} 304*0Sstevel@tonic-gate 305*0Sstevel@tonic-gate# test DB::_find_subline() 306*0Sstevel@tonic-gate{ 307*0Sstevel@tonic-gate my @foo; 308*0Sstevel@tonic-gate local *{ "::_<foo" } = \@foo; 309*0Sstevel@tonic-gate 310*0Sstevel@tonic-gate local $DB::package; 311*0Sstevel@tonic-gate local %DB::sub = ( 312*0Sstevel@tonic-gate 'TEST::foo' => 'foo:10-15', 313*0Sstevel@tonic-gate 'main::foo' => 'foo:11-12', 314*0Sstevel@tonic-gate 'bar::bar' => 'foo:10-16', 315*0Sstevel@tonic-gate ); 316*0Sstevel@tonic-gate 317*0Sstevel@tonic-gate $foo[11] = $dualtrue; 318*0Sstevel@tonic-gate 319*0Sstevel@tonic-gate is( DB::_find_subline('TEST::foo'), 11, 320*0Sstevel@tonic-gate 'DB::_find_subline() should find fully qualified sub' ); 321*0Sstevel@tonic-gate is( DB::_find_subline("TEST'foo"), 11, '... should handle old package sep'); 322*0Sstevel@tonic-gate is( DB::_find_subline('foo'), 11, 323*0Sstevel@tonic-gate '... should resolve unqualified package name to main::' ); 324*0Sstevel@tonic-gate 325*0Sstevel@tonic-gate $DB::package = 'bar'; 326*0Sstevel@tonic-gate is( DB::_find_subline('bar'), 11, 327*0Sstevel@tonic-gate '... should resolve unqualified name with $DB::package, if defined' ); 328*0Sstevel@tonic-gate 329*0Sstevel@tonic-gate $foo[11] = $dualfalse; 330*0Sstevel@tonic-gate 331*0Sstevel@tonic-gate is( DB::_find_subline('TEST::foo'), 15, 332*0Sstevel@tonic-gate '... should increment past lines with no events' ); 333*0Sstevel@tonic-gate 334*0Sstevel@tonic-gate ok( ! defined DB::_find_subline('sirnotappearinginthisfilm'), 335*0Sstevel@tonic-gate '... should not find nonexistant sub' ); 336*0Sstevel@tonic-gate} 337*0Sstevel@tonic-gate 338*0Sstevel@tonic-gate# test DB::clr_breaks() 339*0Sstevel@tonic-gate{ 340*0Sstevel@tonic-gate local *DB::dbline; 341*0Sstevel@tonic-gate my %lines = ( 342*0Sstevel@tonic-gate 1 => "\0", 343*0Sstevel@tonic-gate 2 => undef, 344*0Sstevel@tonic-gate 3 => "123\0\0\0abc", 345*0Sstevel@tonic-gate 4 => "\0\0\0abc", 346*0Sstevel@tonic-gate ); 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gate %DB::dbline = %lines; 349*0Sstevel@tonic-gate DB->clr_breaks(1 .. 4); 350*0Sstevel@tonic-gate is( scalar keys %DB::dbline, 3, 'DB::clr_breaks() should clear breaks' ); 351*0Sstevel@tonic-gate ok( ! exists($DB::dbline{1}), '... should delete empty actions' ); 352*0Sstevel@tonic-gate is( $DB::dbline{3}, "\0\0\0abc", '... should remove break, leaving action'); 353*0Sstevel@tonic-gate is( $DB::dbline{4}, "\0\0\0abc", '... should not remove set actions' ); 354*0Sstevel@tonic-gate 355*0Sstevel@tonic-gate local *{ "::_<foo" } = [ 0, 0, 0, 1 ]; 356*0Sstevel@tonic-gate 357*0Sstevel@tonic-gate local $DB::package; 358*0Sstevel@tonic-gate local %DB::sub = ( 359*0Sstevel@tonic-gate 'main::foo' => 'foo:1-3', 360*0Sstevel@tonic-gate ); 361*0Sstevel@tonic-gate 362*0Sstevel@tonic-gate %DB::dbline = %lines; 363*0Sstevel@tonic-gate DB->clr_breaks('foo'); 364*0Sstevel@tonic-gate 365*0Sstevel@tonic-gate is( $DB::dbline{3}, "\0\0\0abc", 366*0Sstevel@tonic-gate '... should find lines via _find_subline()' ); 367*0Sstevel@tonic-gate 368*0Sstevel@tonic-gate my $db = FakeDB->new(); 369*0Sstevel@tonic-gate DB::clr_breaks($db, 'abadsubname'); 370*0Sstevel@tonic-gate is( $db->{output}, "Subroutine not found.\n", 371*0Sstevel@tonic-gate '... should output warning if sub cannot be found'); 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gate @DB::dbline = (1 .. 4); 374*0Sstevel@tonic-gate %DB::dbline = (%lines, 5 => "\0" ); 375*0Sstevel@tonic-gate 376*0Sstevel@tonic-gate DB::clr_breaks(); 377*0Sstevel@tonic-gate 378*0Sstevel@tonic-gate is( scalar keys %DB::dbline, 4, 379*0Sstevel@tonic-gate 'Relying on @DB::dbline in DB::clr_breaks() should clear breaks' ); 380*0Sstevel@tonic-gate ok( ! exists($DB::dbline{1}), '... should delete empty actions' ); 381*0Sstevel@tonic-gate is( $DB::dbline{3}, "\0\0\0abc", '... should remove break, leaving action'); 382*0Sstevel@tonic-gate is( $DB::dbline{4}, "\0\0\0abc", '... should not remove set actions' ); 383*0Sstevel@tonic-gate ok( exists($DB::dbline{5}), 384*0Sstevel@tonic-gate '... should only go to last index of @DB::dbline' ); 385*0Sstevel@tonic-gate} 386*0Sstevel@tonic-gate 387*0Sstevel@tonic-gate# test DB::set_action() 388*0Sstevel@tonic-gate{ 389*0Sstevel@tonic-gate local *DB::dbline; 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gate %DB::dbline = ( 392*0Sstevel@tonic-gate 2 => "\0abc", 393*0Sstevel@tonic-gate ); 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gate *DB::dbline = [ $dualfalse, $dualfalse, $dualtrue, $dualtrue ]; 396*0Sstevel@tonic-gate 397*0Sstevel@tonic-gate DB->set_action(2, 'def'); 398*0Sstevel@tonic-gate is( $DB::dbline{2}, "\0def", 399*0Sstevel@tonic-gate 'DB::set_action() should replace existing action' ); 400*0Sstevel@tonic-gate DB->set_action(3, ''); 401*0Sstevel@tonic-gate is( $DB::dbline{3}, "\0", '... should set new action' ); 402*0Sstevel@tonic-gate 403*0Sstevel@tonic-gate my $db = FakeDB->new(); 404*0Sstevel@tonic-gate DB::set_action($db, 'abadsubname'); 405*0Sstevel@tonic-gate is( $db->{output}, "Subroutine not found.\n", 406*0Sstevel@tonic-gate '... should output warning if sub cannot be found'); 407*0Sstevel@tonic-gate 408*0Sstevel@tonic-gate DB::set_action($db, 1); 409*0Sstevel@tonic-gate like( $db->{output}, qr/1 not action/, 410*0Sstevel@tonic-gate '... should warn if line cannot be actionivated' ); 411*0Sstevel@tonic-gate} 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate# test DB::clr_actions() 414*0Sstevel@tonic-gate{ 415*0Sstevel@tonic-gate local *DB::dbline; 416*0Sstevel@tonic-gate my %lines = ( 417*0Sstevel@tonic-gate 1 => "\0", 418*0Sstevel@tonic-gate 2 => undef, 419*0Sstevel@tonic-gate 3 => "123\0abc", 420*0Sstevel@tonic-gate 4 => "abc\0", 421*0Sstevel@tonic-gate ); 422*0Sstevel@tonic-gate 423*0Sstevel@tonic-gate %DB::dbline = %lines; 424*0Sstevel@tonic-gate *DB::dbline = [ ($dualtrue) x 4 ]; 425*0Sstevel@tonic-gate 426*0Sstevel@tonic-gate DB->clr_actions(1 .. 4); 427*0Sstevel@tonic-gate 428*0Sstevel@tonic-gate is( scalar keys %DB::dbline, 2, 'DB::clr_actions() should clear actions' ); 429*0Sstevel@tonic-gate ok( ! exists($DB::dbline{1}), '... should delete empty actions' ); 430*0Sstevel@tonic-gate is( $DB::dbline{3}, "123", '... should remove action, leaving break'); 431*0Sstevel@tonic-gate is( $DB::dbline{4}, "abc\0", '... should not remove set breaks' ); 432*0Sstevel@tonic-gate 433*0Sstevel@tonic-gate local *{ "::_<foo" } = [ 0, 0, 0, 1 ]; 434*0Sstevel@tonic-gate 435*0Sstevel@tonic-gate local $DB::package; 436*0Sstevel@tonic-gate local %DB::sub = ( 437*0Sstevel@tonic-gate 'main::foo' => 'foo:1-3', 438*0Sstevel@tonic-gate ); 439*0Sstevel@tonic-gate 440*0Sstevel@tonic-gate %DB::dbline = %lines; 441*0Sstevel@tonic-gate DB->clr_actions('foo'); 442*0Sstevel@tonic-gate 443*0Sstevel@tonic-gate is( $DB::dbline{3}, "123", '... should find lines via _find_subline()' ); 444*0Sstevel@tonic-gate 445*0Sstevel@tonic-gate my $db = FakeDB->new(); 446*0Sstevel@tonic-gate DB::clr_actions($db, 'abadsubname'); 447*0Sstevel@tonic-gate is( $db->{output}, "Subroutine not found.\n", 448*0Sstevel@tonic-gate '... should output warning if sub cannot be found'); 449*0Sstevel@tonic-gate 450*0Sstevel@tonic-gate @DB::dbline = (1 .. 4); 451*0Sstevel@tonic-gate %DB::dbline = (%lines, 5 => "\0" ); 452*0Sstevel@tonic-gate 453*0Sstevel@tonic-gate DB::clr_actions(); 454*0Sstevel@tonic-gate 455*0Sstevel@tonic-gate is( scalar keys %DB::dbline, 4, 456*0Sstevel@tonic-gate 'Relying on @DB::dbline in DB::clr_actions() should clear actions' ); 457*0Sstevel@tonic-gate ok( ! exists($DB::dbline{1}), '... should delete empty actions' ); 458*0Sstevel@tonic-gate is( $DB::dbline{3}, "123", '... should remove action, leaving break'); 459*0Sstevel@tonic-gate is( $DB::dbline{4}, "abc\0", '... should not remove set breaks' ); 460*0Sstevel@tonic-gate ok( exists($DB::dbline{5}), 461*0Sstevel@tonic-gate '... should only go to last index of @DB::dbline' ); 462*0Sstevel@tonic-gate} 463*0Sstevel@tonic-gate 464*0Sstevel@tonic-gate# test DB::prestop() 465*0Sstevel@tonic-gateok( ! defined DB::prestop('test'), 466*0Sstevel@tonic-gate 'DB::prestop() should return undef for undef value' ); 467*0Sstevel@tonic-gateDB::prestop('test', 897); 468*0Sstevel@tonic-gateis( DB::prestop('test'), 897, '... should return value when set' ); 469*0Sstevel@tonic-gate 470*0Sstevel@tonic-gate# test DB::poststop(), not exactly parallel 471*0Sstevel@tonic-gateok( ! defined DB::poststop('tset'), 472*0Sstevel@tonic-gate 'DB::prestop() should return undef for undef value' ); 473*0Sstevel@tonic-gateDB::poststop('tset', 987); 474*0Sstevel@tonic-gateis( DB::poststop('tset'), 987, '... should return value when set' ); 475*0Sstevel@tonic-gate 476*0Sstevel@tonic-gate# test DB::evalcode() 477*0Sstevel@tonic-gateok( ! defined DB::evalcode('foo'), 478*0Sstevel@tonic-gate 'DB::evalcode() should return undef for undef value' ); 479*0Sstevel@tonic-gate 480*0Sstevel@tonic-gateDB::evalcode('foo', 'bar'); 481*0Sstevel@tonic-gateis( DB::evalcode('foo'), 'bar', '... should return value when set' ); 482*0Sstevel@tonic-gate 483*0Sstevel@tonic-gate# test DB::_outputall(), must create fake clients first 484*0Sstevel@tonic-gateok( DB::register( FakeDB->new() ), 'DB::register() should work' ); 485*0Sstevel@tonic-gateDB::register( FakeDB->new() ) for ( 1 .. 2); 486*0Sstevel@tonic-gate 487*0Sstevel@tonic-gateDB::_outputall(1, 2, 3); 488*0Sstevel@tonic-gateis( $FakeDB::output, '123123123', 489*0Sstevel@tonic-gate 'DB::_outputall() should call output(@_) on all clients' ); 490*0Sstevel@tonic-gate 491*0Sstevel@tonic-gate# test virtual methods 492*0Sstevel@tonic-gatefor my $method (qw( cprestop cpoststop awaken init stop idle cleanup output )) { 493*0Sstevel@tonic-gate ok( defined &{ "DB::$method" }, "DB::$method() should be defined" ); 494*0Sstevel@tonic-gate} 495*0Sstevel@tonic-gate 496*0Sstevel@tonic-gate# DB::skippkg() uses lexical 497*0Sstevel@tonic-gate# DB::ready() uses lexical 498*0Sstevel@tonic-gate 499*0Sstevel@tonic-gatepackage FakeDB; 500*0Sstevel@tonic-gate 501*0Sstevel@tonic-gateuse vars qw( $output ); 502*0Sstevel@tonic-gate 503*0Sstevel@tonic-gatesub new { 504*0Sstevel@tonic-gate bless({}, $_[0]); 505*0Sstevel@tonic-gate} 506*0Sstevel@tonic-gate 507*0Sstevel@tonic-gatesub set_tbreak { 508*0Sstevel@tonic-gate my ($self, $val) = @_; 509*0Sstevel@tonic-gate $self->{tbreak} = $val; 510*0Sstevel@tonic-gate} 511*0Sstevel@tonic-gate 512*0Sstevel@tonic-gatesub output { 513*0Sstevel@tonic-gate my $self = shift; 514*0Sstevel@tonic-gate if (ref $self) { 515*0Sstevel@tonic-gate $self->{output} = join('', @_); 516*0Sstevel@tonic-gate } else { 517*0Sstevel@tonic-gate $output .= join('', @_); 518*0Sstevel@tonic-gate } 519*0Sstevel@tonic-gate} 520