4 use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
9 my ($have_c_compiler, $C_support_feature) = check_compiler();
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';
20 #########################
25 my $tmp = File::Spec->catdir( $cwd, 't', '_tmp' );
28 my $dist = DistGen->new( dir => $tmp, xs => 1 );
31 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
32 my $mb = Module::Build->new_from_context;
35 eval {$mb->dispatch('clean')};
38 eval {$mb->dispatch('build')};
42 # Make sure it actually works: that we can call methods in the XS module
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
47 ok $mb->run_perl_command(['-Mblib', '-M'.$dist->name, '-e1']);
49 like stdout_of( sub {$mb->run_perl_command([
50 '-Mblib', '-M'.$dist->name,
51 '-we', "print @{[$dist->name]}::okay()"])}), qr/ok$/;
53 like stdout_of( sub {$mb->run_perl_command([
54 '-Mblib', '-M'.$dist->name,
55 '-we', "print @{[$dist->name]}::version()"])}), qr/0.01$/;
57 like stdout_of( sub {$mb->run_perl_command([
58 '-Mblib', '-M'.$dist->name,
59 '-we', "print @{[$dist->name]}::xs_version()"])}), qr/0.01$/;
64 # Try again in a subprocess
65 eval {$mb->dispatch('clean')};
68 $mb->create_build_script;
71 eval {$mb->run_perl_script('Build')};
75 # We can't be verbose in the sub-test, because Test::Harness will
76 # think that the output is for the top-level test.
77 eval {$mb->dispatch('test')};
80 eval {$mb->dispatch('clean')};
85 skip( "skipping a Unixish-only tests", 1 )
86 unless $mb->os_type eq 'Unix';
88 local $mb->{config}{ld} = "FOO=BAR $mb->{config}{ld}";
89 eval {$mb->dispatch('build')};
93 eval {$mb->dispatch('realclean')};
96 # Make sure blib/ is gone after 'realclean'
101 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
105 ########################################
107 # Try a XS distro with a deep namespace
109 $dist = DistGen->new( name => 'Simple::With::Deep::Namespace',
110 dir => $tmp, xs => 1 );
112 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
114 $mb = Module::Build->new_from_context;
117 $mb->dispatch('build');
120 $mb->dispatch('test');
123 $mb->dispatch('realclean');
127 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";
131 ########################################
133 # Try a XS distro using a flat directory structure
134 # and a 'dist_name' instead of a 'module_name'
136 $dist = DistGen->new( name => 'Dist-Name', dir => $tmp, xs => 1 );
138 $dist->remove_file('lib/Dist-Name.pm');
139 $dist->remove_file('lib/Dist-Name.xs');
141 $dist->change_file('Build.PL', <<"---");
145 my \$builder = Module::Build->new(
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' },
152 \$builder->create_build_script();
154 $dist->add_file('Simple.xs', <<"---");
159 MODULE = Simple PACKAGE = Simple
164 RETVAL = newSVpv( "ok", 0 );
169 $dist->add_file( 'Simple.pm', <<"---" );
177 \@ISA = qw( Exporter DynaLoader );
178 \@EXPORT_OK = qw( okay );
180 bootstrap Simple \$VERSION;
188 Simple - Perl extension for blah blah blah
192 Stub documentation for Simple.
196 A. U. Thor, a.u.thor\@a.galaxy.far.far.away
200 $dist->change_file('t/basic.t', <<"---");
201 use Test::More tests => 2;
207 ok( Simple::okay() eq 'ok' );
211 chdir( $dist->dirname ) or die "Can't chdir to '@{[$dist->dirname]}': $!";
214 $mb = Module::Build->new_from_context;
217 $mb->dispatch('build');
220 $mb->dispatch('test');
223 $mb->dispatch('realclean');
227 chdir( $cwd ) or die "Can''t chdir to '$cwd': $!";