Fix a precedence problem.
[p5sagit/p5-mst-13.2.git] / ext / Storable / t / forgive.t
CommitLineData
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#
8# Original Author: Ulrich Pfeifer
9# (C) Copyright 1997, Universitat Dortmund, all rights reserved.
10#
7a6a85bf 11
12sub BEGIN {
0c384302 13 if ($ENV{PERL_CORE}){
14 chdir('t') if -d 't';
372cb964 15 @INC = ('.', '../lib');
16 } else {
17 unshift @INC, 't';
18 }
9f233367 19 require Config; import Config;
0c384302 20 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367 21 print "1..0 # Skip: Storable was not built\n";
22 exit 0;
23 }
7a6a85bf 24}
25
26use Storable qw(store retrieve);
372cb964 27
197b90bc 28# problems with 5.00404 when in an BEGIN block, so this is defined here
29if (eval { require File::Spec; 1 } || $File::Spec::VERSION < 0.8) {
30 print "1..0 # Skip: File::Spec 0.8 needed\n";
31 exit 0;
32}
7a6a85bf 33
34print "1..8\n";
35
36my $test = 1;
464b080a 37*GLOB = *GLOB; # peacify -w
38my $bad = ['foo', \*GLOB, 'bar'];
7a6a85bf 39my $result;
40
41eval {$result = store ($bad , 'store')};
42print ((!defined $result)?"ok $test\n":"not ok $test\n"); $test++;
43print (($@ ne '')?"ok $test\n":"not ok $test\n"); $test++;
44
45$Storable::forgive_me=1;
46
29fc1735 47my $devnull = File::Spec->devnull;
48
7a6a85bf 49open(SAVEERR, ">&STDERR");
f42118b2 50open(STDERR, ">$devnull") or
7a6a85bf 51 ( print SAVEERR "Unable to redirect STDERR: $!\n" and exit(1) );
52
53eval {$result = store ($bad , 'store')};
54
55open(STDERR, ">&SAVEERR");
56
57print ((defined $result)?"ok $test\n":"not ok $test\n"); $test++;
58print (($@ eq '')?"ok $test\n":"not ok $test\n"); $test++;
59
60my $ret = retrieve('store');
61print ((defined $ret)?"ok $test\n":"not ok $test\n"); $test++;
62print (($ret->[0] eq 'foo')?"ok $test\n":"not ok $test\n"); $test++;
63print (($ret->[2] eq 'bar')?"ok $test\n":"not ok $test\n"); $test++;
64print ((ref $ret->[1] eq 'SCALAR')?"ok $test\n":"not ok $test\n"); $test++;
65
66
29fc1735 67END { 1 while unlink 'store' }