Commit | Line | Data |
82d4508f |
1 | #!./perl |
2 | |
3 | BEGIN { |
4 | chdir 't' if -d 't'; |
5 | @INC = '../lib'; |
6 | } |
7 | |
8 | use Test; |
9 | BEGIN { plan tests => 9; } |
10 | |
a6c2ede0 |
11 | BEGIN { |
82d4508f |
12 | require autouse; |
13 | eval { |
14 | "autouse"->import('List::Util' => 'List::Util::first'); |
15 | }; |
16 | ok( $@, qr/^autouse into different package attempted/ ); |
17 | |
18 | "autouse"->import('List::Util' => qw(max first(&@))); |
a6c2ede0 |
19 | } |
20 | |
82d4508f |
21 | my @a = (1,2,3,4,5.5); |
22 | ok( max(@a), 5.5); |
a6c2ede0 |
23 | |
a6c2ede0 |
24 | |
82d4508f |
25 | # first() has a prototype of &@. Make sure that's preserved. |
26 | ok( (first { $_ > 3 } @a), 4); |
27 | |
28 | |
29 | # Example from the docs. |
30 | use autouse 'Carp' => qw(carp croak); |
31 | |
32 | { |
33 | my @warning; |
34 | local $SIG{__WARN__} = sub { push @warning, @_ }; |
35 | carp "this carp was predeclared and autoused\n"; |
36 | ok( scalar @warning, 1 ); |
37 | ok( $warning[0], "this carp was predeclared and autoused\n" ); |
38 | |
39 | eval { croak "It is but a scratch!" }; |
40 | ok( $@, qr/^It is but a scratch!/); |
41 | } |
42 | |
a6c2ede0 |
43 | |
82d4508f |
44 | # Test that autouse's lazy module loading works. We assume that nothing |
45 | # involved in this test uses Test::Soundex, which is pretty safe. |
46 | use File::Spec; |
47 | use autouse 'Text::Soundex' => qw(soundex); |
a6c2ede0 |
48 | |
82d4508f |
49 | my $mod_file = File::Spec->catfile(qw(Text Soundex.pm)); |
50 | ok( !exists $INC{$mod_file} ); |
51 | ok( soundex('Basset'), 'B230' ); |
52 | ok( exists $INC{$mod_file} ); |
a6c2ede0 |
53 | |