This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Silence a warning from Module::CoreList that occurs when the module version is
[perl5.git] / lib / autouse.t
CommitLineData
82d4508f
MS
1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
5 @INC = '../lib';
78cd8b71 6 require Config;
98641f60 7 if (($Config::Config{'extensions'} !~ m!\bList/Util\b!) ){
78cd8b71
NC
8 print "1..0 # Skip -- Perl configured without List::Util module\n";
9 exit 0;
10 }
82d4508f
MS
11}
12
13use Test;
03699e8e 14BEGIN { plan tests => 12; }
82d4508f 15
a6c2ede0 16BEGIN {
82d4508f
MS
17 require autouse;
18 eval {
5a02ccb1
MS
19 "autouse"->import('List::Util' => 'List::Util::first(&@)');
20 };
21 ok( !$@ );
22
23 eval {
24 "autouse"->import('List::Util' => 'Foo::min');
82d4508f
MS
25 };
26 ok( $@, qr/^autouse into different package attempted/ );
27
28 "autouse"->import('List::Util' => qw(max first(&@)));
a6c2ede0
JH
29}
30
82d4508f
MS
31my @a = (1,2,3,4,5.5);
32ok( max(@a), 5.5);
a6c2ede0 33
a6c2ede0 34
82d4508f
MS
35# first() has a prototype of &@. Make sure that's preserved.
36ok( (first { $_ > 3 } @a), 4);
37
38
39# Example from the docs.
40use autouse 'Carp' => qw(carp croak);
41
42{
43 my @warning;
44 local $SIG{__WARN__} = sub { push @warning, @_ };
45 carp "this carp was predeclared and autoused\n";
46 ok( scalar @warning, 1 );
59b0a8b7 47 ok( $warning[0], qr/^this carp was predeclared and autoused\n/ );
82d4508f
MS
48
49 eval { croak "It is but a scratch!" };
50 ok( $@, qr/^It is but a scratch!/);
51}
52
a6c2ede0 53
82d4508f 54# Test that autouse's lazy module loading works. We assume that nothing
24874030 55# involved in this test uses Text::Soundex, which is pretty safe.
82d4508f 56use autouse 'Text::Soundex' => qw(soundex);
a6c2ede0 57
e5e86a04 58my $mod_file = 'Text/Soundex.pm'; # just fine and portable for %INC
82d4508f
MS
59ok( !exists $INC{$mod_file} );
60ok( soundex('Basset'), 'B230' );
61ok( exists $INC{$mod_file} );
a6c2ede0 62
03699e8e
MS
63use autouse Env => "something";
64eval { something() };
65ok( $@, qr/^\Qautoused module Env has unique import() method/ );
66
67# Check that UNIVERSAL.pm doesn't interfere with modules that don't use
68# Exporter and have no import() of their own.
69require UNIVERSAL;
70autouse->import("Class::ISA" => 'self_and_super_versions');
71my %versions = self_and_super_versions("Class::ISA");
72ok( $versions{"Class::ISA"}, $Class::ISA::VERSION );