File: author-leaks.t

package info (click to toggle)
libmason-perl 2.24-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 720 kB
  • ctags: 245
  • sloc: perl: 4,876; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 1,169 bytes parent folder | download | duplicates (3)
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
#!perl -w

BEGIN {
  unless ($ENV{AUTHOR_TESTING}) {
    require Test::More;
    Test::More::plan(skip_all => 'these tests are for testing by the author');
  }
}

use Devel::LeakGuard::Object qw(leakguard);
use File::Path qw(mkpath);
use File::Temp qw(tempdir);
use Test::Most;
use Mason::Util qw(write_file);
use Mason;

sub testleaks {
    my $code = shift;
    my $report;
    $code->();
    leakguard(
        sub { $code->() },
        only    => 'Mason*',
        on_leak => sub { $report = shift; }
    );
    if ($report) {
        my $desc = join("\n", map { sprintf("%s %d %d", $_, @{ $report->{$_} }) } keys(%$report));
        ok( 0, "leaks found:\n$desc" );
    }
    else {
        ok( 1, "no leaks found" );
    }
}

my $root = tempdir('name-XXXX', TMPDIR => 1, CLEANUP => 1);
my $comp_root = "$root/comps";
my $data_dir = "$root/data";
mkpath( [ $comp_root, $data_dir ], 0, 0775 );

testleaks(
    sub {
        my $interp = Mason->new( comp_root => $comp_root, data_dir => $data_dir );
        foreach my $comp (qw(foo bar)) {
            write_file("$comp_root/$comp.mc", "Hi");
            $interp->run("/$comp");
        }
    }
);

done_testing();