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