6bb30add4059cf4c5bbc458630073b2e342fb181
[p5sagit/Import-Into.git] / t / import_into.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More qw(no_plan);
4
5 BEGIN {
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');
23     CheckFile->import::into(1);
24   }
25
26   $INC{"MultiExporter.pm"} = 1;
27 }
28
29 my @checkcaller;
30 BEGIN {
31
32   package CheckFile;
33
34   sub import {
35     @checkcaller = caller;
36   }
37
38   $INC{"CheckFile.pm"} = 1;
39 }
40
41 BEGIN {
42
43   package TestPackage;
44
45   no warnings;
46
47 #line 1
48   use MultiExporter;
49
50   sub test {
51     thing . undef
52   }
53 }
54
55 my @w;
56
57 is(do {
58   local $SIG{__WARN__} = sub { push @w, @_; };
59   TestPackage::test;
60 }, 'thing', 'returned thing ok');
61
62 is(scalar @w, 1, 'Only one entry in @w');
63
64 like($w[0], qr/uninitialized/, 'Correct warning');
65
66 is $checkcaller[0], 'TestPackage', 'import by level has correct package';
67 is $checkcaller[1], __FILE__, 'import by level has correct file';
68 is $checkcaller[2], 1, 'import by level has correct line';