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