summaryrefslogtreecommitdiff
path: root/dist/Storable/t/boolean.t
blob: 9ba19c0e67a12ec60b8d587afebdf2dc0993da6e (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
use strict;
use warnings;

my $true_ref;
my $false_ref;
BEGIN {
    $true_ref = \!!1;
    $false_ref = \!!0;
}

BEGIN {
    unshift @INC, 't';
    unshift @INC, 't/compat' if $] < 5.006002;
    require Config;
    if ($ENV{PERL_CORE} and $Config::Config{'extensions'} !~ /\bStorable\b/) {
        print "1..0 # Skip: Storable was not built\n";
        exit 0;
    }
}

use Test::More tests => 12;
use Storable qw(thaw freeze);

use constant CORE_BOOLS => defined &builtin::is_bool;

{
  my $x = $true_ref;
  my $y = ${thaw freeze \$x};
  is($y, $x);
  eval {
    $$y = 2;
  };
  isnt $@, '',
    'immortal true maintained as immortal';
}

{
  my $x = $false_ref;
  my $y = ${thaw freeze \$x};
  is($y, $x);
  eval {
    $$y = 2;
  };
  isnt $@, '',
    'immortal false maintained as immortal';
}

{
  my $true = $$true_ref;
  my $x = \$true;
  my $y = ${thaw freeze \$x};
  is($$y, $$x);
  is($$y, '1');
  SKIP: {
    skip "perl $] does not support tracking boolean values", 1
      unless CORE_BOOLS;
    BEGIN { CORE_BOOLS and warnings->unimport('experimental::builtin') }
    ok builtin::is_bool($$y);
  }
  eval {
    $$y = 2;
  };
  is $@, '',
    'mortal true maintained as mortal';
}

{
  my $false = $$false_ref;
  my $x = \$false;
  my $y = ${thaw freeze \$x};
  is($$y, $$x);
  is($$y, '');
  SKIP: {
    skip "perl $] does not support tracking boolean values", 1
      unless CORE_BOOLS;
    BEGIN { CORE_BOOLS and warnings->unimport('experimental::builtin') }
    ok builtin::is_bool($$y);
  }
  eval {
    $$y = 2;
  };
  is $@, '',
    'mortal true maintained as mortal';
}