CPANPLUS-Dist-Build

 view release on metacpan or  search on metacpan

t/02_CPANPLUS-Dist-Build.t  view on Meta::CPAN

            local *CPANPLUS::Module::installed_version = sub {1};
            local *CPANPLUS::Module::packlist = sub { [$p] };
            local *ExtUtils::Installed::files = sub { keys %$p };

            ok( $mod->uninstall,"Uninstalling module" );
        }
    }

    ### throw away all the extracted stuff
    $Utils->_rmdir( dir => $Conf->get_conf('base') );
}

### test ENV setting while running Build.PL code
SKIP: {   ### use print() not die() -- we're redirecting STDERR in tests!
    my $env     = ENV_CPANPLUS_IS_EXECUTING;
    skip("Can't test ENV{$env} -- no buffers available")
      unless IPC::Cmd->can_capture_buffer;
    my $clone   = $Mod->clone;

    ok( $clone,                 'Testing ENV settings $dist->prepare' );

    $clone->status->fetch( File::Spec->catfile($Src, 'noxs', $clone->package) );
    ok( $clone->extract,        '   Files extracted' );

    ### write our own Build.PL file
    my $build_pl = BUILD_PL->( $clone->status->extract );
    {   my $fh   = OPEN_FILE->( $build_pl, '>' );
        print $fh "die qq[ENV=\$ENV{$env}\n];";
        close $fh;
    }
    ok( -e $build_pl,           "   File exists" );

    ### clear errors
    CPANPLUS::Error->flush;

    ### since we're die'ing in the Build.PL, localize
    ### $CPANPLUS::Error::ERROR_FH and redirect to devnull
    ### so we dont spam the result through the test
    ### as this is expected behaviour after all.
    my $rv = do {
        local *CPANPLUS::Error::ERROR_FH;
        open $CPANPLUS::Error::ERROR_FH, ">", File::Spec->devnull;
        $clone->prepare( force => 1 )
    };
    ok( !$rv,                   '   $mod->prepare failed' );

    my $re = quotemeta( $build_pl );
    like( CPANPLUS::Error->stack_as_string, qr/ENV=$re/,
                                "   \$ENV $env set correctly during execution");

    ### and the ENV var should no longer be set now
    ok( !$ENV{$env},            "   ENV var now unset" );
}


sub find_module {
  my $module = shift;

  ### Don't add the .pm yet, in case it's a packlist or something
  ### like ExtUtils::xsubpp.
  my $file = File::Spec->catfile( split m/::/, $module );
  my $candidate;
  foreach (@INC) {
    if (-e ($candidate = File::Spec->catfile($_, $file))
        or
        -e ($candidate = File::Spec->catfile($_, "$file.pm"))
        or
        -e ($candidate = File::Spec->catfile($_, 'auto', $file))
        or
        -e ($candidate = File::Spec->catfile($_, 'auto', "$file.pm"))
        or
        -e ($candidate = File::Spec->catfile($_, $Config{archname},
                                             'auto', $file))
        or
        -e ($candidate = File::Spec->catfile($_, $Config{archname},
                                             'auto', "$file.pm"))) {
      return $candidate;
    }
  }
  return;
}


# Local variables:
# c-indentation-style: bsd
# c-basic-offset: 4
# indent-tabs-mode: nil
# End:
# vim: expandtab shiftwidth=4:



( run in 0.815 second using v1.01-cache-2.11-cpan-483215c6ad5 )