Update Module::Build to 0.33_05
[p5sagit/p5-mst-13.2.git] / lib / autodie / t / user-context.t
CommitLineData
db4e6d09 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
32TODO: {
33 local $TODO = "Fixed in 'hints' branch";
34
35 isa_ok($@,EXCEPTION,"This shouldn't change with array context");
36}
37
38# For good measure, test with built-ins.
39
40eval {
41 use autodie qw(open);
42 open(my $fh, '<', 'xyzzy');
43};
44
45isa_ok($@,EXCEPTION,"Opening a non-existent file should throw an error");
46
47eval {
48 use autodie qw(open);
49 my $x = open(my $fh, '<', 'xyzzy');
50};
51
52isa_ok($@,EXCEPTION,"This shouldn't change with scalar context");
53
54eval {
55 use autodie qw(open);
56 my @x = open(my $fh, '<', 'xyzzy');
57};
58
59isa_ok($@,EXCEPTION,"This shouldn't change with array context");