it works!
[p5sagit/Import-Into.git] / t / import_into.t
1 use strict;
2 use warnings FATAL => 'all';
3 use Test::More;
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   }
24
25   $INC{"MultiExporter.pm"} = 1;
26 }
27
28 BEGIN {
29
30   package TestPackage;
31
32   no warnings;
33
34   use MultiExporter;
35
36   sub test {
37     thing . undef
38   }
39 }
40
41 my @w;
42
43 is(do {
44   local $SIG{__WARN__} = sub { push @w, @_; };
45   TestPackage::test;
46 }, 'thing', 'returned thing ok');
47
48 is(scalar @w, 1, 'Only one entry in @w');
49
50 like($w[0], qr/uninitialized/, 'Correct warning');
51
52 done_testing;