From: Michael G. Schwern Date: Tue, 29 May 2001 00:42:59 +0000 (+0100) Subject: Re: [ID 20010528.001] use autouse 'URI::Escape' => qw(URI::Escape::uri_escape) failed X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=82d4508f1e378a1fc682f730ff20d4be8c3772e5;p=p5sagit%2Fp5-mst-13.2.git Re: [ID 20010528.001] use autouse 'URI::Escape' => qw(URI::Escape::uri_escape) failed Message-ID: <20010529004259.A675@blackrider.blackstar.co.uk> p4raw-id: //depot/perl@10271 --- diff --git a/t/pragma/autouse.t b/t/pragma/autouse.t index dbd4408..0120ed0 100644 --- a/t/pragma/autouse.t +++ b/t/pragma/autouse.t @@ -1,18 +1,53 @@ +#!./perl + +BEGIN { + chdir 't' if -d 't'; + @INC = '../lib'; +} + +use Test; +BEGIN { plan tests => 9; } + BEGIN { - chdir 't' if -d 't'; - @INC = '../lib'; + require autouse; + eval { + "autouse"->import('List::Util' => 'List::Util::first'); + }; + ok( $@, qr/^autouse into different package attempted/ ); + + "autouse"->import('List::Util' => qw(max first(&@))); } -print "1..3\n"; +my @a = (1,2,3,4,5.5); +ok( max(@a), 5.5); -use autouse 'Math::Complex' => qw(cplx); -use autouse 'Math::Trig' => qw(Math::Trig::deg2grad($;$)); -print "ok 1\n"; +# first() has a prototype of &@. Make sure that's preserved. +ok( (first { $_ > 3 } @a), 4); + + +# Example from the docs. +use autouse 'Carp' => qw(carp croak); + +{ + my @warning; + local $SIG{__WARN__} = sub { push @warning, @_ }; + carp "this carp was predeclared and autoused\n"; + ok( scalar @warning, 1 ); + ok( $warning[0], "this carp was predeclared and autoused\n" ); + + eval { croak "It is but a scratch!" }; + ok( $@, qr/^It is but a scratch!/); +} + -print "not " unless sqrt(cplx(-1)) == cplx(0, 1); -print "ok 2\n"; +# Test that autouse's lazy module loading works. We assume that nothing +# involved in this test uses Test::Soundex, which is pretty safe. +use File::Spec; +use autouse 'Text::Soundex' => qw(soundex); -print "not " unless Math::Trig::deg2grad(360, 1) == 400; -print "ok 3\n"; +my $mod_file = File::Spec->catfile(qw(Text Soundex.pm)); +ok( !exists $INC{$mod_file} ); +ok( soundex('Basset'), 'B230' ); +ok( exists $INC{$mod_file} );