CPANPLUS

 view release on metacpan or  search on metacpan

t/20_CPANPLUS-Dist-MM.t  view on Meta::CPAN

### make sure we can find our conf.pl file
BEGIN {
    use FindBin;
    require "$FindBin::Bin/inc/conf.pl";
}

use strict;

use CPANPLUS::Configure;
use CPANPLUS::Backend;
use CPANPLUS::Dist;
use CPANPLUS::Dist::MM;
use CPANPLUS::Internals::Constants;

use Test::More 'no_plan';
use Cwd;
use Config;
use Data::Dumper;
use File::Basename ();
use File::Spec ();

my $conf    = gimme_conf();
my $cb      = CPANPLUS::Backend->new( $conf );
my $File    = 'Bar.pm';

### if we need sudo that's no guarantee we can actually run it
### so set $noperms if sudo is required, as that may mean tests
### fail if you're not allowed to execute sudo. This resolves
### #29904: make test should not use sudo
my $noperms = $conf->get_program('sudo')        || #you need sudo
              $conf->get_conf('makemakerflags') || #you set some funky flags
              not -w $Config{installsitelib};      #cant write to install target

#$IPC::Cmd::DEBUG = $Verbose;

### Make sure we get the _EUMM_NOXS_ version
my $ModName = TEST_CONF_MODULE;

### This is the module name that gets /installed/
my $InstName = TEST_CONF_INST_MODULE;

### don't start sending test reports now... ###
$cb->_callbacks->send_test_report( sub { 0 } );
$conf->set_conf( cpantest => 0 );

### Redirect errors to file ###
*STDERR = output_handle() unless $conf->get_conf('verbose');

### dont uncomment this, it screws up where STDOUT goes and makes
### test::harness create test counter mismatches
#*STDOUT                          = output_handle() unless @ARGV;
### for the same test-output counter mismatch, we disable verbose
### mode
$conf->set_conf( allow_build_interactivity => 0 );

### start with fresh sources ###
ok( $cb->reload_indices( update_source => 0 ),
                                "Rebuilding trees" );

### we might need this Some Day when we're going to install into
### our own sandbox dir.. but for now, no dice due to EU::I bug
# $conf->set_program( sudo => '' );
# $conf->set_conf( makemakerflags => TEST_INSTALL_EU_MM_FLAGS );

### set alternate install dir ###
### XXX rather pointless, since we can't uninstall them, due to a bug
### in EU::Installed (6871). And therefor we can't test uninstall() or any of
### the EU::Installed functions. So, let's just install into sitelib... =/
#my $prefix  = File::Spec->rel2abs( File::Spec->catdir(cwd(),'dummy-perl') );
#my $rv = $cb->configure_object->set_conf( makemakerflags => "PREFIX=$prefix" );
#ok( $rv,                        "Alternate install path set" );

my $Mod     = $cb->module_tree( $ModName );
my $InstMod = $cb->module_tree( $InstName );
ok( $Mod,                       "Loaded object for: " . $Mod->name );
ok( $Mod,                       "Loaded object for: " . $InstMod->name );

### format_available tests ###
{   ok( CPANPLUS::Dist::MM->format_available,
                                "Format is available" );

    ### whitebox test!
    {   local $^W;
        local *CPANPLUS::Dist::MM::can_load = sub { 0 };
        ok(!CPANPLUS::Dist::MM->format_available,
                                "   Making format unavailable" );
    }

    ### test if the error got logged ok ###
    like( CPANPLUS::Error->stack_as_string,
          qr/You do not have .+?'CPANPLUS::Dist::MM' not available/s,
                                "   Format failure logged" );

    ### flush the stack ###
    CPANPLUS::Error->flush;
}

ok( $Mod->fetch,                "Fetching module to ".$Mod->status->fetch );
ok( $Mod->extract,              "Extracting module to ".$Mod->status->extract );

### test target => 'init'
{   my $dist = $Mod->dist( target => TARGET_INIT );
    ok( $dist,                  "Dist created with target => " . TARGET_INIT );



( run in 2.675 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )