xref: /openbsd-src/gnu/usr.bin/perl/cpan/Module-Load/t/01_Module-Load.t (revision ac9b4aacc1da35008afea06a5d23c2f2dea9b93e)
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|LoadMe.pl|,          0,  'file'  ],
21        [q|LoadIt|,             1,  'ambiguous module'  ],
22        [q|ToBeLoaded|,         0,  'ambiguous file'    ],
23    );
24
25    for my $aref (@Map) {
26        my($mod, $flag, $diag) = @$aref;
27
28        my $file = Module::Load::_to_file($mod, $flag);
29
30        eval { load $mod };
31
32        is( $@, '',                 qq[Loading $diag '$mod' $@] );
33        ok( defined($INC{$file}),   qq[  '$file' found in \%INC] );
34    }
35}
36
37### Test importing functions ###
38{   my $mod     = 'TestModule';
39    my @funcs   = qw[func1 func2];
40
41    eval { load $mod, @funcs };
42    is( $@, '', qq[Loaded exporter module '$mod'] );
43
44    ### test if import gets called properly
45    ok( $mod->imported,                 "   ->import() was called" );
46
47    ### test if functions get exported
48    for my $func (@funcs) {
49        ok( $mod->can($func),           "   $mod->can( $func )" );
50        ok( __PACKAGE__->can($func),    "   we ->can ( $func )" );
51    }
52}
53