4 if( $ENV{PERL_CORE} ) {
16 # ModuleName => q| code to check that it was loaded |,
17 'Cwd' => q| ::is( ref Cwd->can('fastcwd'),'CODE' ) |, # 5.7 ?
18 'File::Glob' => q| ::is( ref File::Glob->can('doglob'),'CODE' ) |, # 5.6
19 'SDBM_File' => q| ::is( ref SDBM_File->can('TIEHASH'), 'CODE' ) |, # 5.0
20 'Socket' => q| ::is( ref Socket->can('inet_aton'),'CODE' ) |, # 5.0
21 'Time::HiRes'=> q| ::is( ref Time::HiRes->can('usleep'),'CODE' ) |, # 5.7.3
24 plan tests => 27 + keys(%modules) * 2;
27 # Try to load the module
28 use_ok( 'DynaLoader' );
32 can_ok( 'DynaLoader' => 'bootstrap' ); # defined in Perl section
33 can_ok( 'DynaLoader' => 'dl_error' ); # defined in XS section
34 can_ok( 'DynaLoader' => 'dl_find_symbol' ); # defined in XS section
35 can_ok( 'DynaLoader' => 'dl_install_xsub' ); # defined in XS section
36 can_ok( 'DynaLoader' => 'dl_load_file' ); # defined in XS section
37 can_ok( 'DynaLoader' => 'dl_load_flags' ); # defined in Perl section
38 can_ok( 'DynaLoader' => 'dl_undef_symbols' ); # defined in XS section
39 can_ok( 'DynaLoader' => 'dl_unload_file' ); # defined in XS section
42 local $TODO = "Test::More::can_ok() seems to have trouble dealing with AutoLoaded functions";
43 can_ok( 'DynaLoader' => 'dl_expandspec' ); # defined in AutoLoaded section
44 can_ok( 'DynaLoader' => 'dl_findfile' ); # defined in AutoLoaded section
45 can_ok( 'DynaLoader' => 'dl_find_symbol_anywhere' ); # defined in AutoLoaded section
49 # Check error messages
51 eval { DynaLoader::bootstrap() };
52 like( $@, q{/^Usage: DynaLoader::bootstrap\(module\)/},
53 "calling DynaLoader::bootstrap() with no argument" );
55 eval { package egg_bacon_sausage_and_spam; DynaLoader::bootstrap("egg_bacon_sausage_and_spam") };
56 like( $@, q{/^Can't locate loadable object for module egg_bacon_sausage_and_spam/},
57 "calling DynaLoader::bootstrap() with a package without binary object" );
59 # .. for dl_load_file()
60 eval { DynaLoader::dl_load_file() };
61 like( $@, q{/^Usage: DynaLoader::dl_load_file\(filename, flags=0\)/},
62 "calling DynaLoader::dl_load_file() with no argument" );
64 eval { DynaLoader::dl_load_file(undef) };
65 is( $@, '', "calling DynaLoader::dl_load_file() with undefined argument" ); # is this expected ?
67 eval { DynaLoader::dl_load_file("egg_bacon_sausage_and_spam") };
68 is( $@, '', "calling DynaLoader::dl_load_file() with undefined argument" );
69 like( DynaLoader::dl_error(), q{/^egg_bacon_sausage_and_spam: cannot open shared object file:/},
70 "calling DynaLoader::dl_load_file() with a package without binary object" );
74 eval { @files = DynaLoader::dl_findfile("c") };
75 is( $@, '', "calling dl_findfile()" );
76 cmp_ok( scalar @files, '>=', 1, " - array should contain one result result or more: libc => (@files)" );
79 # Now try to load well known XS modules
80 my $extensions = $Config{'extensions'};
81 $extensions =~ s|/|::|g;
83 for my $module (sort keys %modules) {
85 skip "$module not available", 2 if $extensions !~ /\b$module\b/;
87 is( $@, '', "loading $module" );
91 # checking internal consistency
92 is( scalar @DynaLoader::dl_librefs, scalar keys %modules, "checking number of items in \@dl_librefs" );
93 is( scalar @DynaLoader::dl_modules, scalar keys %modules, "checking number of items in \@dl_modules" );
95 my @loaded_modules = @DynaLoader::dl_modules;
96 for my $libref (reverse @DynaLoader::dl_librefs) {
97 my $module = pop @loaded_modules;
98 my $r = eval { DynaLoader::dl_unload_file($libref) };
99 is( $@, '', "calling dl_unload_file() for $module" );
100 is( $r, 1, " - unload was successful" );