Update CPANPLUS to 0.85_06
[p5sagit/p5-mst-13.2.git] / lib / CPANPLUS / t / 21_CPANPLUS-Dist-No-Build.t
CommitLineData
6aaee015 1### make sure we can find our conf.pl file
2BEGIN {
3 use FindBin;
4 require "$FindBin::Bin/inc/conf.pl";
5}
6
7use strict;
8use Test::More 'no_plan';
4443dd53 9use Module::Loaded;
10use Object::Accessor;
6aaee015 11
12use CPANPLUS::Dist;
13use CPANPLUS::Backend;
4443dd53 14use CPANPLUS::Error;
6aaee015 15use CPANPLUS::Internals::Constants;
16
17my $Conf = gimme_conf();
18my $CB = CPANPLUS::Backend->new( $Conf );
4443dd53 19my $Inst = INSTALLER_BUILD;
6aaee015 20
21### set the config so that we will ignore the build installer,
22### but prefer it anyway
4443dd53 23{ Module::Loaded::mark_as_loaded( $Inst );
24 CPANPLUS::Dist->_ignore_dist_types( $Inst );
6aaee015 25 $Conf->set_conf( prefer_makefile => 0 );
26}
27
28my $Mod = $CB->module_tree( 'Foo::Bar::MB::NOXS' );
29
4443dd53 30ok( $Mod, "Module object retrieved" );
31ok( not grep { $_ eq $Inst } CPANPLUS::Dist->dist_types,
32 " $Inst installer not returned" );
6aaee015 33
34### fetch the file first
35{ my $where = $Mod->fetch;
4443dd53 36 ok( -e $where, " Tarball '$where' exists" );
6aaee015 37}
38
39### extract it, silence warnings/messages
983ffab6 40{ my $where = $Mod->extract;
4443dd53 41 ok( -e $where, " Tarball extracted to '$where'" );
6aaee015 42}
43
44### check the installer type
4443dd53 45{ is( $Mod->status->installer_type, $Inst,
46 "Proper installer type found: $Inst" );
47
48 my $href = $Mod->status->configure_requires;
49 ok( scalar(keys(%$href)), " Dependencies recorded" );
50
51 ok( defined $href->{$Inst}, " Dependency on $Inst" );
6aaee015 52
53 my $err = CPANPLUS::Error->stack_as_string;
4443dd53 54 like( $err, qr/$Inst/, " Message mentions $Inst" );
55 like( $err, qr/prerequisites list/,
56 " Message mentions adding prerequisites" );
57}
58
59### now run the test, it should trigger the installation of the installer
60### XXX whitebox test
61{ no warnings 'redefine';
62
63 ### bootstrapping creates a call to $cb->module_tree('c::d::build')->install
64 ### we need to intercept that call
65 my $org_mt = CPANPLUS::Backend->can('module_tree');
66 local *CPANPLUS::Backend::module_tree = sub {
67 my $self = shift;
68 my $mod = shift;
69
70 ### return a dummy object if this is the bootstrap call
71 return CPANPLUS::Test::Module->new if $mod eq $Inst;
72
73 ### otherwise do a regular call
74 return $org_mt->( $self, $mod, @_ );
75 };
76
77 ### bootstrap install call will abort the ->create() call, so catch
78 ### that here
79 eval { $Mod->create( skiptest => 1) };
80
81 ok( $@, "Create call aborted at bootstrap phase" );
82 like( $@, qr/$Inst/, " Diagnostics confirmed" );
83
84 my $diag = CPANPLUS::Error->stack_as_string;
85 like( $diag, qr/This module requires.*$Inst/,
86 " Dependency on $Inst recorded" );
87 like( $diag, qr/Bootstrapping installer.*$Inst/,
88 " Bootstrap notice recorded" );
89 like( $diag, qr/Installer '$Inst' succesfully bootstrapped/,
90 " Successful bootstrap recorded" );
6aaee015 91}
92
93END { 1 while unlink output_file() }
4443dd53 94
95### place holder package to serve as a module object for C::D::Build
96{ package CPANPLUS::Test::Module;
97 sub new { return bless {} }
98 sub install {
99 ### at load time we ignored C::D::Build. Reset the ignore here
100 ### so a 'rescan' after the 'install' picks up C::D::Build
101 CPANPLUS::Dist->_reset_dist_ignore;
102 return 1;
103 }
104}
105
106### test package for cpanplus::dist::build
107{ package CPANPLUS::Dist::Build;
108 use base 'CPANPLUS::Dist::Base';
109
110 ### shortcut out of the installation procedure
111 sub new { die __PACKAGE__ };
112 sub format_available { 1 }
113 sub init { 1 }
114 sub prepare { 1 }
115 sub create { 1 }
116 sub install { 1 }
117}