X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F050_metaclasses%2F012_moose_exporter.t;h=3635a8b8339c9fbc3fccab52e2a41f0e6dd78fb4;hb=4e1a0020d28612ce072902bf6bc94a073eb852e2;hp=c6c1f4dd8cdd37d8b812d4500f3e4381a883eee3;hpb=a28e50e44945358d15eb19e4688573741a319fe0;p=gitmo%2FMoose.git diff --git a/t/050_metaclasses/012_moose_exporter.t b/t/050_metaclasses/012_moose_exporter.t index c6c1f4d..3635a8b 100644 --- a/t/050_metaclasses/012_moose_exporter.t +++ b/t/050_metaclasses/012_moose_exporter.t @@ -4,12 +4,11 @@ use strict; use warnings; use Test::More; -use Test::Exception; -BEGIN { - eval "use Test::Output;"; - plan skip_all => "Test::Output is required for this test" if $@; -} +use Test::Fatal; +use Test::Requires { + 'Test::Output' => '0.01', # skip all if not installed +}; { package HasOwnImmutable; @@ -111,7 +110,7 @@ BEGIN { use Moose (); sub wrapped2 { - my $caller = shift; + my $caller = shift->name; return $caller . ' called wrapped2'; } @@ -120,9 +119,9 @@ BEGIN { } Moose::Exporter->setup_import_methods( - with_caller => ['wrapped2'], - as_is => ['as_is1'], - also => 'MooseX::Sugar', + with_meta => ['wrapped2'], + as_is => ['as_is1'], + also => 'MooseX::Sugar', ); } @@ -198,19 +197,13 @@ BEGIN { 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' ); } @@ -219,19 +212,13 @@ BEGIN { 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' ); } @@ -240,19 +227,13 @@ BEGIN { 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' ); } @@ -262,13 +243,13 @@ BEGIN { use Moose (); sub has { - my $caller = shift; + my $caller = shift->name; return $caller . ' called has'; } Moose::Exporter->setup_import_methods( - with_caller => ['has'], - also => 'Moose', + with_meta => ['has'], + also => 'Moose', ); } @@ -286,11 +267,56 @@ BEGIN { } { - 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 (); @@ -298,7 +324,7 @@ BEGIN { ::stderr_like { Moose::Exporter->setup_import_methods( also => ['Moose'], - with_caller => ['does_not_exist'], + with_meta => ['does_not_exist'], ); } qr/^Trying to export undefined sub NonExistentExport::does_not_exist/, "warns when a non-existent method is requested to be exported"; @@ -316,6 +342,7 @@ BEGIN { { package AllOptions; use Moose (); + use Moose::Deprecated -api_version => '0.88'; use Moose::Exporter; Moose::Exporter->setup_import_methods(