From: Uri Guttman Date: Fri, 8 May 2009 06:02:22 +0000 (-0400) Subject: moved error.t to error_mode.t X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c27bcc508f5e00a2f293e64897c0b565f01265d0;p=urisagit%2FFile-Slurp.git moved error.t to error_mode.t --- diff --git a/t/error_mode.t b/t/error_mode.t new file mode 100644 index 0000000..c4ecdfe --- /dev/null +++ b/t/error_mode.t @@ -0,0 +1,59 @@ +##!/usr/local/bin/perl -w + +use strict ; +use File::Slurp ; + +use Carp ; +use Test::More tests => 9 ; + +my $file = 'missing/file' ; +unlink $file ; + + +my %modes = ( + 'croak' => \&test_croak, + 'carp' => \&test_carp, + 'quiet' => \&test_quiet, +) ; + +while( my( $mode, $sub ) = each %modes ) { + + $sub->( 'read_file', \&read_file, $file, err_mode => $mode ) ; + $sub->( 'write_file', \&write_file, $file, + { err_mode => $mode }, 'junk' ) ; + $sub->( 'read_dir', \&read_dir, $file, err_mode => $mode ) ; +} + + +sub test_croak { + + my ( $name, $sub, @args ) = @_ ; + + eval { + $sub->( @args ) ; + } ; + + ok( $@, "$name can croak" ) ; +} + +sub test_carp { + + my ( $name, $sub, @args ) = @_ ; + + local $SIG{__WARN__} = sub { ok( 1, "$name can carp" ) } ; + + $sub->( @args ) ; +} + +sub test_quiet { + + my ( $name, $sub, @args ) = @_ ; + + local $SIG{__WARN__} = sub { ok( 0, "$name can be quiet" ) } ; + + eval { + $sub->( @args ) ; + } ; + + ok( !$@, "$name can be quiet" ) ; +}