X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FImport-Into.git;a=blobdiff_plain;f=t%2Fimport_into.t;h=8e57085e8bbb7611ebc9fea262b7cca696b68493;hp=fcf3c84dac4c284f8d4efd5b7869e99b02595c97;hb=7a9ec1de996eb32a6fb07c942ae3c03744a82a17;hpb=b95fe8b9490eeda818c99bf35ed3377d75672409 diff --git a/t/import_into.t b/t/import_into.t index fcf3c84..8e57085 100644 --- a/t/import_into.t +++ b/t/import_into.t @@ -3,48 +3,47 @@ use warnings FATAL => 'all'; use Test::More qw(no_plan); BEGIN { - package MyExporter; + $INC{"MyExporter.pm"} = __FILE__; use base qw(Exporter); our @EXPORT_OK = qw(thing); sub thing { 'thing' } +} - package MultiExporter; - - use Import::Into; +my @importcaller; +my @versioncaller; +my $version; +BEGIN { + package CheckFile; + $INC{"CheckFile.pm"} = __FILE__; sub import { - my $target = caller; - warnings->import::into($target); - MyExporter->import::into($target, 'thing'); - CheckFile->import::into(1); - + @importcaller = caller; + } + sub VERSION { + $version = $_[1]; + @versioncaller = caller; } - - $INC{"MultiExporter.pm"} = 1; } -my @checkcaller; -my $checkversion; BEGIN { + package MultiExporter; + $INC{"MultiExporter.pm"} = __FILE__; - package CheckFile; + use Import::Into; sub import { - @checkcaller = caller; - } - sub VERSION { - $checkversion = $_[1]; + my $target = caller; + warnings->import::into($target); + MyExporter->import::into($target, 'thing'); + CheckFile->import::into(1); } - - $INC{"CheckFile.pm"} = 1; } eval q{ - package TestPackage; no warnings FATAL => 'all'; @@ -69,10 +68,17 @@ is(scalar @w, 1, 'Only one entry in @w'); like($w[0], qr/uninitialized/, 'Correct warning'); -is $checkcaller[0], 'TestPackage', 'import by level has correct package'; -is $checkcaller[1], 'import_into_inline.pl', 'import by level has correct file'; -is $checkcaller[2], 1, 'import by level has correct line'; - +is $importcaller[0], 'TestPackage', + 'import by level has correct package'; +is $importcaller[1], 'import_into_inline.pl', + 'import by level has correct file'; +is $importcaller[2], 1, + 'import by level has correct line'; +is scalar @versioncaller, 0, 'VERSION not called when not specified'; + +@importcaller = (); +@versioncaller = (); +$version = undef; CheckFile->import::into({ package => 'ExplicitPackage', filename => 'explicit-file.pl', @@ -80,7 +86,59 @@ CheckFile->import::into({ version => 219, }); -is $checkcaller[0], 'ExplicitPackage', 'import with hash has correct package'; -is $checkcaller[1], 'explicit-file.pl', 'import with hash has correct file'; -is $checkcaller[2], 42, 'import with hash has correct line'; -is $checkversion, 219, 'import with hash has correct version'; +is $importcaller[0], 'ExplicitPackage', + 'import with hash has correct package'; +is $importcaller[1], 'explicit-file.pl', + 'import with hash has correct file'; +is $importcaller[2], 42, + 'import with hash has correct line'; +is $versioncaller[0], 'ExplicitPackage', + 'VERSION with hash has correct package'; +is $versioncaller[1], 'explicit-file.pl', + 'VERSION with hash has correct file'; +is $versioncaller[2], 42, + 'VERSION with hash has correct line'; +is $version, 219, + 'import with hash has correct version'; + +BEGIN { + package LevelExporter; + $INC{'LevelExporter.pm'} = __FILE__; + + sub import { + CheckFile->import::into({ + level => 1, + version => 219, + }); + } +} + +@importcaller = (); +@versioncaller = (); +$version = undef; +eval q{ + package ExplicitLevel; + +#line 42 "explicit-level.pl" + use LevelExporter; + 1; +} or die $@; + +is $importcaller[0], 'ExplicitLevel', + 'import with level in hash has correct package'; +is $importcaller[1], 'explicit-level.pl', + 'import with level in hash has correct file'; +is $importcaller[2], 42, + 'import with level in hash has correct line'; +is $versioncaller[0], 'ExplicitLevel', + 'VERSION with level in hash has correct package'; +is $versioncaller[1], 'explicit-level.pl', + 'VERSION with level in hash has correct file'; +is $versioncaller[2], 42, + 'VERSION with level in hash has correct line'; +is $version, 219, + 'import with level in hash has correct version'; + +ok( !IPC::Open3->can("open3"), "IPC::Open3 is unloaded" ); +IPC::Open3->import::into("TestPackage"); +ok( TestPackage->can("open3"), "IPC::Open3 was use'd and import::into'd" );