fix level as hashref argument
[p5sagit/Import-Into.git] / t / import_into.t
CommitLineData
2afb5246 1use strict;
2use warnings FATAL => 'all';
1615d435 3use Test::More qw(no_plan);
2afb5246 4
5BEGIN {
6
7 package MyExporter;
8
9 use base qw(Exporter);
10
11 our @EXPORT_OK = qw(thing);
12
13 sub thing { 'thing' }
14
cc087979 15 $INC{"MyExporter.pm"} = 1;
16
2afb5246 17 package MultiExporter;
18
19 use Import::Into;
20
21 sub import {
22 my $target = caller;
23 warnings->import::into($target);
24 MyExporter->import::into($target, 'thing');
e5f9555d 25 CheckFile->import::into(1);
568eef3e 26
2afb5246 27 }
28
29 $INC{"MultiExporter.pm"} = 1;
30}
31
e5f9555d 32my @checkcaller;
568eef3e 33my $checkversion;
e5f9555d 34BEGIN {
35
36 package CheckFile;
37
38 sub import {
39 @checkcaller = caller;
40 }
568eef3e 41 sub VERSION {
42 $checkversion = $_[1];
43 }
e5f9555d 44
45 $INC{"CheckFile.pm"} = 1;
46}
47
8afc1658 48eval q{
2afb5246 49
50 package TestPackage;
51
b95fe8b9 52 no warnings FATAL => 'all';
2afb5246 53
8afc1658 54#line 1 "import_into_inline.pl"
2afb5246 55 use MultiExporter;
56
57 sub test {
58 thing . undef
59 }
8afc1658 60 1;
61} or die $@;
2afb5246 62
63my @w;
64
65is(do {
66 local $SIG{__WARN__} = sub { push @w, @_; };
8afc1658 67 TestPackage::test();
2afb5246 68}, 'thing', 'returned thing ok');
69
70is(scalar @w, 1, 'Only one entry in @w');
71
72like($w[0], qr/uninitialized/, 'Correct warning');
e5f9555d 73
74is $checkcaller[0], 'TestPackage', 'import by level has correct package';
8afc1658 75is $checkcaller[1], 'import_into_inline.pl', 'import by level has correct file';
e5f9555d 76is $checkcaller[2], 1, 'import by level has correct line';
568eef3e 77
78CheckFile->import::into({
79 package => 'ExplicitPackage',
80 filename => 'explicit-file.pl',
81 line => 42,
82 version => 219,
83});
84
85is $checkcaller[0], 'ExplicitPackage', 'import with hash has correct package';
86is $checkcaller[1], 'explicit-file.pl', 'import with hash has correct file';
87is $checkcaller[2], 42, 'import with hash has correct line';
88is $checkversion, 219, 'import with hash has correct version';
cc087979 89
90ok( !IPC::Open3->can("open3"), "IPC::Open3 is unloaded" );
91IPC::Open3->import::into("TestPackage");
92ok( TestPackage->can("open3"), "IPC::Open3 was use'd and import::into'd" );