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