Add ExtUtils::Miniperl to the list of core modules for all versions >= 5.00504
[p5sagit/p5-mst-13.2.git] / lib / Module / Build / t / xs.t
1 #!/usr/bin/perl -w
2
3 use strict;
4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
5 use MBTest;
6 use 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   } elsif ( $^O eq 'VMS' ) {
16     plan skip_all => 'Child test output confuses harness';
17   } else {
18     plan tests => 23;
19   }
20 }
21
22 ensure_blib('Module::Build');
23
24
25 #########################
26
27
28 my $tmp = MBTest->tmpdir;
29
30 use DistGen;
31 my $dist = DistGen->new( dir => $tmp, xs => 1 );
32 $dist->regen;
33
34 $dist->chdir_in;
35 my $mb = Module::Build->new_from_context;
36
37
38 eval {$mb->dispatch('clean')};
39 is $@, '';
40
41 eval {$mb->dispatch('build')};
42 is $@, '';
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
71
72   $mb->create_build_script;
73   my $script = $mb->build_script;
74   ok -e $script;
75
76   eval {$mb->run_perl_script($script)};
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.
82 eval {$mb->dispatch('test')};
83 is $@, '';
84
85 eval {$mb->dispatch('clean')};
86 is $@, '';
87
88
89 SKIP: {
90   skip( "skipping a Unixish-only tests", 1 )
91       unless $mb->is_unixish;
92
93   $mb->{config}->push(ld => "FOO=BAR ".$mb->config('ld'));
94   eval {$mb->dispatch('build')};
95   is $@, '';
96   $mb->{config}->pop('ld');
97 }
98
99 eval {$mb->dispatch('realclean')};
100 is $@, '';
101
102 # Make sure blib/ is gone after 'realclean'
103 ok ! -e 'blib';
104
105
106 # cleanup
107 $dist->remove;
108
109
110 ########################################
111
112 # Try a XS distro with a deep namespace
113
114 $dist = DistGen->new( name => 'Simple::With::Deep::Name',
115                       dir => $tmp, xs => 1 );
116 $dist->regen;
117 $dist->chdir_in;
118
119 $mb = Module::Build->new_from_context;
120 is $@, '';
121
122 $mb->dispatch('build');
123 is $@, '';
124
125 $mb->dispatch('test');
126 is $@, '';
127
128 $mb->dispatch('realclean');
129 is $@, '';
130
131 # cleanup
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
145 $dist->change_build_pl
146   ({
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' },
151   });
152
153 $dist->add_file('Simple.xs', <<"---");
154 #include "EXTERN.h"
155 #include "perl.h"
156 #include "XSUB.h"
157
158 MODULE = Simple         PACKAGE = Simple
159
160 SV *
161 okay()
162     CODE:
163         RETVAL = newSVpv( "ok", 0 );
164     OUTPUT:
165         RETVAL
166 ---
167
168 $dist->add_file( 'Simple.pm', <<"---" );
169 package Simple;
170
171 \$VERSION = '0.01';
172
173 require Exporter;
174 require DynaLoader;
175
176 \@ISA = qw( Exporter DynaLoader );
177 \@EXPORT_OK = qw( okay );
178
179 bootstrap Simple \$VERSION;
180
181 1;
182
183 __END__
184
185 =head1 NAME
186
187 Simple - Perl extension for blah blah blah
188
189 =head1 DESCRIPTION
190
191 Stub documentation for Simple.
192
193 =head1 AUTHOR
194
195 A. U. Thor, a.u.thor\@a.galaxy.far.far.away
196
197 =cut
198 ---
199 $dist->change_file('t/basic.t', <<"---");
200 use Test::More tests => 2;
201 use strict;
202
203 use Simple;
204 ok( 1 );
205
206 ok( Simple::okay() eq 'ok' );
207 ---
208
209 $dist->regen;
210 $dist->chdir_in;
211
212
213 $mb = Module::Build->new_from_context;
214 is $@, '';
215
216 $mb->dispatch('build');
217 is $@, '';
218
219 $mb->dispatch('test');
220 is $@, '';
221
222 $mb->dispatch('realclean');
223 is $@, '';
224
225 # cleanup
226 $dist->remove;