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