Release commit for 1.002002
[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
15 package MultiExporter;
16
17 use Import::Into;
18
19 sub import {
20 my $target = caller;
21 warnings->import::into($target);
22 MyExporter->import::into($target, 'thing');
e5f9555d 23 CheckFile->import::into(1);
568eef3e 24
2afb5246 25 }
26
27 $INC{"MultiExporter.pm"} = 1;
28}
29
e5f9555d 30my @checkcaller;
568eef3e 31my $checkversion;
e5f9555d 32BEGIN {
33
34 package CheckFile;
35
36 sub import {
37 @checkcaller = caller;
38 }
568eef3e 39 sub VERSION {
40 $checkversion = $_[1];
41 }
e5f9555d 42
43 $INC{"CheckFile.pm"} = 1;
44}
45
8afc1658 46eval q{
2afb5246 47
48 package TestPackage;
49
b95fe8b9 50 no warnings FATAL => 'all';
2afb5246 51
8afc1658 52#line 1 "import_into_inline.pl"
2afb5246 53 use MultiExporter;
54
55 sub test {
56 thing . undef
57 }
8afc1658 58 1;
59} or die $@;
2afb5246 60
61my @w;
62
63is(do {
64 local $SIG{__WARN__} = sub { push @w, @_; };
8afc1658 65 TestPackage::test();
2afb5246 66}, 'thing', 'returned thing ok');
67
68is(scalar @w, 1, 'Only one entry in @w');
69
70like($w[0], qr/uninitialized/, 'Correct warning');
e5f9555d 71
72is $checkcaller[0], 'TestPackage', 'import by level has correct package';
8afc1658 73is $checkcaller[1], 'import_into_inline.pl', 'import by level has correct file';
e5f9555d 74is $checkcaller[2], 1, 'import by level has correct line';
568eef3e 75
76CheckFile->import::into({
77 package => 'ExplicitPackage',
78 filename => 'explicit-file.pl',
79 line => 42,
80 version => 219,
81});
82
83is $checkcaller[0], 'ExplicitPackage', 'import with hash has correct package';
84is $checkcaller[1], 'explicit-file.pl', 'import with hash has correct file';
85is $checkcaller[2], 42, 'import with hash has correct line';
86is $checkversion, 219, 'import with hash has correct version';