File: zz-plugin-leak.t

package info (click to toggle)
libtemplate-perl 2.27-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 2,632 kB
  • sloc: perl: 14,750; makefile: 11; sh: 5
file content (83 lines) | stat: -rw-r--r-- 2,064 bytes parent folder | download
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
#============================================================= -*-perl-*-
#
# t/zz-plugin-leak.t
#
# Test the Template::Plugins module.
#
# Written by Andy Wardley <abw@wardley.org>
#
# Copyright (C) 1996-2014 Andy Wardley.  All Rights Reserved.
# Copyright (C) 1998-2000 Canon Research Centre Europe Ltd.
#
# This is free software; you can redistribute it and/or modify it
# under the same terms as Perl itself.
#
#========================================================================

use strict;
use lib qw( t/lib ./lib ../lib ../blib/arch );
use Template::Test;
use Template::Plugins;
use Template::Constants qw( :debug );
use Cwd qw( abs_path );
$^W                    = 1;
my $DEBUG = grep(/^--?d(debug)?$/, @ARGV);

BEGIN {
    unless (grep(/--dev/, @ARGV)) {
        skip_all('Internal test for developer, add the --dev flag to run');
    }
    unless ( $ENV{AUTOMATED_TESTING} or $ENV{RELEASE_TESTING} ) {
        skip_all("Developer tests not required for installation");
    }
}

use Test::LeakTrace;

if ($@) {
    skip_all('Test::LeakTrace not installed');
}

ntests(2);

my $dir = abs_path(-d 't' ? 't/test/plugin' : 'test/plugin');
my $src = abs_path(-d 't' ? 't/test/lib'    : 'test/lib');
unshift(@INC, $dir);


my ($input, $output);
$output = '';

# Copy input parsing from Template::Test::test_expect
eval {
    local $/ = undef;
    $input = <DATA>;
};

$input =~ s/^#.*?\n//gm;
$input = $' if $input =~ /\s*--\s*start\s*--\s*/;
$input = $` if $input =~ /\s*--\s*stop\s*--\s*/;


# Declare a processor
my $tt1 = Template->new({
    PLUGIN_BASE  => [ 'MyPlugs', 'Template::Plugin' ],
    INCLUDE_PATH => $src,
    DEBUG => $DEBUG ? DEBUG_PLUGINS : 0,
}) || die Template->error();

# Check whether processing with a double-included filter produces more than 4 leaks.
leaks_cmp_ok {
    $tt1->process(\$input, {}, \$output);
} '<', 4;

# There should be none at all here.
no_leaks_ok {
    $tt1->process(\$input, {}, \$output);
} "No leaks at all";

__END__
[% USE Simple -%]
[% 'world' | simple %]
[% INCLUDE simple2 %]
[% 'hello' | simple %]