From 33089258eec06b9ba0b0a6002f85456d18a36d18 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Thu, 21 Jul 2022 23:50:47 +0900 Subject: [PATCH 1/3] Let `install` hint the user to do `init`. ... if PERLBREW_ROOT is missing. --- lib/App/Perlbrew/Path.pm | 6 ++++++ lib/App/perlbrew.pm | 5 +++++ t/error-install-before-init.t | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 t/error-install-before-init.t diff --git a/lib/App/Perlbrew/Path.pm b/lib/App/Perlbrew/Path.pm index 74aa835b..26a156b5 100644 --- a/lib/App/Perlbrew/Path.pm +++ b/lib/App/Perlbrew/Path.pm @@ -38,6 +38,12 @@ sub new { bless { path => _joinpath (@path) }, $class; } +sub exists { + my ($self) = @_; + + -e $self->stringify; +} + sub basename { my ($self, $suffix) = @_; diff --git a/lib/App/perlbrew.pm b/lib/App/perlbrew.pm index bdf281e5..fb489142 100644 --- a/lib/App/perlbrew.pm +++ b/lib/App/perlbrew.pm @@ -1282,6 +1282,11 @@ 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"); + exit(-1); + } + unless ($dist) { $self->run_command_help("install"); exit(-1); diff --git a/t/error-install-before-init.t b/t/error-install-before-init.t new file mode 100644 index 00000000..1f5dd0f1 --- /dev/null +++ b/t/error-install-before-init.t @@ -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; From 02dcc71320c63bcb93f729ee284ad4f357194722 Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Fri, 22 Jul 2022 00:23:45 +0900 Subject: [PATCH 2/3] remove that unreachable exit. --- lib/App/perlbrew.pm | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/App/perlbrew.pm b/lib/App/perlbrew.pm index fb489142..6a8c1f27 100644 --- a/lib/App/perlbrew.pm +++ b/lib/App/perlbrew.pm @@ -1284,7 +1284,6 @@ sub run_command_install { unless ($self->root->exists) { die("ERROR: perlbrew root " . $self->root . " does not exist. Run `perlbrew init` to prepare it first.\n"); - exit(-1); } unless ($dist) { From ba06b6cb4e25124e807a82a9431a61f7f371a85e Mon Sep 17 00:00:00 2001 From: Kang-min Liu Date: Fri, 22 Jul 2022 00:32:40 +0900 Subject: [PATCH 3/3] Adjust a few tests after changing `install` command. Since it would errro when PERLBREW_ROOT is missing, we need to ensure PERLBRE_ROOT exist if we intend to run `install` in the test code. --- t/12.destdir.t | 6 ------ t/12.sitecustomize.t | 6 ------ 2 files changed, 12 deletions(-) diff --git a/t/12.destdir.t b/t/12.destdir.t index a85a42a2..0a2b44dc 100644 --- a/t/12.destdir.t +++ b/t/12.destdir.t @@ -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'; diff --git a/t/12.sitecustomize.t b/t/12.sitecustomize.t index ac2f8335..74570fdd 100644 --- a/t/12.sitecustomize.t +++ b/t/12.sitecustomize.t @@ -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';