1### Module::Load test suite ###
2use strict;
3use warnings;
4
5BEGIN {
6    if( $ENV{PERL_CORE} ) {
7        chdir '../lib/Module/Load' if -d '../lib/Module/Load';
8        unshift @INC, '../../..';
9    }
10}
11
12BEGIN { chdir 't' if -d 't' }
13
14use lib qw[../lib to_load];
15use Module::Load;
16use Test::More 'no_plan';
17
18### test loading files & modules
19{   my @Map = (
20        # module               flag diagnostic
21        [q|Must::Be::Loaded|,   1,  'module'],
22        [q|::Must::Be::Loaded|, 1,  'module'],
23        [q|LoadMe.pl|,          0,  'file'  ],
24        [q|LoadIt|,             1,  'ambiguous module'  ],
25        [q|ToBeLoaded|,         0,  'ambiguous file'    ],
26    );
27
28    for my $aref (@Map) {
29        my($mod, $flag, $diag) = @$aref;
30
31        my $file = Module::Load::_to_file($mod, $flag);
32
33        eval { load $mod };
34
35        is( $@, '',                 qq[Loading $diag '$mod' $@] );
36        ok( defined($INC{$file}),   qq[  '$file' found in \%INC] );
37    }
38}
39
40### Test importing functions ###
41{   my $mod     = 'TestModule';
42    my @funcs   = qw[func1 func2];
43
44    eval { load $mod, @funcs };
45    is( $@, '', qq[Loaded exporter module '$mod'] );
46
47    ### test if import gets called properly
48    ok( $mod->imported,                 "   ->import() was called" );
49
50    ### test if functions get exported
51    for my $func (@funcs) {
52        ok( $mod->can($func),           "   $mod->can( $func )" );
53        ok( __PACKAGE__->can($func),    "   we ->can ( $func )" );
54    }
55}
56