Fix (comment) typo pointed out by Robin Barker
[p5sagit/p5-mst-13.2.git] / dist / Storable / t / store.t
CommitLineData
7a6a85bf 1#!./perl
7a6a85bf 2#
3# Copyright (c) 1995-2000, Raphael Manfredi
4#
9e21b3d0 5# You may redistribute only under the same terms as Perl 5, as specified
6# in the README file that comes with the distribution.
7a6a85bf 7#
7a6a85bf 8
9sub BEGIN {
48c887dd 10 unshift @INC, 't';
9f233367 11 require Config; import Config;
0c384302 12 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367 13 print "1..0 # Skip: Storable was not built\n";
14 exit 0;
15 }
372cb964 16 require 'st-dump.pl';
7a6a85bf 17}
18
9e21b3d0 19use Storable qw(store retrieve store_fd nstore_fd fd_retrieve);
7a6a85bf 20
21print "1..20\n";
22
23$a = 'toto';
24$b = \$a;
25$c = bless {}, CLASS;
26$c->{attribute} = 'attrval';
27%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
28@a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
29 $b, \$a, $a, $c, \$c, \%a);
30
31print "not " unless defined store(\@a, 'store');
32print "ok 1\n";
33
34$dumped = &dump(\@a);
35print "ok 2\n";
36
37$root = retrieve('store');
38print "not " unless defined $root;
39print "ok 3\n";
40
41$got = &dump($root);
42print "ok 4\n";
43
44print "not " unless $got eq $dumped;
45print "ok 5\n";
46
29fc1735 471 while unlink 'store';
7a6a85bf 48
49package FOO; @ISA = qw(Storable);
50
51sub make {
52 my $self = bless {};
53 $self->{key} = \%main::a;
54 return $self;
55};
56
57package main;
58
59$foo = FOO->make;
60print "not " unless $foo->store('store');
61print "ok 6\n";
62
63print "not " unless open(OUT, '>>store');
64print "ok 7\n";
65binmode OUT;
66
67print "not " unless defined store_fd(\@a, ::OUT);
68print "ok 8\n";
69print "not " unless defined nstore_fd($foo, ::OUT);
70print "ok 9\n";
71print "not " unless defined nstore_fd(\%a, ::OUT);
72print "ok 10\n";
73
74print "not " unless close(OUT);
75print "ok 11\n";
76
77print "not " unless open(OUT, 'store');
78binmode OUT;
79
9e21b3d0 80$r = fd_retrieve(::OUT);
7a6a85bf 81print "not " unless defined $r;
82print "ok 12\n";
83print "not " unless &dump($foo) eq &dump($r);
84print "ok 13\n";
85
9e21b3d0 86$r = fd_retrieve(::OUT);
7a6a85bf 87print "not " unless defined $r;
88print "ok 14\n";
89print "not " unless &dump(\@a) eq &dump($r);
90print "ok 15\n";
91
9e21b3d0 92$r = fd_retrieve(main::OUT);
7a6a85bf 93print "not " unless defined $r;
94print "ok 16\n";
95print "not " unless &dump($foo) eq &dump($r);
96print "ok 17\n";
97
9e21b3d0 98$r = fd_retrieve(::OUT);
7a6a85bf 99print "not " unless defined $r;
100print "ok 18\n";
101print "not " unless &dump(\%a) eq &dump($r);
102print "ok 19\n";
103
9e21b3d0 104eval { $r = fd_retrieve(::OUT); };
7a6a85bf 105print "not " unless $@;
106print "ok 20\n";
107
d1e4d418 108close OUT or die "Could not close: $!";
29fc1735 109END { 1 while unlink 'store' }