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