1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/perl
# I can't make this go with Test::More because we're hooking the symbol table
use vars qw/@CALLED/;
use Devel::CallTrace;
package DB;
sub Devel::CallTrace::called {
my @args = ($_[0], $DB::sub, $_[1]);
push @main::CALLED, \@args;
}
package main;
sub bar {
baz();
}
sub baz {
1;
}
my $return = bar();
package DB;
eval "sub DB::sub {&\$DB::sub};";
package main;
unless( scalar @CALLED == 2 ) { print "not "};
print "ok 1 - There were two calls\n";
unless ($return ==1) { print "not "};
print "ok 2\n";
my $first = shift @CALLED;
unless ($first->[0] == '1') { print "not "};
print "ok 3 - Started with a depth of 1 - ".$first->[0]."\n";
unless ($first->[1] eq 'main::bar') { print "not "};
print "ok 4 - bar was called first: ".$first->[1]."\n";
my $second = shift @CALLED;
unless ($second->[0] == '2') { print "not "};
print "ok 5 - Started with a depth of 2 ".$second->[0]."\n";
unless ($second->[1] eq 'main::baz') { print "not "};
print "ok 6 - baz was called second ".$second->[1]."\n";
print "1..6\n";
1;
|