Commit | Line | Data |
c27bcc50 |
1 | ##!/usr/local/bin/perl -w |
2 | |
3 | use strict ; |
4 | use File::Slurp ; |
5 | |
6 | use Carp ; |
7 | use Test::More tests => 9 ; |
8 | |
9 | my $file = 'missing/file' ; |
8ed110f9 |
10 | #unlink $file ; |
c27bcc50 |
11 | |
12 | |
13 | my %modes = ( |
14 | 'croak' => \&test_croak, |
15 | 'carp' => \&test_carp, |
16 | 'quiet' => \&test_quiet, |
17 | ) ; |
18 | |
19 | while( 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 | |
28 | sub test_croak { |
29 | |
30 | my ( $name, $sub, @args ) = @_ ; |
31 | |
32 | eval { |
33 | $sub->( @args ) ; |
34 | } ; |
35 | |
36 | ok( $@, "$name can croak" ) ; |
37 | } |
38 | |
39 | sub 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 | |
48 | sub 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 | } |