File: zz-plugin-cycle.t

package info (click to toggle)
libtemplate-perl 3.102-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,680 kB
  • sloc: perl: 14,945; makefile: 11; sh: 5
file content (77 lines) | stat: -rw-r--r-- 1,641 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
#============================================================= -*-perl-*-
#
# t/zz-plugin-cycle.t
#
# Check for memory leak when using Template::Plugin::Simple
#
# Written by Nicolas R. <atoomic@cpan.org>
#
# Copyright (C) 2018 cPanel Inc.  All Rights Reserved.
#
# 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;
use Template::Plugin::Simple;

use Test::More;

plan skip_all => "Developer test" unless ( $ENV{AUTOMATED_TESTING} or $ENV{RELEASE_TESTING} );

eval { require Test::LeakTrace };
if ( $@ or !$INC{'Test/LeakTrace.pm'} ) {
    plan skip_all => 'Test::LeakTrace not installed';
}

plan tests => 2;

note "plugin_simple_test();";

ok plugin_simple_test(), "plugin_simple_test";

note "Searching for leak using Test::LeakTrace...";


my $no_leaks = Test::LeakTrace::no_leaks_ok( \&plugin_simple_test, 'no leak from Template::Plugin' );

if ( !$no_leaks ) {
    diag "Memory leak detected...";

    if ( eval { require Devel::Cycle; 1 } ) {
        Devel::Cycle::find_cycle( plugin_simple_test() );
    }
    else {
        diag "consider installing Devel::Cycle to detect leak";
    }
}

exit;

sub plugin_simple_test {
    my $tpl = Template->new({
        PLUGIN_BASE => [ 'test' ],
        DEBUG => 1,
    }) or die;
    $tpl->context->plugin( 'Simple', [] );

    return $tpl;
}

package test::Simple;

sub new {
    my ($pkg) = @_;
    return bless {}, $pkg;
}

sub load {
    my $class   = shift;
    return $class;
}

1;