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