This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Re: AIX and gcc (moving targets)
[perl5.git] / t / pragma / autouse.t
CommitLineData
82d4508f
MS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
6}
7
8use Test;
9BEGIN { plan tests => 9; }
10
a6c2ede0 11BEGIN {
82d4508f
MS
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
JH
19}
20
82d4508f
MS
21my @a = (1,2,3,4,5.5);
22ok( max(@a), 5.5);
a6c2ede0 23
a6c2ede0 24
82d4508f
MS
25# first() has a prototype of &@. Make sure that's preserved.
26ok( (first { $_ > 3 } @a), 4);
27
28
29# Example from the docs.
30use 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
24874030 45# involved in this test uses Text::Soundex, which is pretty safe.
82d4508f
MS
46use File::Spec;
47use autouse 'Text::Soundex' => qw(soundex);
a6c2ede0 48
82d4508f 49my $mod_file = File::Spec->catfile(qw(Text Soundex.pm));
24874030 50$mod_file = VMS::Filespec::unixify($mod_file) if $^O eq 'VMS';
82d4508f
MS
51ok( !exists $INC{$mod_file} );
52ok( soundex('Basset'), 'B230' );
53ok( exists $INC{$mod_file} );
a6c2ede0 54