Lots of spring cleaning. (No functional changes.)
[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#
7a6a85bf 13
14sub BEGIN {
0c384302 15 if ($ENV{PERL_CORE}){
16 chdir('t') if -d 't';
372cb964 17 @INC = ('.', '../lib');
18 } else {
19 unshift @INC, 't';
20 }
21 require File::Spec;
22 if ($File::Spec::VERSION < 0.8) {
23 print "1..0 # Skip: newer File::Spec needed\n";
24 exit 0;
0c384302 25 }
9f233367 26 require Config; import Config;
0c384302 27 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367 28 print "1..0 # Skip: Storable was not built\n";
29 exit 0;
30 }
7a6a85bf 31}
32
33use Storable qw(store retrieve);
372cb964 34
7a6a85bf 35
36print "1..8\n";
37
38my $test = 1;
39my $bad = ['foo', sub { 1 }, 'bar'];
40my $result;
41
42eval {$result = store ($bad , 'store')};
43print ((!defined $result)?"ok $test\n":"not ok $test\n"); $test++;
44print (($@ ne '')?"ok $test\n":"not ok $test\n"); $test++;
45
46$Storable::forgive_me=1;
47
29fc1735 48my $devnull = File::Spec->devnull;
49
7a6a85bf 50open(SAVEERR, ">&STDERR");
f42118b2 51open(STDERR, ">$devnull") or
7a6a85bf 52 ( print SAVEERR "Unable to redirect STDERR: $!\n" and exit(1) );
53
54eval {$result = store ($bad , 'store')};
55
56open(STDERR, ">&SAVEERR");
57
58print ((defined $result)?"ok $test\n":"not ok $test\n"); $test++;
59print (($@ eq '')?"ok $test\n":"not ok $test\n"); $test++;
60
61my $ret = retrieve('store');
62print ((defined $ret)?"ok $test\n":"not ok $test\n"); $test++;
63print (($ret->[0] eq 'foo')?"ok $test\n":"not ok $test\n"); $test++;
64print (($ret->[2] eq 'bar')?"ok $test\n":"not ok $test\n"); $test++;
65print ((ref $ret->[1] eq 'SCALAR')?"ok $test\n":"not ok $test\n"); $test++;
66
67
29fc1735 68END { 1 while unlink 'store' }