File: 13_leaktrace_thr.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 (48 lines) | stat: -rw-r--r-- 681 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
#!perl -w

use strict;

use constant HAS_THREADS   => eval q{ use threads; 1 };
use constant HAS_LEAKTRACE => eval q{use Test::LeakTrace 0.06; 1};
use Test::More;

BEGIN{
	if(HAS_THREADS && HAS_LEAKTRACE){
		plan tests => 2;
	}
	else{
		plan skip_all => 'require both threads and Test::LeakTrace';
	}
}
use Hash::FieldHash qw(:all);


{
	package A;

	sub new{
		bless [], shift;
	}
}


fieldhash my %hash;

leaks_cmp_ok{
	# NOTE: weaken({}) leaks an AV in 5.10.0, so I use [] in here.
	my $x = A->new();
	my $y = A->new();

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

	async{
		my $z = ['thx'];
		$hash{$z}++;
	}->join();

	
} '<=', 1;

is_deeply \%hash, {};