Remove duplicately applied patch shards.
[p5sagit/p5-mst-13.2.git] / t / lib / st-store.t
CommitLineData
7a6a85bf 1#!./perl
2
3# $Id: store.t,v 0.7 2000/08/03 22:04:45 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: store.t,v $
11# Revision 0.7 2000/08/03 22:04:45 ram
12# Baseline for second beta release.
13#
14
15sub BEGIN {
16 chdir('t') if -d 't';
8268a68b 17 unshift @INC, '../lib';
9f233367 18 require Config; import Config;
19 if ($Config{'extensions'} !~ /\bStorable\b/) {
20 print "1..0 # Skip: Storable was not built\n";
21 exit 0;
22 }
7a6a85bf 23 require 'lib/st-dump.pl';
24}
25
26
27use Storable qw(store retrieve store_fd nstore_fd retrieve_fd);
28
29print "1..20\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 store(\@a, 'store');
40print "ok 1\n";
41
42$dumped = &dump(\@a);
43print "ok 2\n";
44
45$root = retrieve('store');
46print "not " unless defined $root;
47print "ok 3\n";
48
49$got = &dump($root);
50print "ok 4\n";
51
52print "not " unless $got eq $dumped;
53print "ok 5\n";
54
29fc1735 551 while unlink 'store';
7a6a85bf 56
57package FOO; @ISA = qw(Storable);
58
59sub make {
60 my $self = bless {};
61 $self->{key} = \%main::a;
62 return $self;
63};
64
65package main;
66
67$foo = FOO->make;
68print "not " unless $foo->store('store');
69print "ok 6\n";
70
71print "not " unless open(OUT, '>>store');
72print "ok 7\n";
73binmode OUT;
74
75print "not " unless defined store_fd(\@a, ::OUT);
76print "ok 8\n";
77print "not " unless defined nstore_fd($foo, ::OUT);
78print "ok 9\n";
79print "not " unless defined nstore_fd(\%a, ::OUT);
80print "ok 10\n";
81
82print "not " unless close(OUT);
83print "ok 11\n";
84
85print "not " unless open(OUT, 'store');
86binmode OUT;
87
88$r = retrieve_fd(::OUT);
89print "not " unless defined $r;
90print "ok 12\n";
91print "not " unless &dump($foo) eq &dump($r);
92print "ok 13\n";
93
94$r = retrieve_fd(::OUT);
95print "not " unless defined $r;
96print "ok 14\n";
97print "not " unless &dump(\@a) eq &dump($r);
98print "ok 15\n";
99
100$r = retrieve_fd(main::OUT);
101print "not " unless defined $r;
102print "ok 16\n";
103print "not " unless &dump($foo) eq &dump($r);
104print "ok 17\n";
105
106$r = retrieve_fd(::OUT);
107print "not " unless defined $r;
108print "ok 18\n";
109print "not " unless &dump(\%a) eq &dump($r);
110print "ok 19\n";
111
112eval { $r = retrieve_fd(::OUT); };
113print "not " unless $@;
114print "ok 20\n";
115
116close OUT;
29fc1735 117END { 1 while unlink 'store' }
7a6a85bf 118
119