File: 12_leaktrace.t

package info (click to toggle)
libhash-fieldhash-perl 0.15-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 296 kB
  • sloc: perl: 1,249; ansic: 207; makefile: 10
file content (56 lines) | stat: -rw-r--r-- 818 bytes parent folder | download | duplicates (7)
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
#!perl -w

use strict;

use constant HAS_LEAKTRACE => eval q{use Test::LeakTrace 0.07; 1};
use Test::More HAS_LEAKTRACE ? (tests => 5) : (skip_all => 'require Test::LeakTrace');

use Hash::FieldHash qw(:all);

my %hash;
{
	package A;
	use Hash::FieldHash qw(:all);

	fieldhash %hash, 'foo';

	sub new{
		my $class = shift;
		my $obj = bless do{ \my $o }, $class;
		return Hash::FieldHash::from_hash($obj, {@_});
	}
}


no_leaks_ok{
	my $x = A->new();
	my $y = A->new();

	$hash{$x} = 'Hello';
	$hash{$y} = 0.5;
	$hash{$y}++ for 1 .. 10;
};

is_deeply \%hash, {};

no_leaks_ok{
	my $x = A->new(foo => 10);
	my $y = A->new(foo => 100);

	$x->foo($x->foo+1);
	$y->foo($y->foo+1);
};
is_deeply \%hash, {};


no_leaks_ok{
	fieldhash my %h;

	for(1){
		my $o = [42];
		my $p = [3.14];
		$h{$o} = 100;
		$h{$p} = 200;
	}
};