1 ### make sure we can find our conf.pl file
4 require "$FindBin::Bin/inc/conf.pl";
8 use CPANPLUS::Configure;
10 use CPANPLUS::Internals::Constants;
11 use CPANPLUS::Module::Fake;
12 use CPANPLUS::Module::Author::Fake;
15 use Test::More 'no_plan';
16 use File::Basename qw[basename];
18 use IPC::Cmd 'can_run';
20 $SIG{__WARN__} = sub {warn @_ unless @_ && $_[0] =~ /redefined|isn't numeric/};
22 # Load these two modules in advance, even though they would be
23 # auto-loaded, because we want to override some of their subs.
24 use ExtUtils::Packlist;
25 use ExtUtils::Installed;
27 my $Class = 'CPANPLUS::Dist::Build';
28 my $Utils = 'CPANPLUS::Internals::Utils';
29 my $Have_CC = can_run($Config{'cc'} )? 1 : 0;
30 my $Usedl = $Config{usedl} ? 1 : 0;
33 my $Lib = File::Spec->rel2abs(File::Spec->catdir( qw[dummy-perl] ));
34 my $Src = File::Spec->rel2abs(File::Spec->catdir( qw[src] ));
36 my $Verbose = @ARGV ? 1 : 0;
37 my $Conf = gimme_conf();
38 my $CB = CPANPLUS::Backend->new( $Conf );
40 #$Conf->set_conf( base => 'dummy-cpanplus' );
41 #$Conf->set_conf( dist_type => '' );
42 #$Conf->set_conf( verbose => $Verbose );
43 #$Conf->set_conf( signature => 0 );
44 ### running tests will mess with the test output so skip 'm
45 #$Conf->set_conf( skiptest => 1 );
47 ### create a fake object, so we don't use the actual module tree
48 ### make sure to add dslip data, so CPANPLUS doesn't try to find
49 ### it in another module in the package, for which it needs the
51 my $Mod = CPANPLUS::Module::Fake->new(
54 author => CPANPLUS::Module::Author::Fake->new,
55 package => 'Foo-Bar-0.01.tar.gz',
59 ### dmq tells us that we should run with /nologo
60 ### if using nmake, as it's very noise otherwise.
61 ### XXX copied from CPANPLUS' test include file!
62 { my $make = $Conf->get_program('make');
63 if( $make and basename($make) =~ /^nmake/i and
67 $Conf->set_program( make => $make );
73 my %Map = ( noxs => 0,
78 ### Disable certain possible settings, so we dont accidentally
79 ### touch anything outside our sandbox
81 ### set buildflags to install in our dummy perl dir
82 $Conf->set_conf( buildflags => "install_base=$Lib" );
84 ### don't start sending test reports now... ###
85 $CB->_callbacks->send_test_report( sub { 0 } );
86 $Conf->set_conf( cpantest => 0 );
88 ### we dont need sudo -- we're installing in our own sandbox now
89 $Conf->set_program( sudo => undef );
94 ok( $Class->format_available, "Format is available" );
97 while( my($path,$need_cc) = each %Map ) {
99 my $mod = $Mod->clone;
100 ok( $mod, "Module object created for '$path'" );
102 ### set the fetch location -- it's local
103 { my $where = File::Spec->rel2abs(
104 File::Spec->catfile( $Src, $path, $mod->package )
107 $mod->status->fetch( $where );
109 ok( -e $where, " Tarball '$where' exists" );
112 ok( $mod->prepare, " Preparing module" );
114 ok( $mod->status->dist_cpan,
115 " Dist registered as status" );
117 isa_ok( $mod->status->dist_cpan, $Class );
119 ok( $mod->status->dist_cpan->status->prepared,
120 " Prepared status registered" );
121 is( $mod->status->dist_cpan->status->distdir, $mod->status->extract,
122 " Distdir status registered properly" );
125 is( $mod->status->installer_type, INSTALLER_BUILD,
126 " Proper installer type found" );
129 ### we might not have a C compiler
131 skip("Perl wasn't built with support for dynamic loading " .
132 "-- skipping compile tests", 5) unless $Usedl;
133 skip("The CC compiler listed in Config.pm is not available " .
134 "-- skipping compile tests", 5) if $need_cc && !$Have_CC;
135 skip("Module::Build is not compiled with C support ".
136 "-- skipping compile tests", 5)
137 unless eval { require Module::Build::ConfigData;
138 Module::Build::ConfigData->feature('C_support') };
140 ok( $mod->create( ), "Creating module" );
141 ok( $mod->status->dist_cpan->status->created,
142 " Created status registered" );
146 skip("Install tests require Module::Build 0.2606 or higher", 2)
147 unless $Module::Build::VERSION >= '0.2606';
149 ### flush the lib cache
150 ### otherwise, cpanplus thinks the module's already installed
151 ### since the blib is already in @INC
152 $CB->_flush( list => [qw|lib|] );
154 ### force the install, make sure the Dist::Build->install()
156 ok( $mod->install( force => 1 ),
157 "Installing module" );
158 ok( $mod->status->installed,
159 " Status says module installed" );
163 my $minversion = 0.2609;
164 skip(qq[Uninstalling requires at least Module::Build $minversion], 1)
165 unless eval { Module::Build->VERSION($minversion); 1 };
167 # The installation directory actually needs to be in @INC
168 # in order to test uninstallation
169 { my $libdir = File::Spec->catdir($Lib, 'lib', 'perl5');
171 # lib.pm is documented to require unix-style paths
172 $libdir = VMS::Filespec::unixify($libdir) if $^O eq 'VMS';
174 'lib'->import( $libdir );
177 # EU::Installed and CP+::M are only capable of searching
178 # for modules in the core directories. We need to fake
179 # them out with our own subs here.
180 my $packlist = find_module($mod->name . '::.packlist');
181 ok $packlist, "Found packlist";
183 my $p = ExtUtils::Packlist->new($packlist);
184 ok keys(%$p) > 0, "Packlist contains entries";
186 local *CPANPLUS::Module::installed_version = sub {1};
187 local *CPANPLUS::Module::packlist = sub { [$p] };
188 local *ExtUtils::Installed::files = sub { keys %$p };
190 ok( $mod->uninstall,"Uninstalling module" );
194 ### throw away all the extracted stuff
195 $Utils->_rmdir( dir => $Conf->get_conf('base') );
198 ### test ENV setting while running Build.PL code
199 SKIP: { ### use print() not die() -- we're redirecting STDERR in tests!
200 my $env = ENV_CPANPLUS_IS_EXECUTING;
201 skip("Can't test ENV{$env} -- no buffers available")
202 unless IPC::Cmd->can_capture_buffer;
203 my $clone = $Mod->clone;
205 ok( $clone, 'Testing ENV settings $dist->prepare' );
207 $clone->status->fetch( File::Spec->catfile($Src, 'noxs', $clone->package) );
208 ok( $clone->extract, ' Files extracted' );
210 ### write our own Build.PL file
211 my $build_pl = BUILD_PL->( $clone->status->extract );
212 { my $fh = OPEN_FILE->( $build_pl, '>' );
213 print $fh "die qq[ENV=\$ENV{$env}\n];";
216 ok( -e $build_pl, " File exists" );
219 CPANPLUS::Error->flush;
221 ### since we're die'ing in the Build.PL, localize
222 ### $CPANPLUS::Error::ERROR_FH and redirect to devnull
223 ### so we dont spam the result through the test
224 ### as this is expected behaviour after all.
226 local *CPANPLUS::Error::ERROR_FH;
227 open $CPANPLUS::Error::ERROR_FH, ">", File::Spec->devnull;
228 $clone->prepare( force => 1 )
230 ok( !$rv, ' $mod->prepare failed' );
232 my $re = quotemeta( $build_pl );
233 like( CPANPLUS::Error->stack_as_string, qr/ENV=$re/,
234 " \$ENV $env set correctly during execution");
236 ### and the ENV var should no longer be set now
237 ok( !$ENV{$env}, " ENV var now unset" );
244 ### Don't add the .pm yet, in case it's a packlist or something
245 ### like ExtUtils::xsubpp.
246 my $file = File::Spec->catfile( split m/::/, $module );
249 if (-e ($candidate = File::Spec->catfile($_, $file))
251 -e ($candidate = File::Spec->catfile($_, "$file.pm"))
253 -e ($candidate = File::Spec->catfile($_, 'auto', $file))
255 -e ($candidate = File::Spec->catfile($_, 'auto', "$file.pm"))
257 -e ($candidate = File::Spec->catfile($_, $Config{archname},
260 -e ($candidate = File::Spec->catfile($_, $Config{archname},
261 'auto', "$file.pm"))) {
270 # c-indentation-style: bsd
272 # indent-tabs-mode: nil
274 # vim: expandtab shiftwidth=4: