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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
|
#============================================================= -*-perl-*-
#
# t/leak.t
#
# Attempts to detect memory leaks... but fails. That's a Good Thing
# if it means there are no memory leaks (in this particular aspect)
# or a Bad Thing if it there are, but we're not smart enough to detect
# them. :-)
#
# Written by Andy Wardley <abw@kfs.org>
#
# Copyright (C) 1996-2001 Andy Wardley. All Rights Reserved.
# Copyright (C) 1998-2001 Canon Research Centre Europe Ltd.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
# $Id: leak.t,v 2.4 2001/06/23 08:42:00 abw Exp $
#
#========================================================================
use strict;
use lib qw( ./lib ../lib );
use Template::Test;
$^W = 1;
$Template::Test::PRESERVE = 1;
#$Template::Parser::DEBUG = 1;
#$Template::Directive::PRETTY = 1;
#------------------------------------------------------------------------
package Holler;
use vars qw( $TRACE $PREFIX );
$TRACE = '';
$PREFIX = 'Holler:';
sub new {
my $class = shift;
my $id = shift || '<anon>';
my $self = bless \$id, $class;
$self->trace("created");
return $self;
}
sub trace {
my $self = shift;
$TRACE .= "$$self @_\n";
}
sub clear {
$TRACE = '';
return '';
}
sub DESTROY {
my $self = shift;
$self->trace("destroyed");
}
#------------------------------------------------------------------------
package Plugin::Holler;
use base qw( Template::Plugin );
sub new {
my ($class, $context, @args) = @_;
bless {
context => $context,
holler => Holler->new(@args),
}, $class;
}
sub trace {
my $self = shift;
$self->{ context }->process('trace');
}
#------------------------------------------------------------------------
package main;
my $ttcfg = {
INCLUDE_PATH => -d 't' ? 't/test/src' : 'test/src',
PLUGIN_FACTORY => { holler => 'Plugin::Holler' },
EVAL_PERL => 1,
BLOCKS => {
trace => "TRACE ==[% trace %]==",
},
};
my $ttvars = {
holler => sub { Holler->new(@_) },
trace => sub { $Holler::TRACE },
clear => \&Holler::clear,
v56 => ( $^V && eval '$^V ge v5.6.0' && eval '$^V le v5.7.0' ),
};
test_expect(\*DATA, $ttcfg, $ttvars);
__DATA__
-- test --
[% a = holler('first'); trace %]
-- expect --
first created
-- test --
[% trace %]
-- expect --
first created
first destroyed
-- test --
[% BLOCK shout; a = holler('second'); END -%]
[% clear; PROCESS shout; trace %]
-- expect --
second created
-- test --
[% BLOCK shout; a = holler('third'); END -%]
[% clear; INCLUDE shout; trace %]
-- expect --
third created
third destroyed
-- test --
[% MACRO shout BLOCK; a = holler('fourth'); END -%]
[% clear; shout; trace %]
-- expect --
fourth created
fourth destroyed
-- test --
[% clear; USE holler('holler plugin'); trace %]
-- expect --
holler plugin created
-- test --
[% BLOCK shout; USE holler('process plugin'); END -%]
[% clear; PROCESS shout; holler.trace %]
-- expect --
TRACE ==process plugin created
==
-- test --
[% BLOCK shout; USE holler('include plugin'); END -%]
[% clear; INCLUDE shout; trace %]
-- expect --
include plugin created
include plugin destroyed
-- test --
[% MACRO shout BLOCK; USE holler('macro plugin'); END -%]
[% clear; shout; trace %]
-- expect --
macro plugin created
macro plugin destroyed
-- test --
[% MACRO shout BLOCK;
USE holler('macro plugin');
holler.trace;
END
-%]
[% clear; shout; trace %]
-- expect --
TRACE ==macro plugin created
==macro plugin created
macro plugin destroyed
-- test --
[% clear; PROCESS leak1; trace %]
-- expect --
<leak1>
</leak1>
Hello created
-- test --
[% clear; INCLUDE leak1; trace %]
-- expect --
<leak1>
</leak1>
Hello created
Hello destroyed
-- test --
[% clear; PROCESS leak2; trace %]
-- expect --
<leak2>
</leak2>
Goodbye created
-- test --
[% clear; INCLUDE leak2; trace %]
-- expect --
<leak2>
</leak2>
Goodbye created
Goodbye destroyed
-- test --
[% MACRO leak BLOCK;
PROCESS leak1 + leak2;
USE holler('macro plugin');
END
-%]
[% IF v56;
clear; leak; trace;
ELSE;
"Perl version < 5.6.0 or > 5.7.0, skipping this test";
END
-%]
-- expect --
-- process --
[% IF v56 -%]
<leak1>
</leak1>
<leak2>
</leak2>
Hello created
Goodbye created
macro plugin created
Hello destroyed
Goodbye destroyed
macro plugin destroyed
[% ELSE -%]
Perl version < 5.6.0 or > 5.7.0, skipping this test
[% END -%]
-- test --
[% PERL %]
Holler->clear();
my $h = Holler->new('perl');
$stash->set( h => $h );
[% END -%]
[% trace %]
-- expect --
perl created
-- test --
[% BLOCK x; PERL %]
Holler->clear();
my $h = Holler->new('perl');
$stash->set( h => $h );
[% END; END -%]
[% x; trace %]
-- expect --
perl created
perl destroyed
-- test --
[% MACRO y PERL %]
Holler->clear();
my $h = Holler->new('perl macro');
$stash->set( h => $h );
[% END -%]
[% y; trace %]
-- expect --
perl macro created
perl macro destroyed
|