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