X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F01simple.t;h=200f339c2260d4c1f529c40fcdd4f1865708bd0f;hb=d4b2facbcfca13060dbeadb0baba7d7893326dbc;hp=6cb6406ddae569135bf3ed688b6d257b3530454f;hpb=b6086e0da219b3dc46281b04c574a02e4fa2b5a5;p=p5sagit%2FPackage-Variant.git diff --git a/t/01simple.t b/t/01simple.t index 6cb6406..200f339 100644 --- a/t/01simple.t +++ b/t/01simple.t @@ -1,4 +1,4 @@ -use strictures 1; +use strictures 2; use Test::More; use Test::Fatal; use Package::Variant (); @@ -61,4 +61,93 @@ is exception { is_deeply $renamed->args, [9..12], 'imported generator can be renamed'; }, undef, 'no errors for renamed usage'; +my @imported; +BEGIN { + package TestImportableA; + sub import { push @imported, shift } + $INC{'TestImportableA.pm'} = __FILE__; + package TestImportableB; + sub import { push @imported, shift } + $INC{'TestImportableB.pm'} = __FILE__; + package TestArrayImports; + use Package::Variant + importing => [ + 'TestImportableA', + 'TestImportableB', + ]; + sub make_variant { } + $INC{'TestArrayImports.pm'} = __FILE__; +} + +use TestArrayImports; +TestArrayImports(23); + +is_deeply [@imported], [qw( TestImportableA TestImportableB )], + 'multiple imports in the right order'; + +BEGIN { + package TestSingleImport; + use Package::Variant importing => 'TestImportableA'; + sub make_variant { } + $INC{'TestSingleImport.pm'} = __FILE__; +} + +@imported = (); + +use TestSingleImport; +TestSingleImport(23); + +is_deeply [@imported], [qw( TestImportableA )], + 'scalar import works'; + +@imported = (); + +TestSingleImport::->build_variant; + +is_deeply [@imported], [qw( TestImportableA )], + 'build_variant works'; + +like exception { + Package::Variant->import( + importing => \'foo', subs => [qw( foo )], + ); +}, qr/importing.+option.+hash.+array/i, 'invalid "importing" option'; + +like exception { + Package::Variant->import( + importing => { foo => \'bar' }, subs => [qw( bar )], + ); +}, qr/import.+argument.+foo.+not.+array/i, 'invalid import argument list'; + +like exception { + Package::Variant->import( + importing => [ foo => ['bar'], ['bam'], subs => [qw( bar )] ], + ); +}, qr/value.+3.+importing.+not.+string/i, 'importing array invalid key'; + +like exception { + Package::Variant->import( + importing => [ foo => \'bam', subs => [qw( bar )] ], + ); +}, qr/value.+2.+foo.+importing.+array/i, 'importing array invalid list'; + +BEGIN { + package TestOverrideName; + + use Package::Variant; + + sub make_variant_package_name { + my (undef, @args) = @_; + return $args[0]; + } + + sub make_variant { + install hey => sub { 'hey' }; + } +} + +is(TestOverrideName::->build_variant('hey'), 'hey'); + +is(hey->hey, 'hey', 'hey'); + done_testing;