Switching to `` requires one more \ to escape $Config in new_config=`...`
[p5sagit/p5-mst-13.2.git] / t / lib / autodie / usersub.t
CommitLineData
0b09a93a 1#!/usr/bin/perl -w
2use strict;
3
4use Test::More 'no_plan';
5
6sub mytest {
7 return $_[0];
8}
9
10is(mytest(q{foo}),q{foo},"Mytest returns input");
11
12my $return = eval { mytest(undef); };
13
14ok(!defined($return), "mytest returns undef without autodie");
15is($@,"","Mytest doesn't throw an exception without autodie");
16
17$return = eval {
18 use autodie qw(mytest);
19
20 mytest('foo');
21};
22
23is($return,'foo',"Mytest returns input with autodie");
24
25$return = eval {
26 use autodie qw(mytest);
27
28 mytest(undef);
29};
30
31isa_ok($@,'autodie::exception',"autodie mytest/undef throws exception");
32
33# We set initial values here because we're expecting $data to be
34# changed to undef later on. Having it as undef to begin with means
35# we can't see mytest(undef) working correctly.
36
37my ($data, $data2) = (1,1);
38
39eval {
40 use autodie qw(mytest);
41
42 {
43 no autodie qw(mytest);
44
45 $data = mytest(undef);
46 $data2 = mytest('foo');
47 }
48};
49
50is($@,"","no autodie can counter use autodie for user subs");
51ok(!defined($data), "mytest(undef) should return undef");
52is($data2, "foo", "mytest(foo) should return foo");
53
54eval {
55 mytest(undef);
56};
57
58is($@,"","No lingering failure effects");
59
60$return = eval {
61 mytest("bar");
62};
63
64is($return,"bar","No lingering return effects");