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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#!/usr/bin/perl -T
use constant HAVE_DEVEL_CYCLE => eval { require Devel::Cycle; };
use lib '.'; use lib 't';
use SATest; sa_t_init("memory_cycles");
use Test::More;
plan skip_all => "Devel::Cycle module required for this test" unless HAVE_DEVEL_CYCLE;
plan tests => 4;
use strict;
use Mail::SpamAssassin;
# ---------------------------------------------------------------------------
my $spamtest = Mail::SpamAssassin->new({
rules_filename => $localrules,
site_rules_filename => $siterules,
userprefs_filename => $userrules,
local_tests_only => 1,
debug => 0,
dont_copy_prefs => 1,
});
$spamtest->init(0); # parse rules
ok($spamtest);
open (IN, "<data/spam/009");
my $dataref = [<IN>];
close IN;
my $mail = $spamtest->parse($dataref);
my $status = $spamtest->check($mail);
my $output = $status->get_report();
$status->finish();
ok (check_for_cycles($status));
$mail->finish();
ok (check_for_cycles($mail));
$spamtest->finish();
ok (check_for_cycles($spamtest));
exit;
############################################################################
# Test::Memory::Cycle would be a nice way to do this -- but it relies
# on Test::More. so just do it ourselves.
our $cycles;
sub check_for_cycles {
my $obj = shift;
$cycles = 0;
Devel::Cycle::find_cycle ($obj, \&cyclecb);
if ($cycles) {
print "found $cycles cycles! dump to follow:\n";
Devel::Cycle::find_cycle ($obj); # with default output-to-stdout callback
return 0;
} else {
return 1;
}
}
sub cyclecb {
my $aryref = shift;
$cycles += scalar @{$aryref};
}
|