Skip to content

Commit

Permalink
Merge pull request #746 from Tekki/install-cpm
Browse files Browse the repository at this point in the history
Document and test install-cpm command.
  • Loading branch information
gugod committed Jul 14, 2022
2 parents 9781f82 + 057daa2 commit 65daf9c
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
9 changes: 8 additions & 1 deletion perlbrew
Original file line number Diff line number Diff line change
Expand Up @@ -44211,6 +44211,7 @@ Commands:

install-patchperl Install patchperl
install-cpanm Install cpanm, a friendly companion.
install-cpm Install cpm, a faster but still friendly companion.
install-multiple Install multiple versions and flavors of perl

download Download the specified perl distribution tarball.
Expand Down Expand Up @@ -44663,6 +44664,12 @@ Install the C<cpanm> standalone executable in C<$PERLBREW_ROOT/bin>.
For more rationale about the existence of this command, read
<http://perlbrew.pl/Perlbrew-and-Friends.html>

=head1 COMMAND: INSTALL-CPM

Usage: perlbrew install-cpm

Install the C<cpm> standalone executable in C<$PERLBREW_ROOT/bin>.

=head1 COMMAND: INSTALL-PATCHPERL

Usage: perlbrew install-patchperl
Expand Down Expand Up @@ -44827,6 +44834,6 @@ Noted that this does not guarantee that the versions of modules stays the same i

=head1 SEE ALSO

L<App::perlbrew>, L<App::cpanminus>, L<Devel::PatchPerl>
L<App::perlbrew>, L<App::cpanminus>, L<App::cpm>, L<Devel::PatchPerl>

=cut
5 changes: 5 additions & 0 deletions script/perlbrew
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Commands:
install-patchperl Install patchperl
install-cpanm Install cpanm, a friendly companion.
install-cpm Install cpm, a faster but still friendly companion.
install-multiple Install multiple versions and flavors of perl
download Download the specified perl distribution tarball.
Expand Down Expand Up @@ -494,6 +495,10 @@ Install the C<cpanm> standalone executable in C<$PERLBREW_ROOT/bin>.
For more rationale about the existence of this command, read
<http://perlbrew.pl/Perlbrew-and-Friends.html>
Usage: perlbrew install-cpm
Install the C<cpm> standalone executable in C<$PERLBREW_ROOT/bin>.
=head1 COMMAND: INSTALL-PATCHPERL
Usage: perlbrew install-patchperl
Expand Down
24 changes: 24 additions & 0 deletions t/08.error_install_cpm.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env perl
use strict;
use warnings;

use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require 'test_helpers.pl';

use Test::More;
use Test::Exception;

no warnings 'redefine';
sub App::perlbrew::http_get { "" }

throws_ok(
sub {
my $app = App::perlbrew->new("install-cpm");
$app->run;
},
qr[ERROR: Failed to retrieve cpm executable.]
);

done_testing;
31 changes: 31 additions & 0 deletions t/command-install-cpm.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::Spec;
use File::Temp qw( tempdir );

use App::perlbrew;
$App::perlbrew::PERLBREW_ROOT = my $perlbrew_root = tempdir( CLEANUP => 1 );
$App::perlbrew::PERLBREW_HOME = my $perlbrew_home = tempdir( CLEANUP => 1 );

{
no warnings 'redefine';
sub App::perlbrew::http_get {
my ($url) = @_;
like $url, qr/cpm$/, "GET cpm url: $url";
return "#!/usr/bin/env perl\n# The content of cpm";
}
}

describe "App::perlbrew->install_cpm" => sub {
it "should produce 'cpm' in the bin dir" => sub {
my $app = App::perlbrew->new("install-cpm", "-q");
$app->run();

my $cpm = App::Perlbrew::Path->new($perlbrew_root, "bin", "cpm");
ok -f $cpm, "cpm is produced. $cpm";
ok -x $cpm, "cpm should be an executable.";
};
};

runtests unless caller;
38 changes: 38 additions & 0 deletions t/failure-command-install-cpm.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env perl
use strict;
use warnings;
use Test::Spec;
use File::Temp qw( tempdir );

use App::perlbrew;
$App::perlbrew::PERLBREW_ROOT = my $perlbrew_root = tempdir( CLEANUP => 1 );
$App::perlbrew::PERLBREW_HOME = my $perlbrew_home = tempdir( CLEANUP => 1 );

{
no warnings 'redefine';
sub App::perlbrew::http_get {
my ($url) = @_;
like $url, qr/cpm$/, "GET cpm url: $url";
return "404 not found.";
}
}

describe "App::perlbrew->install_cpm" => sub {
it "should no produced 'cpm' in the bin dir, if the downloaded content seems to be invalid." => sub {
my $error;
my $error_produced = 0;
eval {
my $app = App::perlbrew->new("install-cpm", "-q");
$app->run();
} or do {
$error = $@;
$error_produced = 1;
};

my $cpm = App::Perlbrew::Path->new($perlbrew_root, "bin", "cpm");
ok $error_produced, "generated an error: $error";
ok !(-f $cpm), "cpm is not produced. $cpm";
};
};

runtests unless caller;

0 comments on commit 65daf9c

Please sign in to comment.