Don't forget to tidy up.
[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';
20822f61 17 @INC = '.';
18 push @INC, '../lib';
9f233367 19 require Config; import Config;
20 if ($Config{'extensions'} !~ /\bStorable\b/) {
21 print "1..0 # Skip: Storable was not built\n";
22 exit 0;
23 }
7a6a85bf 24 require 'lib/st-dump.pl';
25}
26
27
28use Storable qw(store retrieve store_fd nstore_fd retrieve_fd);
29
30print "1..20\n";
31
32$a = 'toto';
33$b = \$a;
34$c = bless {}, CLASS;
35$c->{attribute} = 'attrval';
36%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
37@a = ('first', undef, 3, -4, -3.14159, 456, 4.5,
38 $b, \$a, $a, $c, \$c, \%a);
39
40print "not " unless defined store(\@a, 'store');
41print "ok 1\n";
42
43$dumped = &dump(\@a);
44print "ok 2\n";
45
46$root = retrieve('store');
47print "not " unless defined $root;
48print "ok 3\n";
49
50$got = &dump($root);
51print "ok 4\n";
52
53print "not " unless $got eq $dumped;
54print "ok 5\n";
55
29fc1735 561 while unlink 'store';
7a6a85bf 57
58package FOO; @ISA = qw(Storable);
59
60sub make {
61 my $self = bless {};
62 $self->{key} = \%main::a;
63 return $self;
64};
65
66package main;
67
68$foo = FOO->make;
69print "not " unless $foo->store('store');
70print "ok 6\n";
71
72print "not " unless open(OUT, '>>store');
73print "ok 7\n";
74binmode OUT;
75
76print "not " unless defined store_fd(\@a, ::OUT);
77print "ok 8\n";
78print "not " unless defined nstore_fd($foo, ::OUT);
79print "ok 9\n";
80print "not " unless defined nstore_fd(\%a, ::OUT);
81print "ok 10\n";
82
83print "not " unless close(OUT);
84print "ok 11\n";
85
86print "not " unless open(OUT, 'store');
87binmode OUT;
88
89$r = retrieve_fd(::OUT);
90print "not " unless defined $r;
91print "ok 12\n";
92print "not " unless &dump($foo) eq &dump($r);
93print "ok 13\n";
94
95$r = retrieve_fd(::OUT);
96print "not " unless defined $r;
97print "ok 14\n";
98print "not " unless &dump(\@a) eq &dump($r);
99print "ok 15\n";
100
101$r = retrieve_fd(main::OUT);
102print "not " unless defined $r;
103print "ok 16\n";
104print "not " unless &dump($foo) eq &dump($r);
105print "ok 17\n";
106
107$r = retrieve_fd(::OUT);
108print "not " unless defined $r;
109print "ok 18\n";
110print "not " unless &dump(\%a) eq &dump($r);
111print "ok 19\n";
112
113eval { $r = retrieve_fd(::OUT); };
114print "not " unless $@;
115print "ok 20\n";
116
117close OUT;
29fc1735 118END { 1 while unlink 'store' }
7a6a85bf 119
120