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
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
11 BEGIN {
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(&@)));
19 }
20
21 my @a = (1,2,3,4,5.5);
22 ok( max(@a), 5.5);
23
24
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
43
44 # Test that autouse's lazy module loading works.  We assume that nothing
45 # involved in this test uses Text::Soundex, which is pretty safe.
46 use File::Spec;
47 use autouse 'Text::Soundex' => qw(soundex);
48
49 my $mod_file = File::Spec->catfile(qw(Text Soundex.pm));
50 $mod_file = VMS::Filespec::unixify($mod_file) if $^O eq 'VMS';
51 ok( !exists $INC{$mod_file} );
52 ok( soundex('Basset'), 'B230' );
53 ok( exists $INC{$mod_file} );
54