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