3 ##############################################################################
4 # $URL: http://perlcritic.tigris.org/svn/perlcritic/trunk/Perl-Critic/t/92_memory_leaks.t $
5 # $Date: 2008-06-06 00:48:04 -0500 (Fri, 06 Jun 2008) $
8 ##############################################################################
14 use Test::More; #plan set below
16 use Perl::Critic::PolicyFactory (-test => 1);
17 use Perl::Critic::Document;
22 use Perl::Critic::TestUtils qw();
23 Perl::Critic::TestUtils::block_perlcriticrc();
25 eval 'use Test::Memory::Cycle'; ## no critic
26 plan( skip_all => 'Test::Memory::Cycle requried to test memory leaks') if $@;
28 #-----------------------------------------------------------------------------
31 # We have to create and test Perl::Critic::Document for memory leaks
32 # separately because it is not a persistent attribute of the Perl::Critic
33 # object. The current API requires us to create the P::C::Document from
34 # an instance of an existing PPI::Document. In the future, I hope to make
35 # that interface a little more opaque. But this works for now.
37 # Coincidentally, I've discovered that PPI::Documents may or may not
38 # contain circular references, depending on the input code. On some
39 # level, I'm sure this makes perfect sense, but I haven't stopped to think
40 # about it. The particular input we use here does not seem to create
41 # circular references.
43 my $code = q{print foo(); split /this/, $that;};
44 my $ppi_doc = PPI::Document->new( \$code );
45 my $pc_doc = Perl::Critic::Document->new( $ppi_doc );
46 my $critic = Perl::Critic->new( -severity => 1 );
47 my @violations = $critic->critique( $pc_doc );
48 die "No violations were created" if not @violations;
50 # One test for each violation, plus one each for Critic and Document.
51 plan( tests => scalar @violations + 2 );
53 memory_cycle_ok( $pc_doc );
54 memory_cycle_ok( $critic );
55 memory_cycle_ok($_) for @violations;
58 #-----------------------------------------------------------------------------
60 # ensure we run true if this test is loaded by
61 # t/92_memory_leaks.t.without_optional_dependencies.t
64 ###############################################################################
67 # cperl-indent-level: 4
69 # indent-tabs-mode: nil
70 # c-indentation-style: bsd
72 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :