xref: /openbsd/gnu/usr.bin/perl/dist/Storable/t/retrieve.t (revision 5af055cd)
1#!./perl
2#
3#  Copyright (c) 1995-2000, Raphael Manfredi
4#
5#  You may redistribute only under the same terms as Perl 5, as specified
6#  in the README file that comes with the distribution.
7#
8
9sub BEGIN {
10    unshift @INC, 't';
11    unshift @INC, 't/compat' if $] < 5.006002;
12    require Config; import Config;
13    if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
14        print "1..0 # Skip: Storable was not built\n";
15        exit 0;
16    }
17    require 'st-dump.pl';
18}
19
20
21use Storable qw(store retrieve nstore);
22use Test::More tests => 14;
23
24$a = 'toto';
25$b = \$a;
26$c = bless {}, CLASS;
27$c->{attribute} = 'attrval';
28%a = ('key', 'value', 1, 0, $a, $b, 'cvar', \$c);
29@a = ('first', '', undef, 3, -4, -3.14159, 456, 4.5,
30	$b, \$a, $a, $c, \$c, \%a);
31
32isnt(store(\@a, 'store'), undef);
33is(Storable::last_op_in_netorder(), '');
34isnt(nstore(\@a, 'nstore'), undef);
35is(Storable::last_op_in_netorder(), 1);
36is(Storable::last_op_in_netorder(), 1);
37
38$root = retrieve('store');
39isnt($root, undef);
40is(Storable::last_op_in_netorder(), '');
41
42$nroot = retrieve('nstore');
43isnt($root, undef);
44is(Storable::last_op_in_netorder(), 1);
45
46$d1 = &dump($root);
47isnt($d1, undef);
48$d2 = &dump($nroot);
49isnt($d2, undef);
50
51is($d1, $d2);
52
53# Make sure empty string is defined at retrieval time
54isnt($root->[1], undef);
55is(length $root->[1], 0);
56
57END { 1 while unlink('store', 'nstore') }
58