diff --git a/perlbrew b/perlbrew index 355f14dd..86c9545f 100755 --- a/perlbrew +++ b/perlbrew @@ -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. @@ -44663,6 +44664,12 @@ Install the C standalone executable in C<$PERLBREW_ROOT/bin>. For more rationale about the existence of this command, read +=head1 COMMAND: INSTALL-CPM + +Usage: perlbrew install-cpm + +Install the C standalone executable in C<$PERLBREW_ROOT/bin>. + =head1 COMMAND: INSTALL-PATCHPERL Usage: perlbrew install-patchperl @@ -44827,6 +44834,6 @@ Noted that this does not guarantee that the versions of modules stays the same i =head1 SEE ALSO -L, L, L +L, L, L, L =cut diff --git a/script/perlbrew b/script/perlbrew index 3a518e2f..a2cb3552 100755 --- a/script/perlbrew +++ b/script/perlbrew @@ -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. @@ -494,6 +495,10 @@ Install the C standalone executable in C<$PERLBREW_ROOT/bin>. For more rationale about the existence of this command, read +Usage: perlbrew install-cpm + +Install the C standalone executable in C<$PERLBREW_ROOT/bin>. + =head1 COMMAND: INSTALL-PATCHPERL Usage: perlbrew install-patchperl diff --git a/t/08.error_install_cpm.t b/t/08.error_install_cpm.t new file mode 100644 index 00000000..9a0958d1 --- /dev/null +++ b/t/08.error_install_cpm.t @@ -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; diff --git a/t/command-install-cpm.t b/t/command-install-cpm.t new file mode 100644 index 00000000..a7fb08a3 --- /dev/null +++ b/t/command-install-cpm.t @@ -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; diff --git a/t/failure-command-install-cpm.t b/t/failure-command-install-cpm.t new file mode 100644 index 00000000..c83b0fae --- /dev/null +++ b/t/failure-command-install-cpm.t @@ -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;