1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
#!/usr/bin/perl -w
use strict;
use lib 't/lib';
use MBTest;
use Config;
my $tmp;
blib_load('Module::Build');
{
my ($have_c_compiler, $tmp_exec) = check_compiler();
if ( !$have_c_compiler ) {
plan skip_all => 'No compiler found';
} elsif ( !$tmp_exec ) {
plan skip_all => 'Compiler is dysfunctional';
} elsif ( $^O eq 'VMS' ) {
plan skip_all => 'Child test output confuses harness';
} elsif ( !$Config{usedl} ) {
plan skip_all => 'Perl not compiled for dynamic loading'
} else {
plan tests => 22;
}
require Cwd;
$tmp = MBTest->tmpdir( $tmp_exec ? () : (DIR => Cwd::cwd) );
}
#########################
use DistGen;
my $dist = DistGen->new( dir => $tmp, xs => 1 )->chdir_in->regen;
my $mb = $dist->new_from_context;
eval {$mb->dispatch('clean')};
is $@, '';
eval {$mb->dispatch('build')};
is $@, '';
{
# Make sure it actually works: that we can call methods in the XS module
# Unfortunately, We must do this is a subprocess because some OS will not
# release the handle on a dynamic lib until the attaching process terminates
ok $mb->run_perl_command(['-Mblib', '-M'.$dist->name, '-e1']);
like stdout_of( sub {$mb->run_perl_command([
'-Mblib', '-M'.$dist->name,
'-we', "print @{[$dist->name]}::okay()"])}), qr/ok$/;
like stdout_of( sub {$mb->run_perl_command([
'-Mblib', '-M'.$dist->name,
'-we', "print @{[$dist->name]}::version()"])}), qr/0.01$/;
like stdout_of( sub {$mb->run_perl_command([
'-Mblib', '-M'.$dist->name,
'-we', "print @{[$dist->name]}::xs_version()"])}), qr/0.01$/;
}
{
# Try again in a subprocess
eval {$mb->dispatch('clean')};
is $@, '';
$mb->create_build_script;
my $script = $mb->build_script;
ok -e $script;
eval {$mb->run_perl_script($script)};
is $@, '';
}
# We can't be verbose in the sub-test, because Test::Harness will
# think that the output is for the top-level test.
stdout_stderr_of( sub { eval {$mb->dispatch('test')} });
is $@, '';
eval {$mb->dispatch('clean')};
is $@, '';
SKIP: {
skip( "skipping a Unixish-only tests", 1 )
unless $mb->is_unixish;
$mb->{config}->push(ld => "FOO=BAR ".$mb->config('ld'));
eval {$mb->dispatch('build')};
is $@, '';
$mb->{config}->pop('ld');
}
eval {$mb->dispatch('realclean')};
is $@, '';
# Make sure blib/ is gone after 'realclean'
ok ! -e 'blib';
########################################
# Try a XS distro with a deep namespace
$dist->reset( name => 'Simple::With::Deep::Name', dir => $tmp, xs => 1 );
$dist->chdir_in->regen;
$mb = $dist->new_from_context;
eval { $mb->dispatch('build') };
is $@, '';
stdout_stderr_of( sub { eval { $mb->dispatch('test') } } );
is $@, '';
eval { $mb->dispatch('clean') };
eval { $mb->dispatch('build', 'pureperl_only' => 1) };
like $@, qr/\ACan\'t build xs files under --pureperl-only/, 'Can\'t build xs under pureperl';
eval { $mb->dispatch('build', pureperl_only => 1, allow_pureperl => 1) };
is $@, '', 'Can\'t build xs under pureperl, unless allow_pureperl';
eval { $mb->dispatch('realclean') };
is $@, '';
########################################
# Try a XS distro using a flat directory structure
# and a 'dist_name' instead of a 'module_name'
$dist->reset( name => 'Dist-Name', dir => $tmp, xs => 1 )->chdir_in;
$dist->remove_file('lib/Dist-Name.pm');
$dist->remove_file('lib/Dist-Name.xs');
$dist->change_build_pl
({
dist_name => 'Dist-Name',
dist_version_from => 'Simple.pm',
pm_files => { 'Simple.pm' => 'lib/Simple.pm' },
xs_files => { 'Simple.xs' => 'lib/Simple.xs' },
});
$dist->add_file('Simple.xs', <<"---");
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
MODULE = Simple PACKAGE = Simple
SV *
okay()
CODE:
RETVAL = newSVpv( "ok", 0 );
OUTPUT:
RETVAL
---
$dist->add_file( 'Simple.pm', <<"---" );
package Simple;
use strict;
use warnings;
our \$VERSION = '0.01';
require Exporter;
require DynaLoader;
our \@ISA = qw( Exporter DynaLoader );
our \@EXPORT_OK = qw( okay );
bootstrap Simple \$VERSION;
1;
__END__
=head1 NAME
Simple - Perl extension for blah blah blah
=head1 DESCRIPTION
Stub documentation for Simple.
=head1 AUTHOR
A. U. Thor, a.u.thor\@a.galaxy.far.far.away
=cut
---
$dist->change_file('t/basic.t', <<"---");
use Test::More tests => 2;
use strict;
use Simple;
ok( 1 );
ok( Simple::okay() eq 'ok' );
---
$dist->regen;
$mb = $dist->new_from_context;
eval { $mb->dispatch('build') };
is $@, '';
stdout_of( sub { eval { $mb->dispatch('test') } } );
is $@, '';
eval { $mb->dispatch('realclean') };
is $@, '';
|