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