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