This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Uncomment and fix up tests at the end of Storable's blessed.t
[perl5.git] / dist / Storable / t / forgive.t
CommitLineData
7a6a85bf 1#!./perl
7a6a85bf
RG
2#
3# Copyright (c) 1995-2000, Raphael Manfredi
4#
9e21b3d0
JH
5# You may redistribute only under the same terms as Perl 5, as specified
6# in the README file that comes with the distribution.
7a6a85bf
RG
7#
8# Original Author: Ulrich Pfeifer
9# (C) Copyright 1997, Universitat Dortmund, all rights reserved.
10#
7a6a85bf
RG
11
12sub BEGIN {
48c887dd 13 unshift @INC, 't';
9f233367 14 require Config; import Config;
0c384302 15 if ($ENV{PERL_CORE} and $Config{'extensions'} !~ /\bStorable\b/) {
9f233367
PP
16 print "1..0 # Skip: Storable was not built\n";
17 exit 0;
18 }
7a6a85bf
RG
19}
20
21use Storable qw(store retrieve);
372cb964 22
197b90bc 23# problems with 5.00404 when in an BEGIN block, so this is defined here
87baa35a 24if (!eval { require File::Spec; 1 } || $File::Spec::VERSION < 0.8) {
197b90bc
SR
25 print "1..0 # Skip: File::Spec 0.8 needed\n";
26 exit 0;
a2307be4
NC
27 # Mention $File::Spec::VERSION again, as 5.00503's harness seems to have
28 # warnings on.
29 exit $File::Spec::VERSION;
197b90bc 30}
7a6a85bf
RG
31
32print "1..8\n";
33
34my $test = 1;
464b080a
SR
35*GLOB = *GLOB; # peacify -w
36my $bad = ['foo', \*GLOB, 'bar'];
7a6a85bf
RG
37my $result;
38
39eval {$result = store ($bad , 'store')};
40print ((!defined $result)?"ok $test\n":"not ok $test\n"); $test++;
41print (($@ ne '')?"ok $test\n":"not ok $test\n"); $test++;
42
43$Storable::forgive_me=1;
44
29fc1735
JH
45my $devnull = File::Spec->devnull;
46
7a6a85bf 47open(SAVEERR, ">&STDERR");
f42118b2 48open(STDERR, ">$devnull") or
7a6a85bf
RG
49 ( print SAVEERR "Unable to redirect STDERR: $!\n" and exit(1) );
50
51eval {$result = store ($bad , 'store')};
52
53open(STDERR, ">&SAVEERR");
54
55print ((defined $result)?"ok $test\n":"not ok $test\n"); $test++;
56print (($@ eq '')?"ok $test\n":"not ok $test\n"); $test++;
57
58my $ret = retrieve('store');
59print ((defined $ret)?"ok $test\n":"not ok $test\n"); $test++;
60print (($ret->[0] eq 'foo')?"ok $test\n":"not ok $test\n"); $test++;
61print (($ret->[2] eq 'bar')?"ok $test\n":"not ok $test\n"); $test++;
62print ((ref $ret->[1] eq 'SCALAR')?"ok $test\n":"not ok $test\n"); $test++;
63
64
29fc1735 65END { 1 while unlink 'store' }