Modified source files and compiled any and armel versions of packages
[pkg-perl] / deb-src / libperl-critic-perl / libperl-critic-perl-1.088 / t / 92_memory_leaks.t
1 #!perl
2
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) $
6 #   $Author: clonezone $
7 # $Revision: 2416 $
8 ##############################################################################
9
10 use 5.006001;
11 use strict;
12 use warnings;
13
14 use Test::More; #plan set below
15
16 use Perl::Critic::PolicyFactory (-test => 1);
17 use Perl::Critic::Document;
18 use Perl::Critic;
19
20 use PPI::Document;
21
22 use Perl::Critic::TestUtils qw();
23 Perl::Critic::TestUtils::block_perlcriticrc();
24
25 eval 'use Test::Memory::Cycle'; ## no critic
26 plan( skip_all => 'Test::Memory::Cycle requried to test memory leaks') if $@;
27
28 #-----------------------------------------------------------------------------
29 {
30
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.
36
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.
42
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;
49
50     # One test for each violation, plus one each for Critic and Document.
51     plan( tests => scalar @violations + 2 );
52
53     memory_cycle_ok( $pc_doc );
54     memory_cycle_ok( $critic );
55     memory_cycle_ok($_) for @violations;
56 }
57
58 #-----------------------------------------------------------------------------
59
60 # ensure we run true if this test is loaded by
61 # t/92_memory_leaks.t.without_optional_dependencies.t
62 1;
63
64 ###############################################################################
65 # Local Variables:
66 #   mode: cperl
67 #   cperl-indent-level: 4
68 #   fill-column: 78
69 #   indent-tabs-mode: nil
70 #   c-indentation-style: bsd
71 # End:
72 # ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :