Moved Module::Load from lib/ to ext/
[p5sagit/p5-mst-13.2.git] / ext / Module-Load / t / 01_Module-Load.t
CommitLineData
0819efc5 1### Module::Load test suite ###
85a8a980 2BEGIN {
0819efc5 3 if( $ENV{PERL_CORE} ) {
4 chdir '../lib/Module/Load' if -d '../lib/Module/Load';
5 unshift @INC, '../../..';
6 }
85a8a980 7}
0819efc5 8
9BEGIN { chdir 't' if -d 't' }
10
11use strict;
12use lib qw[../lib to_load];
13use Module::Load;
85a8a980 14use Test::More 'no_plan';
0819efc5 15
85a8a980 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 );
0819efc5 24
85a8a980 25 for my $aref (@Map) {
26 my($mod, $flag, $diag) = @$aref;
0819efc5 27
85a8a980 28 my $file = Module::Load::_to_file($mod, $flag);
0819efc5 29
85a8a980 30 eval { load $mod };
0819efc5 31
85a8a980 32 is( $@, '', qq[Loading $diag '$mod' $@] );
33 ok( defined($INC{$file}), qq[ '$file' found in \%INC] );
34 }
0819efc5 35}
36
37### Test importing functions ###
38{ my $mod = 'TestModule';
39 my @funcs = qw[func1 func2];
85a8a980 40
0819efc5 41 eval { load $mod, @funcs };
42 is( $@, '', qq[Loaded exporter module '$mod'] );
85a8a980 43
44 ### test if import gets called properly
45 ok( $mod->imported, " ->import() was called" );
46
47 ### test if functions get exported
0819efc5 48 for my $func (@funcs) {
85a8a980 49 ok( $mod->can($func), " $mod->can( $func )" );
50 ok( __PACKAGE__->can($func), " we ->can ( $func )" );
51 }
52}