Commit | Line | Data |
bb4e9162 |
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 | } else { |
16 | plan tests => 22; |
17 | } |
18 | } |
19 | |
20 | ######################### |
21 | |
22 | |
23 | use Cwd (); |
24 | my $cwd = Cwd::cwd; |
7a827510 |
25 | my $tmp = MBTest->tmpdir; |
bb4e9162 |
26 | |
27 | use DistGen; |
28 | my $dist = DistGen->new( dir => $tmp, xs => 1 ); |
29 | $dist->regen; |
30 | |
31 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
32 | my $mb = Module::Build->new_from_context; |
33 | |
34 | |
35 | eval {$mb->dispatch('clean')}; |
36 | is $@, ''; |
37 | |
38 | eval {$mb->dispatch('build')}; |
39 | is $@, ''; |
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. |
79 | eval {$mb->dispatch('test')}; |
80 | is $@, ''; |
81 | |
82 | eval {$mb->dispatch('clean')}; |
83 | is $@, ''; |
84 | |
85 | |
86 | SKIP: { |
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 | |
96 | eval {$mb->dispatch('realclean')}; |
97 | is $@, ''; |
98 | |
99 | # Make sure blib/ is gone after 'realclean' |
100 | ok ! -e 'blib'; |
101 | |
102 | |
103 | # cleanup |
104 | chdir( $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 | |
3143ec60 |
112 | $dist = DistGen->new( name => 'Simple::With::Deep::Name', |
bb4e9162 |
113 | dir => $tmp, xs => 1 ); |
114 | $dist->regen; |
115 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
116 | |
117 | $mb = Module::Build->new_from_context; |
118 | is $@, ''; |
119 | |
120 | $mb->dispatch('build'); |
121 | is $@, ''; |
122 | |
123 | $mb->dispatch('test'); |
124 | is $@, ''; |
125 | |
126 | $mb->dispatch('realclean'); |
127 | is $@, ''; |
128 | |
129 | # cleanup |
130 | chdir( $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 | |
7a827510 |
144 | $dist->change_build_pl |
145 | ({ |
bb4e9162 |
146 | dist_name => 'Dist-Name', |
147 | dist_version_from => 'Simple.pm', |
148 | pm_files => { 'Simple.pm' => 'lib/Simple.pm' }, |
149 | xs_files => { 'Simple.xs' => 'lib/Simple.xs' }, |
7a827510 |
150 | }); |
bb4e9162 |
151 | |
bb4e9162 |
152 | $dist->add_file('Simple.xs', <<"---"); |
153 | #include "EXTERN.h" |
154 | #include "perl.h" |
155 | #include "XSUB.h" |
156 | |
157 | MODULE = Simple PACKAGE = Simple |
158 | |
159 | SV * |
160 | okay() |
161 | CODE: |
162 | RETVAL = newSVpv( "ok", 0 ); |
163 | OUTPUT: |
164 | RETVAL |
165 | --- |
166 | |
167 | $dist->add_file( 'Simple.pm', <<"---" ); |
168 | package Simple; |
169 | |
170 | \$VERSION = '0.01'; |
171 | |
172 | require Exporter; |
173 | require DynaLoader; |
174 | |
175 | \@ISA = qw( Exporter DynaLoader ); |
176 | \@EXPORT_OK = qw( okay ); |
177 | |
178 | bootstrap Simple \$VERSION; |
179 | |
180 | 1; |
181 | |
182 | __END__ |
183 | |
184 | =head1 NAME |
185 | |
186 | Simple - Perl extension for blah blah blah |
187 | |
188 | =head1 DESCRIPTION |
189 | |
190 | Stub documentation for Simple. |
191 | |
192 | =head1 AUTHOR |
193 | |
194 | A. U. Thor, a.u.thor\@a.galaxy.far.far.away |
195 | |
196 | =cut |
197 | --- |
198 | $dist->change_file('t/basic.t', <<"---"); |
199 | use Test::More tests => 2; |
200 | use strict; |
201 | |
202 | use Simple; |
203 | ok( 1 ); |
204 | |
205 | ok( Simple::okay() eq 'ok' ); |
206 | --- |
207 | |
208 | $dist->regen; |
209 | chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!"; |
210 | |
211 | |
212 | $mb = Module::Build->new_from_context; |
213 | is $@, ''; |
214 | |
215 | $mb->dispatch('build'); |
216 | is $@, ''; |
217 | |
218 | $mb->dispatch('test'); |
219 | is $@, ''; |
220 | |
221 | $mb->dispatch('realclean'); |
222 | is $@, ''; |
223 | |
224 | # cleanup |
225 | chdir( $cwd ) or die "Can''t chdir to '$cwd': $!"; |
226 | $dist->remove; |
227 | |
228 | use File::Path; |
229 | rmtree( $tmp ); |