File: 04reftypes.t

package info (click to toggle)
libtest-refcount-perl 0.10-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 136 kB
  • sloc: perl: 211; makefile: 2
file content (40 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl

use strict;
use warnings;

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

use Symbol qw( gensym );

use Test::Refcount;

my %refs = (
   SCALAR => do { my $var; \$var },
   ARRAY  => [],
   HASH   => +{},
   # This magic is to ensure the code ref is new, not shared. To be a new one
   # it has to contain a unique pad.
   CODE   => do { my $var; sub { $var } },
   GLOB   => gensym(),
   Regex  => qr/foo/,
);

foreach my $type (qw( SCALAR ARRAY HASH CODE GLOB Regex )) {
   SKIP: {
      if( $type eq "Regex" and $] >= 5.011 ) {
         # Perl v5.11 seems to have odd behaviour with Regexp references. They start
         # off with a refcount of 2. Not sure if this is a bug in Perl, or my
         # assumption. Until P5P have worked it out, we'll skip this. See also
         # similar skip logic in Devel-Refcount's tests
         skip "Bleadperl", 1;
      }

      test_out( "ok 1 - anon $type ref" );
      is_refcount( $refs{$type}, 1, "anon $type ref" );
      test_test( "anon $type ref succeeds" );
   }
}

done_testing;