X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FAutoLoader.t;h=92d66fa7314d7ec550b552209b9f2887e2d99f7f;hb=584420f022db57225e9644b9c6668ff9f567984a;hp=9ed79e3f4a8af2c2e0a89b961f04324a492fca5c;hpb=a498340c5e9c95b1999816d3f8194563b91f0950;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/AutoLoader.t b/lib/AutoLoader.t index 9ed79e3..92d66fa 100755 --- a/lib/AutoLoader.t +++ b/lib/AutoLoader.t @@ -16,7 +16,7 @@ BEGIN unshift @INC, $dir; } -use Test::More tests => 17; +use Test::More tests => 22; # First we must set up some autoloader files my $fulldir = File::Spec->catdir( $dir, 'auto', 'Foo' ); @@ -74,18 +74,21 @@ AutoLoader->import( 'AUTOLOAD' ); sub new { bless {}, shift }; sub foo; -sub bar; sub bazmarkhianish; package main; -my $foo = new Foo; +my $foo = Foo->new(); my $result = $foo->can( 'foo' ); ok( $result, 'can() first time' ); is( $foo->foo, 'foo', 'autoloaded first time' ); is( $foo->foo, 'foo', 'regular call' ); is( $result, \&Foo::foo, 'can() returns ref to regular installed sub' ); +$result = $foo->can( 'bar' ); +ok( $result, 'can() should work when importing AUTOLOAD too' ); +is( $foo->bar, 'bar', 'regular call' ); +is( $result, \&Foo::bar, '... returning ref to regular installed sub' ); eval { $foo->will_fail; @@ -97,7 +100,7 @@ ok( ! $result, 'can() should fail on undefined methods' ); # Used to be trouble with this eval { - my $foo = new Foo; + my $foo = Foo->new(); die "oops"; }; like( $@, qr/oops/, 'indirect method call' ); @@ -118,7 +121,7 @@ is( $foo->bazmarkhianish($1), 'foo', '(again)' ); eval { $foo->blechanawilla; }; -like( $@, qr/syntax error/, 'require error propagates' ); +like( $@, qr/syntax error/i, 'require error propagates' ); # test recursive autoloads open(F, '>', File::Spec->catfile( $fulldir, 'a.al')) @@ -144,6 +147,7 @@ Foo::a(); package Bar; AutoLoader->import(); ::ok( ! defined &AUTOLOAD, 'AutoLoader should not export AUTOLOAD by default' ); +::ok( ! defined &can, '... nor can()' ); package Foo; AutoLoader->unimport(); @@ -160,8 +164,21 @@ AutoLoader->unimport(); ::is( Baz->AUTOLOAD(), 'i am here', '... but not non-imported AUTOLOAD()' ); + +package SomeClass; +use AutoLoader 'AUTOLOAD'; +sub new { + bless {} => shift; +} + package main; +$INC{"SomeClass.pm"} = $0; # Prepare possible recursion +{ + my $p = SomeClass->new(); +} # <-- deep recursion in AUTOLOAD looking for SomeClass::DESTROY? +::ok(1, "AutoLoader shouldn't loop forever if \%INC is modified"); + # cleanup END { return unless $dir && -d $dir;