Reverse the output from _follow_also
[gitmo/Moose.git] / t / 050_metaclasses / 012_moose_exporter.t
index e37669d..3635a8b 100644 (file)
@@ -4,7 +4,7 @@ use strict;
 use warnings;
 
 use Test::More;
-use Test::Exception;
+use Test::Fatal;
 
 use Test::Requires {
     'Test::Output' => '0.01', # skip all if not installed
@@ -197,19 +197,13 @@ use Test::Requires {
 
     use Moose ();
 
-    ::dies_ok(
-        sub {
-            Moose::Exporter->setup_import_methods(
+    ::like(
+        ::exception{ Moose::Exporter->setup_import_methods(
                 also => [ 'Moose', 'MooseX::CircularAlso' ],
             );
-        },
-        'a circular reference in also dies with an error'
-    );
-
-    ::like(
-        $@,
+            },
         qr/\QCircular reference in 'also' parameter to Moose::Exporter between MooseX::CircularAlso and MooseX::CircularAlso/,
-        'got the expected error from circular reference in also'
+        'a circular reference in also dies with an error'
     );
 }
 
@@ -218,19 +212,13 @@ use Test::Requires {
 
     use Moose ();
 
-    ::dies_ok(
-        sub {
-            Moose::Exporter->setup_import_methods(
-                also => [ 'NoSuchThing' ],
-            );
-        },
-        'a package which does not use Moose::Exporter in also dies with an error'
-    );
-
     ::like(
-        $@,
+        ::exception{ Moose::Exporter->setup_import_methods(
+                also => ['NoSuchThing'],
+            );
+            },
         qr/\QPackage in also (NoSuchThing) does not seem to use Moose::Exporter (is it loaded?) at /,
-        'got the expected error from a reference in also to a package which is not loaded'
+        'a package which does not use Moose::Exporter in also dies with an error'
     );
 }
 
@@ -239,19 +227,13 @@ use Test::Requires {
 
     use Moose ();
 
-    ::dies_ok(
-        sub {
-            Moose::Exporter->setup_import_methods(
-                also => [ 'Moose::Meta::Method' ],
-            );
-        },
-        'a package which does not use Moose::Exporter in also dies with an error'
-    );
-
     ::like(
-        $@,
+        ::exception{ Moose::Exporter->setup_import_methods(
+                also => ['Moose::Meta::Method'],
+            );
+            },
         qr/\QPackage in also (Moose::Meta::Method) does not seem to use Moose::Exporter at /,
-        'got the expected error from a reference in also to a package which does not use Moose::Exporter'
+        'a package which does not use Moose::Exporter in also dies with an error'
     );
 }
 
@@ -285,11 +267,56 @@ use Test::Requires {
 }
 
 {
-    ok( ! WantsSugar->can('has'),  'WantsSugar::has() has been cleaned' );
-    ok( ! WantsSugar->can('with'), 'WantsSugar::with() has been cleaned' );
+    ok( ! WantsOverridingSugar->can('has'),  'WantsSugar::has() has been cleaned' );
+    ok( ! WantsOverridingSugar->can('with'), 'WantsSugar::with() has been cleaned' );
+}
+
+{
+    package MooseX::OverridingSugar::PassThru;
+    
+    sub with {
+        my $caller = shift->name;
+        return $caller . ' called with';
+    }
+    
+    Moose::Exporter->setup_import_methods(
+        with_meta => ['with'],
+        also      => 'MooseX::OverridingSugar',
+    );
+    
 }
 
 {
+
+    package WantsOverridingSugar::PassThru;
+
+    MooseX::OverridingSugar::PassThru->import();
+
+    ::can_ok( 'WantsOverridingSugar::PassThru', 'has' );
+    ::can_ok( 'WantsOverridingSugar::PassThru', 'with' );
+    ::is(
+        has('foo'),
+        'WantsOverridingSugar::PassThru called has',
+        'has from MooseX::OverridingSugar is called, not has from Moose'
+    );
+
+    ::is(
+        with('foo'),
+        'WantsOverridingSugar::PassThru called with',
+        'with from MooseX::OverridingSugar::PassThru is called, not has from Moose'
+    );
+
+
+    MooseX::OverridingSugar::PassThru->unimport();
+}
+
+{
+    ok( ! WantsOverridingSugar::PassThru->can('has'),  'WantsOverridingSugar::PassThru::has() has been cleaned' );
+    ok( ! WantsOverridingSugar::PassThru->can('with'), 'WantsOverridingSugar::PassThru::with() has been cleaned' );
+}
+
+{
+
     package NonExistentExport;
 
     use Moose ();