Upgrade to PathTools-3.23.
[p5sagit/p5-mst-13.2.git] / lib / AutoLoader.t
index 408b281..da7071b 100755 (executable)
@@ -16,7 +16,7 @@ BEGIN
        unshift @INC, $dir;
 }
 
-use Test::More tests => 14;
+use Test::More tests => 21;
 
 # First we must set up some autoloader files
 my $fulldir = File::Spec->catdir( $dir, 'auto', 'Foo' );
@@ -73,22 +73,34 @@ require AutoLoader;
 AutoLoader->import( 'AUTOLOAD' );
 
 sub new { bless {}, shift };
+sub foo;
+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;
 };
 like( $@, qr/^Can't locate/, 'undefined method' );
 
+$result = $foo->can( 'will_fail' );
+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' );
@@ -109,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'))
@@ -135,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();