From: Graham Knop Date: Wed, 26 Aug 2015 09:34:34 +0000 (-0400) Subject: refactor test for clarity X-Git-Tag: v1.002005~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FImport-Into.git;a=commitdiff_plain;h=a6e3c44c68290b6b3f7a6aee792fffa5085f5151;hp=bd74adea007ab33d9b1321d911dd76371317c128 refactor test for clarity --- diff --git a/t/import_into.t b/t/import_into.t index 066e172..12b200b 100644 --- a/t/import_into.t +++ b/t/import_into.t @@ -3,18 +3,33 @@ 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' } +} + +my @importcaller; +my $version; +BEGIN { + package CheckFile; + $INC{"CheckFile.pm"} = __FILE__; - $INC{"MyExporter.pm"} = 1; + sub import { + @importcaller = caller; + } + sub VERSION { + $version = $_[1]; + } +} +BEGIN { package MultiExporter; + $INC{"MultiExporter.pm"} = __FILE__; use Import::Into; @@ -23,30 +38,10 @@ BEGIN { warnings->import::into($target); MyExporter->import::into($target, 'thing'); CheckFile->import::into(1); - } - - $INC{"MultiExporter.pm"} = 1; -} - -my @checkcaller; -my $checkversion; -BEGIN { - - package CheckFile; - - sub import { - @checkcaller = caller; - } - sub VERSION { - $checkversion = $_[1]; - } - - $INC{"CheckFile.pm"} = 1; } eval q{ - package TestPackage; no warnings FATAL => 'all'; @@ -71,10 +66,15 @@ 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'; +@importcaller = (); +$version = undef; CheckFile->import::into({ package => 'ExplicitPackage', filename => 'explicit-file.pl', @@ -82,10 +82,26 @@ 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 $version, 219, + 'import with hash has correct version'; + +BEGIN { + package LevelExporter; + $INC{'LevelExporter.pm'} = __FILE__; + + sub import { + CheckFile->import::into({ + level => 1, + version => 219, + }); + } +} ok( !IPC::Open3->can("open3"), "IPC::Open3 is unloaded" ); IPC::Open3->import::into("TestPackage");