File: memory.t

package info (click to toggle)
libtest-deep-perl 0.113-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 464 kB
  • ctags: 254
  • sloc: perl: 2,144; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 643 bytes parent folder | download | duplicates (4)
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
use strict;
use warnings;

use Test::Tester;
use Test::More;

BEGIN
{
  require Scalar::Util;
  if (grep /^weaken$/, @Scalar::Util::EXPORT_FAIL)
  {
    plan(skip_all => "no weak refs in this version of perl");
    exit(0);
  }
}

use t::std;

use Scalar::Util qw( isweak weaken);

sub left
{
  my $ref = shift;
  eq_deeply($ref, []);
  return "left";
}

sub right
{
  my $ref = shift;
  eq_deeply([], $ref);
  return "right";
}

my @subs = (\&left, \&right);
for my $sub (@subs)
{
  my $ref = [];

  my $weak = $ref;
  weaken($weak);
  my $side = &$sub($ref, []);
  $ref = 1;
  ok((! $weak), "$side didn't capture") || diag "weak = $weak";
}