Re: [ID 20010529.003] find2perl and File::Find doesn't emulate find when path is...
[p5sagit/p5-mst-13.2.git] / t / pragma / autouse.t
CommitLineData
82d4508f 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 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 21my @a = (1,2,3,4,5.5);
22ok( max(@a), 5.5);
a6c2ede0 23
a6c2ede0 24
82d4508f 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
45# involved in this test uses Test::Soundex, which is pretty safe.
46use File::Spec;
47use autouse 'Text::Soundex' => qw(soundex);
a6c2ede0 48
82d4508f 49my $mod_file = File::Spec->catfile(qw(Text Soundex.pm));
50ok( !exists $INC{$mod_file} );
51ok( soundex('Basset'), 'B230' );
52ok( exists $INC{$mod_file} );
a6c2ede0 53