Skip to content

Commit

Permalink
Tests for custom callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfsage committed Jun 10, 2011
1 parent 9c59284 commit eec0fb2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
17 changes: 16 additions & 1 deletion t/01-runtime-control.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use warnings;

use Test::More;

plan tests => 9;
plan tests => 13;

use Config;

Expand Down Expand Up @@ -59,3 +59,18 @@ like($output, qr/^>> \d+ main, .*mem_enable.pl \(10\) used 2048 bytes$/m,

like($output, qr/hello world/, 'program ran successfully');

# Test custom callback
$ENV{MEMORYTRACE_LIGHT} = $p_arg;

$output = `$perlbin $includes -d:MemoryTrace::Light t/bin/mem_callback.pl 2>&1`;

like($output, qr/^>> \d+ main, .*mem_callback.pl \(12\) used 1 bytes$/m,
'program printed default trace output');

like($output, qr/^I caught main .*mem_callback.pl 16 2 !$/m,
'program printed custom callback output after set_callback');

like($output, qr/^>> \d+ main, .*mem_callback.pl \(20\) used 4 bytes$/m,
'program printed default trace output after restore_callback');

like($output, qr/hello world/, 'program ran successfully');
22 changes: 22 additions & 0 deletions t/bin/mem_callback.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Basic callback test case
use lib 't/lib/';

use Devel::MemoryTrace::Light;

use DMTraceProviderNextMem;

sub c_callback {
print "I caught @_ !\n";
}

$DMTraceProviderNextMem::mem = 1;

DB::set_callback(\&c_callback);

$DMTraceProviderNextMem::mem += 2;

DB::restore_callback();

$DMTraceProviderNextMem::mem += 4;

print "hello world\n";

0 comments on commit eec0fb2

Please sign in to comment.