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.010 );
19 fail_on_empty fail_on_false fail_on_undef
22 use autodie qw(fail_on_empty fail_on_false fail_on_undef);
24 diag("Sub::Identify ", exists( $INC{'Sub/Identify.pm'} ) ? "is" : "is not",
27 my $hints = "autodie::hints";
31 is( $hints->sub_fullname(\©), 'File::Copy::copy' , "Id: copy" );
32 is( $hints->sub_fullname(\&cp), 'File::Copy::copy' , "Id: cp" );
34 is( $hints->sub_fullname(\&move), 'File::Copy::move' , "Id: move" );
35 is( $hints->sub_fullname(\&mv), 'File::Copy::move' , "Id: mv" );
38 ok( $hints->get_hints_for(\©)->{scalar}->(0) ,
39 "copy() hints should fail on 0 for scalars."
48 my $scalar_context = copy(NO_SUCH_FILE, NO_SUCH_FILE2);
51 isnt("$@", "", "Copying in scalar context should throw an error.");
52 isa_ok($@, "autodie::exception");
59 my @list_context = copy(NO_SUCH_FILE, NO_SUCH_FILE2);
62 isnt("$@", "", "Copying in list context should throw an error.");
63 isa_ok($@, "autodie::exception");
65 # Tests on loaded funcs.
69 # Test code # Exception expected?
71 'fail_on_empty()' => 1,
72 'fail_on_empty(0)' => 0,
73 'fail_on_empty(undef)' => 0,
74 'fail_on_empty(1)' => 0,
76 'fail_on_false()' => 1,
77 'fail_on_false(0)' => 1,
78 'fail_on_false(undef)' => 1,
79 'fail_on_false(1)' => 0,
81 'fail_on_undef()' => 1,
82 'fail_on_undef(0)' => 0,
83 'fail_on_undef(undef)' => 1,
84 'fail_on_undef(1)' => 0,
88 # On Perl 5.8, autodie doesn't correctly propagate into string evals.
89 # The following snippet forces the use of autodie inside the eval if
90 # we really really have to. For 5.10+, we don't want to include this
91 # fix, because the tests will act as a canary if we screw up string
97 "use autodie qw(fail_on_empty fail_on_false fail_on_undef); "
100 while (my ($test, $exception_expected) = each %tests) {
107 if ($exception_expected) {
108 isnt("$@", "", $test);