File: 01leak.t

package info (click to toggle)
libtest-memorygrowth-perl 0.05-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 152; makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,180 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
#!/usr/bin/perl

use v5.14;
use warnings;

use Test2::V0;
use Test::Builder::Tester;

use Test::MemoryGrowth;

my $l = 10;
my $r = 20;
my $sum;

test_out( "ok 1 - addition does not grow" );
no_growth { $sum = $l + $r } "addition does not grow";
test_test( "no_growth addition succeeds" );

my @arr;
test_out( "not ok 1 - push does not grow" );
test_fail( +12 );
# Process memory growth might not be noticable, depending on Perl version,
# loaded modules, memory ordering, etc..
test_err( qr/(^# Lost \d+ bytes of memory over \d+ calls, average of \d+\.\d\d per call\n)?/ );
if( Test::MemoryGrowth::HAVE_DEVEL_GLADIATOR ) {
   test_err( qr/^# Growths in arena object counts:\n/ );
   test_err( qr/^#   SCALAR \d+ -> \d+ \(1\.00 per call\)\n/ );
}
if( Test::MemoryGrowth::HAVE_DEVEL_MAT_DUMPER ) {
   test_err( qr/^# Writing heap dump to \S+\n/ );
   test_err( qr/^# Writing heap dump after one more iteration to \S+\n/ );
}
no_growth { push @arr, "hello"; } "push does not grow";
test_test( "no_growth push fails" );

done_testing;

END {
   # Clean up Devel::MAT dumpfile
   ( my $basename = $0 ) =~ s/\.t$//;

   -f and unlink for "$basename-1.pmat", "$basename-1-after.pmat";
}