summaryrefslogtreecommitdiff
path: root/cpan/CPANPLUS/t/21_CPANPLUS-Dist-No-Build.t
blob: 10a2745d80d0c4a374501e3a3271d777e6750f64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
### make sure we can find our conf.pl file
BEGIN {
    use FindBin;
    require "$FindBin::Bin/inc/conf.pl";
}

use strict;
use Test::More 'no_plan';
use Module::Loaded;
use Object::Accessor;

use CPANPLUS::Dist;
use CPANPLUS::Backend;
use CPANPLUS::Error;
use CPANPLUS::Internals::Constants;

my $Conf    = gimme_conf();
my $CB      = CPANPLUS::Backend->new( $Conf );
my $Inst    = INSTALLER_BUILD;

### set the config so that we will ignore the build installer,
### but prefer it anyway
{   Module::Loaded::mark_as_loaded( $Inst );
    CPANPLUS::Dist->_ignore_dist_types( $Inst );
    $Conf->set_conf( prefer_makefile => 0 );
}

my $Mod = $CB->module_tree( 'Foo::Bar::MB::NOXS' );

ok( $Mod,                       "Module object retrieved" );
ok( not grep { $_ eq $Inst } CPANPLUS::Dist->dist_types,
                                "   $Inst installer not returned" );

### fetch the file first
{   my $where = $Mod->fetch;
    ok( -e $where,              "   Tarball '$where' exists" );
}

### extract it, silence warnings/messages
{   my $where = $Mod->extract;
    ok( -e $where,              "   Tarball extracted to '$where'" );
}

### check the installer type
{   is( $Mod->status->installer_type, $Inst,
                                "Proper installer type found: $Inst" );

    my $href = $Mod->status->configure_requires;
    ok( scalar(keys(%$href)),   "   Dependencies recorded" );

    ok( defined $href->{$Inst}, "       Dependency on $Inst" );
    cmp_ok( $href->{$Inst}, '>', 0,
                                "           Minimum version: $href->{$Inst}" );

    my $err = CPANPLUS::Error->stack_as_string;
    like( $err, qr/$Inst/,      "   Message mentions $Inst" );
    like( $err, qr/prerequisites list/,
                                "   Message mentions adding prerequisites" );
}

### now run the test, it should trigger the installation of the installer
### XXX whitebox test
{   no warnings 'redefine';

    ### bootstrapping creates a call to $cb->module_tree('c::d::build')->install
    ### we need to intercept that call
    my $org_mt = CPANPLUS::Backend->can('module_tree');
    local *CPANPLUS::Backend::module_tree = sub {
        my $self = shift;
        my $mod  = shift;

        ### return a dummy object if this is the bootstrap call
        return CPANPLUS::Test::Module->new if $mod eq $Inst;

        ### otherwise do a regular call
        return $org_mt->( $self, $mod, @_ );
    };

    ### bootstrap install call will abort the ->create() call, so catch
    ### that here
    eval { $Mod->create( skiptest => 1) };

    ok( $@,                     "Create call aborted at bootstrap phase" );
    like( $@, qr/$Inst/,        "   Diagnostics confirmed" );

    my $diag = CPANPLUS::Error->stack_as_string;
    like( $diag, qr/This module requires.*$Inst/,
                                "   Dependency on $Inst recorded" );
    like( $diag, qr/Bootstrapping installer.*$Inst/,
                                "       Bootstrap notice recorded" );
    like( $diag, qr/Installer '$Inst' successfully bootstrapped/,
                                "       Successful bootstrap recorded" );
}

END { 1 while unlink output_file()  }

### place holder package to serve as a module object for C::D::Build
{   package CPANPLUS::Test::Module;
    sub new     { return bless {} }
    sub install {
        ### at load time we ignored C::D::Build. Reset the ignore here
        ### so a 'rescan' after the 'install' picks up C::D::Build
        CPANPLUS::Dist->_reset_dist_ignore;
        return 1;
    }
}

### test package for cpanplus::dist::build
{   package CPANPLUS::Dist::Build;
    use base 'CPANPLUS::Dist::Base';

    ### shortcut out of the installation procedure
    sub new                 { die __PACKAGE__ };
    sub format_available    { 1 }
    sub init                { 1 }
    sub prepare             { 1 }
    sub create              { 1 }
    sub install             { 1 }
}