7 use lib "$FindBin::Bin/lib";
9 use File::Copy qw(copy move cp mv);
11 use Test::More 'no_plan';
13 use constant NO_SUCH_FILE => "this_file_had_better_not_exist";
14 use constant NO_SUCH_FILE2 => "this_file_had_better_not_exist_xyzzy";
16 use constant PERL510 => ( $] >= 5.0100 );
17 use constant PERL5101 => ( $] >= 5.0101 );
20 fail_on_empty fail_on_false fail_on_undef
23 use autodie qw(fail_on_empty fail_on_false fail_on_undef);
25 diag("Sub::Identify ", exists( $INC{'Sub/Identify.pm'} ) ? "is" : "is not",
26 " loaded") if (! $ENV{PERL_CORE});
28 my $hints = "autodie::hints";
32 is( $hints->sub_fullname(\©), 'File::Copy::copy' , "Id: copy" );
34 $hints->sub_fullname(\&cp),
35 PERL5101 ? 'File::Copy::cp' : 'File::Copy::copy' , "Id: cp"
38 is( $hints->sub_fullname(\&move), 'File::Copy::move' , "Id: move" );
39 is( $hints->sub_fullname(\&mv),
40 PERL5101 ? 'File::Copy::mv' : 'File::Copy::move' , "Id: mv"
44 ok( $hints->get_hints_for(\©)->{scalar}->(0) ,
45 "copy() hints should fail on 0 for scalars."
47 ok( $hints->get_hints_for(\©)->{list}->(0) ,
48 "copy() hints should fail on 0 for lists."
57 my $scalar_context = copy(NO_SUCH_FILE, NO_SUCH_FILE2);
60 isnt("$@", "", "Copying in scalar context should throw an error.");
61 isa_ok($@, "autodie::exception");
63 is($@->function, "File::Copy::copy", "Function should be original name");
66 skip("File::Copy is weird on Win32 before 5.10.1", 1)
67 if ( ! PERL5101 and $^O eq "MSWin32" );
69 is($@->return, 0, "File::Copy returns zero on failure");
72 is($@->context, "scalar", "File::Copy called in scalar context");
79 my @list_context = copy(NO_SUCH_FILE, NO_SUCH_FILE2);
82 isnt("$@", "", "Copying in list context should throw an error.");
83 isa_ok($@, "autodie::exception");
85 is($@->function, "File::Copy::copy", "Function should be original name");
88 skip("File::Copy is weird on Win32 before 5.10.1", 1)
89 if ( ! PERL5101 and $^O eq "MSWin32" );
91 is_deeply($@->return, [0], "File::Copy returns zero on failure");
93 is($@->context, "list", "File::Copy called in list context");
95 # Tests on loaded funcs.
99 # Test code # Exception expected?
101 'fail_on_empty()' => 1,
102 'fail_on_empty(0)' => 0,
103 'fail_on_empty(undef)' => 0,
104 'fail_on_empty(1)' => 0,
106 'fail_on_false()' => 1,
107 'fail_on_false(0)' => 1,
108 'fail_on_false(undef)' => 1,
109 'fail_on_false(1)' => 0,
111 'fail_on_undef()' => 1,
112 'fail_on_undef(0)' => 0,
113 'fail_on_undef(undef)' => 1,
114 'fail_on_undef(1)' => 0,
118 # On Perl 5.8, autodie doesn't correctly propagate into string evals.
119 # The following snippet forces the use of autodie inside the eval if
120 # we really really have to. For 5.10+, we don't want to include this
121 # fix, because the tests will act as a canary if we screw up string
127 "use autodie qw(fail_on_empty fail_on_false fail_on_undef); "
130 while (my ($test, $exception_expected) = each %tests) {
137 if ($exception_expected) {
138 isnt("$@", "", $test);