5 if ($Config::Config{'extensions'} !~ m!\bList/Util\b!){
6 print "1..0 # Skip -- Perl configured without List::Util module\n";
11 use Test::More tests => 15;
16 "autouse"->import('Scalar::Util' => 'Scalar::Util::set_prototype(&$)');
21 "autouse"->import('Scalar::Util' => 'Foo::min');
23 ok( $@, qr/^autouse into different package attempted/ );
25 "autouse"->import('Scalar::Util' => qw(isdual set_prototype(&$)));
31 # set_prototype() has a prototype of &$. Make sure that's preserved.
32 sub sum { return $_[0] + $_[1] };
33 is( (set_prototype \&sum, '$$'), \&sum);
36 # Example from the docs.
37 use autouse 'Carp' => qw(carp croak);
41 local $SIG{__WARN__} = sub { push @warning, @_ };
42 carp "this carp was predeclared and autoused\n";
43 is( scalar @warning, 1 );
44 like( $warning[0], qr/^this carp was predeclared and autoused\n/ );
46 eval { croak "It is but a scratch!" };
47 like( $@, qr/^It is but a scratch!/);
51 # Test that autouse's lazy module loading works.
52 use autouse 'Errno' => qw(EPERM);
54 my $mod_file = 'Errno.pm'; # just fine and portable for %INC
55 ok( !exists $INC{$mod_file} );
56 ok( EPERM ); # test if non-zero
57 ok( exists $INC{$mod_file} );
59 use autouse Env => "something";
61 like( $@, qr/^\Qautoused module Env has unique import() method/ );
63 # Check that UNIVERSAL.pm doesn't interfere with modules that don't use
64 # Exporter and have no import() of their own.
67 unshift @INC, File::Spec->catdir('t', 'lib'), 'lib';
68 autouse->import("MyTestModule" => 'test_function');
69 my $ret = test_function();
72 # Test that autouse is exempt from all methods of triggering the subroutine
73 # redefinition warning.
75 skip "Fails in 5.15.5 and below (perl bug)", 2 if $] < 5.0150051;
76 use warnings; local $^W = 1; no warnings 'once';
78 local $SIG{__WARN__} = sub { $w .= shift };
79 use autouse MyTestModule2 => 'test_function2';
80 *MyTestModule2::test_function2 = \&test_function2;
81 require MyTestModule2;
83 'no redefinition warning when clobbering autouse stub with new sub';
85 import MyTestModule2 'test_function2';
87 'no redefinition warning when clobbering autouse stub via *a=\&b';
90 skip "Fails from 5.10 to 5.15.5 (perl bug)", 1
91 if $] < 5.0150051 and $] > 5.0099;
93 skip "no B", 1 unless $Config{extensions} =~ /\bB\b/;
94 use warnings; local $^W = 1; no warnings 'once';
96 local $SIG{__WARN__} = sub { $w .= shift };
97 use autouse B => "sv_undef";
98 *B::sv_undef = \&sv_undef;
101 'no redefinition warning when clobbering autouse stub with new XSUB';