App-perlbrew

 view release on metacpan or  search on metacpan

t/12.sitecustomize.t  view on Meta::CPAN


sub App::perlbrew::do_install_release {
    my ($self, $dist) = @_;
    my ($dist_name, $dist_version) = $dist =~ m/^(.*)-([\d.]+(?:-RC\d+)?)$/;

    my $name = $dist;
    $name = $self->{as} if $self->{as};

    my $root = App::Perlbrew::Path->new ($ENV{PERLBREW_ROOT});
    my $installation_dir = $root->child("perls", $name);
    $installation_dir->mkpath;
    $root->child("perls", $name, "bin")->mkpath;

    my $perl = $root->child("perls", $name, "bin")->child("perl");
    write_file($perl, "#!/bin/sh\nperl \"\$@\";\n");
    chmod 0755, $perl;

    # fake the install
    $self->do_install_this("/tmp/fake-src/perl-5.14.2", $dist_version, $dist);
}

use warnings;

## main

note "PERLBREW_ROOT set to $ENV{PERLBREW_ROOT}";

subtest "No perls yet installed" => sub {
    my $app = App::perlbrew->new;
    my @installed = grep { !$_->{is_external} } $app->installed_perls;
    is 0+@installed, 0, "no perls installed";
};

subtest "--sitecustomize option can be set" => sub {
    my $app = App::perlbrew->new('install', 'perl-5.14.2',
        '--sitecustomize=mysitecustomize.pl'
    );

    is join(' ', $app->args), join(' ', qw(install perl-5.14.2)), "post-option args correct";
    is $app->{sitecustomize}, 'mysitecustomize.pl', '--sitecustomize set as expected';
};

subtest "mock installing" => sub {
    my $sitefile = File::Temp->new;
    print $sitefile "use strict;\n";
    close $sitefile;
    my $app = App::perlbrew->new('install', 'perl-5.14.2',
        "--sitecustomize=$sitefile"
    );
    my ($output,$error) = capture { $app->run };

    my @installed = grep { !$_->{is_external} } $app->installed_perls;
    is 0+@installed, 1, "found 1 installed perl";

    is $installed[0]->{name}, "perl-5.14.2", "found expected perl";
    my $root = App::Perlbrew::Path->new ($ENV{PERLBREW_ROOT});
    my $perldir = $root->child("perls", "perl-5.14.2");
    my $installedsite = $perldir->child('lib', 'site_perl', '5.14.2', 'sitecustomize.pl');
    ok( -f $installedsite, "sitecustomize.pl installed" );

    my $guts = do { local (@ARGV, $/) = $installedsite; <> };
    is( $guts, "use strict;\n", "sitecustomize.pl contents correct" );
};

done_testing;
# vim: ts=4 sts=4 sw=4 et:



( run in 2.760 seconds using v1.01-cache-2.11-cpan-364913b4093 )