summaryrefslogtreecommitdiff
path: root/t/release-memory-leak.t
blob: 0543aabf0b39e62e8eca9464f72d10c522482596 (plain)
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

BEGIN {
  unless ($ENV{RELEASE_TESTING}) {
    require Test::More;
    Test::More::plan(skip_all => 'these tests are for release candidate testing');
  }
}

use strict;
use warnings;

use Test::More;

BEGIN {
    plan skip_all => q{Test::LeakTrace doesn't install with blead (as of 5.21.8)}
        if $] >= 5.021008;
}

use Test::LeakTrace qw( no_leaks_ok );

use Params::Validate qw( validate );

subtest(
    'callback with default error' => sub {
        no_leaks_ok( sub { val1( foo => 42 ); }, 'validation passes' );
        local $TODO = 'Not sure if all the leaks are in Carp or not';
        no_leaks_ok(
            sub {
                eval { val1( foo => 'forty two' ) };
            },
            'validation fails'
        );
    },
);

subtest(
    'callback that dies with string' => sub {
        no_leaks_ok( sub { val2( foo => 42 ); }, 'validation passes' );
        local $TODO = 'Not sure if all the leaks are in Carp or not';
        no_leaks_ok(
            sub {
                eval { val2( foo => 'forty two' ) };
            },
            'validation fails'
        );
    },
);

subtest(
    'callback that dies with object' => sub {
        no_leaks_ok( sub { val3( foo => 42 ); }, 'validation passes' );
        no_leaks_ok(
            sub {
                eval { val3( foo => 'forty two' ) };
            },
            'validation fails'
        );
    },
);

done_testing();

sub val1 {
    validate(
        @_,
        {
            foo => {
                callbacks => {
                    'is int' => sub { $_[0] =~ /^[0-9]+$/ }
                }
            },
        },
    );
}

sub val2 {
    validate(
        @_,
        {
            foo => {
                callbacks => {
                    'is int' => sub {
                        $_[0] =~ /^[0-9]+$/ or die "$_[0] is not an integer";
                    }
                }
            },
        },
    );
}

sub val3 {
    validate(
        @_,
        {
            foo => {
                callbacks => {
                    'is int' => sub {
                        $_[0] =~ /^[0-9]+$/
                            or die { error => "$_[0] is not an integer" };
                    }
                }
            },
        },
    );
}