make new Storable tests forgiving of places where not built
[p5sagit/p5-mst-13.2.git] / t / lib / st-dclone.t
CommitLineData
7a6a85bf 1#!./perl
2
3# $Id: dclone.t,v 0.7 2000/08/03 22:04:44 ram Exp $
4#
5# Copyright (c) 1995-2000, Raphael Manfredi
6#
7# You may redistribute only under the terms of the Artistic License,
8# as specified in the README file that comes with the distribution.
9#
10# $Log: dclone.t,v $
11# Revision 0.7 2000/08/03 22:04:44 ram
12# Baseline for second beta release.
13#
14
15sub BEGIN {
16 chdir('t') if -d 't';
9f233367 17 require Config; import Config;
18 if ($Config{'extensions'} !~ /\bStorable\b/) {
19 print "1..0 # Skip: Storable was not built\n";
20 exit 0;
21 }
7a6a85bf 22 unshift @INC, '../lib';
23 require 'lib/st-dump.pl';
24}
25
26
27use Storable qw(dclone);
28
29print "1..9\n";
30
31$a = 'toto';
32$b = \$a;
33$c = bless {}, CLASS;
34$c->{attribute} = 'attrval';
35%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
36@a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
37 $b, \$a, $a, $c, \$c, \%a);
38
39print "not " unless defined ($aref = dclone(\@a));
40print "ok 1\n";
41
42$dumped = &dump(\@a);
43print "ok 2\n";
44
45$got = &dump($aref);
46print "ok 3\n";
47
48print "not " unless $got eq $dumped;
49print "ok 4\n";
50
51package FOO; @ISA = qw(Storable);
52
53sub make {
54 my $self = bless {};
55 $self->{key} = \%main::a;
56 return $self;
57};
58
59package main;
60
61$foo = FOO->make;
62print "not " unless defined($r = $foo->dclone);
63print "ok 5\n";
64
65print "not " unless &dump($foo) eq &dump($r);
66print "ok 6\n";
67
68# Ensure refs to "undef" values are properly shared during cloning
69my $hash;
70push @{$$hash{''}}, \$$hash{a};
71print "not " unless $$hash{''}[0] == \$$hash{a};
72print "ok 7\n";
73
74my $cloned = dclone(dclone($hash));
75print "not " unless $$cloned{''}[0] == \$$cloned{a};
76print "ok 8\n";
77
78$$cloned{a} = "blah";
79print "not " unless $$cloned{''}[0] == \$$cloned{a};
80print "ok 9\n";
81