Commit | Line | Data |
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 | |
9 | sub 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 |
19 | use Storable qw(store retrieve store_fd nstore_fd fd_retrieve); |
7a6a85bf |
20 | |
21 | print "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 | |
31 | print "not " unless defined store(\@a, 'store'); |
32 | print "ok 1\n"; |
33 | |
34 | $dumped = &dump(\@a); |
35 | print "ok 2\n"; |
36 | |
37 | $root = retrieve('store'); |
38 | print "not " unless defined $root; |
39 | print "ok 3\n"; |
40 | |
41 | $got = &dump($root); |
42 | print "ok 4\n"; |
43 | |
44 | print "not " unless $got eq $dumped; |
45 | print "ok 5\n"; |
46 | |
29fc1735 |
47 | 1 while unlink 'store'; |
7a6a85bf |
48 | |
49 | package FOO; @ISA = qw(Storable); |
50 | |
51 | sub make { |
52 | my $self = bless {}; |
53 | $self->{key} = \%main::a; |
54 | return $self; |
55 | }; |
56 | |
57 | package main; |
58 | |
59 | $foo = FOO->make; |
60 | print "not " unless $foo->store('store'); |
61 | print "ok 6\n"; |
62 | |
63 | print "not " unless open(OUT, '>>store'); |
64 | print "ok 7\n"; |
65 | binmode OUT; |
66 | |
67 | print "not " unless defined store_fd(\@a, ::OUT); |
68 | print "ok 8\n"; |
69 | print "not " unless defined nstore_fd($foo, ::OUT); |
70 | print "ok 9\n"; |
71 | print "not " unless defined nstore_fd(\%a, ::OUT); |
72 | print "ok 10\n"; |
73 | |
74 | print "not " unless close(OUT); |
75 | print "ok 11\n"; |
76 | |
77 | print "not " unless open(OUT, 'store'); |
78 | binmode OUT; |
79 | |
9e21b3d0 |
80 | $r = fd_retrieve(::OUT); |
7a6a85bf |
81 | print "not " unless defined $r; |
82 | print "ok 12\n"; |
83 | print "not " unless &dump($foo) eq &dump($r); |
84 | print "ok 13\n"; |
85 | |
9e21b3d0 |
86 | $r = fd_retrieve(::OUT); |
7a6a85bf |
87 | print "not " unless defined $r; |
88 | print "ok 14\n"; |
89 | print "not " unless &dump(\@a) eq &dump($r); |
90 | print "ok 15\n"; |
91 | |
9e21b3d0 |
92 | $r = fd_retrieve(main::OUT); |
7a6a85bf |
93 | print "not " unless defined $r; |
94 | print "ok 16\n"; |
95 | print "not " unless &dump($foo) eq &dump($r); |
96 | print "ok 17\n"; |
97 | |
9e21b3d0 |
98 | $r = fd_retrieve(::OUT); |
7a6a85bf |
99 | print "not " unless defined $r; |
100 | print "ok 18\n"; |
101 | print "not " unless &dump(\%a) eq &dump($r); |
102 | print "ok 19\n"; |
103 | |
9e21b3d0 |
104 | eval { $r = fd_retrieve(::OUT); }; |
7a6a85bf |
105 | print "not " unless $@; |
106 | print "ok 20\n"; |
107 | |
d1e4d418 |
108 | close OUT or die "Could not close: $!"; |
29fc1735 |
109 | END { 1 while unlink 'store' } |