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