Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let install hint the user to do init. #751

Merged
merged 3 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/App/Perlbrew/Path.pm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ sub new {
bless { path => _joinpath (@path) }, $class;
}

sub exists {
my ($self) = @_;

-e $self->stringify;
}

sub basename {
my ($self, $suffix) = @_;

Expand Down
4 changes: 4 additions & 0 deletions lib/App/perlbrew.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,10 @@ sub do_install_release {
sub run_command_install {
my ($self, $dist, $opts) = @_;

unless ($self->root->exists) {
die("ERROR: perlbrew root " . $self->root . " does not exist. Run `perlbrew init` to prepare it first.\n");
}

unless ($dist) {
$self->run_command_help("install");
exit(-1);
Expand Down
6 changes: 0 additions & 6 deletions t/12.destdir.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ my $DESTDIR = tempdir( CLEANUP => 1 );

use Test::More;

## setup

App::Perlbrew::Path
->new($ENV{PERLBREW_ROOT})
->rmpath;

## mock

no warnings 'redefine';
Expand Down
6 changes: 0 additions & 6 deletions t/12.sitecustomize.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ $ENV{PERLBREW_ROOT} = $App::perlbrew::PERLBREW_ROOT;

use Test::More;

## setup

App::Perlbrew::Path
->new ($ENV{PERLBREW_ROOT})
->rmpath;

## mock

no warnings 'redefine';
Expand Down
24 changes: 24 additions & 0 deletions t/error-install-before-init.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env perl
use strict;
use warnings;

use Test::More;
use Test::Exception;
use File::Temp qw(tempdir);

use App::perlbrew;
use App::Perlbrew::Path;

my $fakehome = tempdir( CLEANUP => 1 );

$ENV{PERLBREW_ROOT} = $App::perlbrew::PERLBREW_ROOT = App::Perlbrew::Path->new($fakehome)->child("perl5")->stringify;

throws_ok(
sub {
my $app = App::perlbrew->new("install", "perl-5.36.0");
$app->run;
},
qr[ERROR: .*perlbrew init.*]
);

done_testing;