3 new versions checked in finally.
[urisagit/File-Slurp.git] / t / error_mode.t
CommitLineData
c27bcc50 1##!/usr/local/bin/perl -w
2
3use strict ;
4use File::Slurp ;
5
6use Carp ;
7use Test::More tests => 9 ;
8
9my $file = 'missing/file' ;
8ed110f9 10#unlink $file ;
c27bcc50 11
12
13my %modes = (
14 'croak' => \&test_croak,
15 'carp' => \&test_carp,
16 'quiet' => \&test_quiet,
17) ;
18
19while( my( $mode, $sub ) = each %modes ) {
20
21 $sub->( 'read_file', \&read_file, $file, err_mode => $mode ) ;
22 $sub->( 'write_file', \&write_file, $file,
23 { err_mode => $mode }, 'junk' ) ;
24 $sub->( 'read_dir', \&read_dir, $file, err_mode => $mode ) ;
25}
26
27
28sub test_croak {
29
30 my ( $name, $sub, @args ) = @_ ;
31
32 eval {
33 $sub->( @args ) ;
34 } ;
35
36 ok( $@, "$name can croak" ) ;
37}
38
39sub test_carp {
40
41 my ( $name, $sub, @args ) = @_ ;
42
43 local $SIG{__WARN__} = sub { ok( 1, "$name can carp" ) } ;
44
45 $sub->( @args ) ;
46}
47
48sub test_quiet {
49
50 my ( $name, $sub, @args ) = @_ ;
51
52 local $SIG{__WARN__} = sub { ok( 0, "$name can be quiet" ) } ;
53
54 eval {
55 $sub->( @args ) ;
56 } ;
57
58 ok( !$@, "$name can be quiet" ) ;
59}