1#!/usr/bin/perl -w 2use strict; 3use warnings; 4use Test::More 'no_plan'; 5use File::Copy; 6use constant NO_SUCH_FILE => 'this_file_had_better_not_exist'; 7use constant EXCEPTION => 'autodie::exception'; 8 9# http://perlmonks.org/?node_id=744246 describes a situation where 10# using autodie on user-defined functions can fail, depending upon 11# their context. These tests attempt to detect this bug. 12 13eval { 14 use autodie qw(copy); 15 copy(NO_SUCH_FILE, 'xyzzy'); 16}; 17 18isa_ok($@,EXCEPTION,"Copying a non-existent file should throw an error"); 19 20eval { 21 use autodie qw(copy); 22 my $x = copy(NO_SUCH_FILE, 'xyzzy'); 23}; 24 25isa_ok($@,EXCEPTION,"This shouldn't change with scalar context"); 26 27eval { 28 use autodie qw(copy); 29 my @x = copy(NO_SUCH_FILE, 'xyzzy'); 30}; 31 32isa_ok($@,EXCEPTION,"This shouldn't change with array context"); 33 34# For good measure, test with built-ins. 35 36eval { 37 use autodie qw(open); 38 open(my $fh, '<', 'xyzzy'); 39}; 40 41isa_ok($@,EXCEPTION,"Opening a non-existent file should throw an error"); 42 43eval { 44 use autodie qw(open); 45 my $x = open(my $fh, '<', 'xyzzy'); 46}; 47 48isa_ok($@,EXCEPTION,"This shouldn't change with scalar context"); 49 50eval { 51 use autodie qw(open); 52 my @x = open(my $fh, '<', 'xyzzy'); 53}; 54 55isa_ok($@,EXCEPTION,"This shouldn't change with array context"); 56