version 0.11
[gitmo/Class-C3.git] / t / 32_next_method_edge_cases.t
index 94e79bf..5af7004 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 9;
+use Test::More tests => 12;
 
 BEGIN {   
     use_ok('Class::C3');
@@ -36,12 +36,13 @@ BEGIN {
         use warnings;
         use Class::C3;
         our @ISA = ('Foo');
-    }
+    }  
     
     my $bar = Bar->new();
     isa_ok($bar, 'Bar');
     isa_ok($bar, 'Foo');    
     
+    # test it working with with Sub::Name
     SKIP: {    
         eval 'use Sub::Name';
         skip "Sub::Name is required for this test", 3 if $@;
@@ -53,9 +54,37 @@ BEGIN {
             *{'Bar::bar'} = $m;
         }
 
+        Class::C3::initialize();  
+
         can_ok($bar, 'bar');
         my $value = eval { $bar->bar() };
         ok(!$@, '... calling bar() succedded') || diag $@;
         is($value, 'Foo::bar', '... got the right return value too');
     }
+    
+    # test it failing without Sub::Name
+    {
+        package Baz;
+        use strict;
+        use warnings;
+        use Class::C3;
+        our @ISA = ('Foo');
+    }      
+    
+    my $baz = Baz->new();
+    isa_ok($baz, 'Baz');
+    isa_ok($baz, 'Foo');    
+    
+    {
+        my $m = sub { (shift)->next::method() };
+        {
+            no strict 'refs';
+            *{'Baz::bar'} = $m;
+        }
+
+        Class::C3::initialize();  
+
+        eval { $baz->bar() };
+        ok($@, '... calling bar() with next::method failed') || diag $@;
+    }    
 }
\ No newline at end of file