Upgrade to XSLoader-0.07.
[p5sagit/p5-mst-13.2.git] / ext / DynaLoader / t / XSLoader.t
1 #!/usr/bin/perl -T
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = '../lib';
7     }
8 }
9
10 use strict;
11 use Config;
12
13 BEGIN {
14     eval "use Test::More";
15     if ($@) {
16         print "1..0 # Skip: Test::More not available\n";
17         die "Test::More not available\n";
18     }
19 }
20
21
22 my %modules = (
23     # ModuleName  => q|code to check that it was loaded|,
24     'Cwd'        => q| ::can_ok( 'Cwd' => 'fastcwd'         ) |,  # 5.7 ?
25     'File::Glob' => q| ::can_ok( 'File::Glob' => 'doglob'   ) |,  # 5.6
26     'SDBM_File'  => q| ::can_ok( 'SDBM_File' => 'TIEHASH'   ) |,  # 5.0
27     'Socket'     => q| ::can_ok( 'Socket' => 'inet_aton'    ) |,  # 5.0
28     'Time::HiRes'=> q| ::can_ok( 'Time::HiRes' => 'usleep'  ) |,  # 5.7.3
29 );
30
31 plan tests => keys(%modules) * 3 + 5;
32
33 # Try to load the module
34 use_ok( 'XSLoader' );
35
36 # Check functions
37 can_ok( 'XSLoader' => 'load' );
38 can_ok( 'XSLoader' => 'bootstrap_inherit' );
39
40 # Check error messages
41 eval { XSLoader::load() };
42 like( $@, '/^XSLoader::load\(\'Your::Module\', \$Your::Module::VERSION\)/',
43         "calling XSLoader::load() with no argument" );
44
45 eval q{ package Thwack; XSLoader::load('Thwack'); };
46 like( $@, q{/^Can't locate loadable object for module Thwack in @INC/},
47         "calling XSLoader::load() under a package with no XS part" );
48
49 # Now try to load well known XS modules
50 my $extensions = $Config{'extensions'};
51 $extensions =~ s|/|::|g;
52
53 for my $module (sort keys %modules) {
54     SKIP: {
55         skip "$module not available", 3 if $extensions !~ /\b$module\b/;
56
57         eval qq{ package $module; XSLoader::load('$module', "qunckkk"); };
58         like( $@, "/^$module object version \\S+ does not match bootstrap parameter (?:qunckkk|0\\.000)/",  
59                 "calling XSLoader::load() with a XS module and an incorrect version" );
60
61         eval qq{ package $module; XSLoader::load('$module'); };
62         is( $@, '',  "XSLoader::load($module)");
63
64         eval qq{ package $module; $modules{$module}; };
65     }
66 }
67