VERSION's caller should also match given location
[p5sagit/Import-Into.git] / t / import_into.t
index 12b200b..8e57085 100644 (file)
@@ -14,6 +14,7 @@ BEGIN {
 }
 
 my @importcaller;
+my @versioncaller;
 my $version;
 BEGIN {
   package CheckFile;
@@ -24,6 +25,7 @@ BEGIN {
   }
   sub VERSION {
     $version = $_[1];
+    @versioncaller = caller;
   }
 }
 
@@ -72,8 +74,10 @@ 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',
@@ -88,6 +92,12 @@ 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';
 
@@ -103,6 +113,32 @@ BEGIN {
   }
 }
 
+@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" );