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