Re: [PATCH] another Storable test (Re: perl@16005)
[p5sagit/p5-mst-13.2.git] / ext / Storable / t / forgive.t
1 #!./perl
2
3 # $Id: forgive.t,v 1.0.1.1 2000/09/01 19:40:42 ram Exp $
4 #
5 #  Copyright (c) 1995-2000, Raphael Manfredi
6 #  
7 #  You may redistribute only under the same terms as Perl 5, as specified
8 #  in the README file that comes with the distribution.
9 #
10 # Original Author: Ulrich Pfeifer
11 # (C) Copyright 1997, Universitat Dortmund, all rights reserved.
12 #
13 # $Log: forgive.t,v $
14 # Revision 1.0.1.1  2000/09/01 19:40:42  ram
15 # Baseline for first official release.
16 #
17 # Revision 1.0  2000/09/01 19:40:41  ram
18 # Baseline for first official release.
19 #
20
21 sub BEGIN {
22     if ($] < 5.006) {
23         print "1..0 # Skip: newer File::Spec needed\n";
24         exit 0;
25     }
26     if ($ENV{PERL_CORE}){
27         chdir('t') if -d 't';
28         @INC = '.'; 
29         push @INC, '../lib';
30     }
31     require Config; import Config;
32     if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
33         print "1..0 # Skip: Storable was not built\n";
34         exit 0;
35     }
36 }
37
38 use Storable qw(store retrieve);
39 use File::Spec;
40
41 print "1..8\n";
42
43 my $test = 1;
44 my $bad = ['foo', sub { 1 },  'bar'];
45 my $result;
46
47 eval {$result = store ($bad , 'store')};
48 print ((!defined $result)?"ok $test\n":"not ok $test\n"); $test++;
49 print (($@ ne '')?"ok $test\n":"not ok $test\n"); $test++;
50
51 $Storable::forgive_me=1;
52
53 my $devnull = File::Spec->devnull;
54
55 open(SAVEERR, ">&STDERR");
56 open(STDERR, ">$devnull") or 
57   ( print SAVEERR "Unable to redirect STDERR: $!\n" and exit(1) );
58
59 eval {$result = store ($bad , 'store')};
60
61 open(STDERR, ">&SAVEERR");
62
63 print ((defined $result)?"ok $test\n":"not ok $test\n"); $test++;
64 print (($@ eq '')?"ok $test\n":"not ok $test\n"); $test++;
65
66 my $ret = retrieve('store');
67 print ((defined $ret)?"ok $test\n":"not ok $test\n"); $test++;
68 print (($ret->[0] eq 'foo')?"ok $test\n":"not ok $test\n"); $test++;
69 print (($ret->[2] eq 'bar')?"ok $test\n":"not ok $test\n"); $test++;
70 print ((ref $ret->[1] eq 'SCALAR')?"ok $test\n":"not ok $test\n"); $test++;
71
72
73 END { 1 while unlink 'store' }