Skip to content

Commit

Permalink
Merge pull request #93 from skaji/with-without
Browse files Browse the repository at this point in the history
add all with/without options for consistency
  • Loading branch information
skaji committed Jun 24, 2017
2 parents b004005 + 57cb139 commit 9af2c7d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 21 deletions.
26 changes: 17 additions & 9 deletions lib/App/cpm.pm
Expand Up @@ -36,6 +36,14 @@ sub new {
configure_timeout => 60,
build_timeout => 3600,
test_timeout => 1800,
with_requires => 1,
with_recommends => 0,
with_suggests => 0,
with_configure => 0,
with_build => 1,
with_test => 1,
with_runtime => 1,
with_develop => 0,
%option
}, $class;
}
Expand All @@ -45,6 +53,10 @@ sub parse_options {
local @ARGV = @_;
$self->{notest} = 1;
my (@mirror, @resolver);
my $with_option = sub {
my $n = shift;
("with-$n", \$self->{"with_$n"}, "without-$n", sub { $self->{"with_$n"} = 0 });
};
GetOptions
"L|local-lib-contained=s" => \($self->{local_lib}),
"V|version" => sub { $self->cmd_version; exit },
Expand All @@ -64,13 +76,12 @@ sub parse_options {
"dev" => \($self->{dev}),
"man-pages" => \($self->{man_pages}),
"home=s" => \($self->{home}),
"with-develop" => \($self->{with_develop}),
"with-recommends" => \($self->{with_recommends}),
"with-suggests" => \($self->{with_suggests}),
"retry!" => \($self->{retry}),
"configure-timeout=i" => \($self->{configure_timeout}),
"build-timeout=i" => \($self->{build_timeout}),
"test-timeout=i" => \($self->{test_timeout}),
(map $with_option->($_), qw(requires recommends suggests)),
(map $with_option->($_), qw(configure build test runtime develop)),
or exit 1;

$self->{local_lib} = $self->maybe_abs($self->{local_lib}) unless $self->{global};
Expand Down Expand Up @@ -380,12 +391,9 @@ sub load_cpanfile {
require Module::CPANfile;
my $cpanfile = Module::CPANfile->load($file);
my $prereqs = $cpanfile->prereqs_with;
my $phases = [qw(build test runtime)];
push @$phases, 'develop' if $self->{with_develop};
my $types = [qw(requires)];
push @$types, 'recommends' if $self->{with_recommends};
push @$types, 'suggests' if $self->{with_suggests};
my $requirements = $prereqs->merged_requirements($phases, $types);
my @phase = grep $self->{"with_$_"}, qw(configure build test runtime develop);
my @type = grep $self->{"with_$_"}, qw(requires recommends suggests);
my $requirements = $prereqs->merged_requirements(\@phase, \@type);
my $hash = $requirements->as_string_hash;

my (@package, @distribution);
Expand Down
18 changes: 12 additions & 6 deletions script/cpm
Expand Up @@ -41,6 +41,9 @@ cpm - a fast CPAN module installer
# use darkpan first, and if it fails, use metadb and normal CPAN
> cpm install --resolver 02packages,http://example.com/darkpan --resolver metadb Your::Module
# specify types/phases in cpanfile by "--with-*" and "--without-*" options
> cpm install --with-recommends --without-test
=head1 OPTIONS
-w, --workers=N
Expand All @@ -67,12 +70,6 @@ cpm - a fast CPAN module installer
run test cases, default: no
--man-pages
generate man pages
--with-develop (EXPERIMENTAL)
install dependencies of phase 'develop' in cpanfile too
--with-recommends (EXPERIMENTAL)
install dependencies of type 'recommends' in cpanfile too
--with-suggests (EXPERIMENTAL)
install dependencies of type 'suggests' in cpanfile too
--retry, --no-retry
retry configure/build/test/install if fails, default: retry
--configure-timeout=sec, --build-timeout=sec, --test-timeout=sec
Expand All @@ -81,6 +78,15 @@ cpm - a fast CPAN module installer
show version
-h, --help
show this help
--with-requires, --without-requires (default: with)
--with-recommends, --without-recommends (default: without)
--with-suggests, --without-suggests (default: without)
--with-configure, --without-configure (default: without)
--with-build, --without-build (default: with)
--with-test, --without-test (default: with)
--with-runtime, --without-runtime (default: with)
--with-develop, --without-develop (default: without)
specify types/phases of dependencies in cpanfile to be installed
=head1 COPYRIGHT AND LICENSE
Expand Down
31 changes: 25 additions & 6 deletions xt/27_optional_type.t
Expand Up @@ -16,6 +16,10 @@ on develop => sub {
recommends 'File::pushd';
suggests 'Try::Tiny';
};
on configure => sub {
requires 'Devel::CheckBin';
};
___

subtest 'normal' => sub {
Expand All @@ -32,6 +36,7 @@ subtest 'develop' => sub {
like $r->err, qr/DONE install Parallel-Pipes/;
unlike $r->err, qr/DONE install File-pushd/;
unlike $r->err, qr/DONE install Try-Tiny/;
unlike $r->err, qr/DONE install Devel-CheckBin/;
};

subtest 'recommends' => sub {
Expand All @@ -42,6 +47,7 @@ subtest 'recommends' => sub {
unlike $r->err, qr/DONE install Parallel-Pipes/;
unlike $r->err, qr/DONE install File-pushd/;
unlike $r->err, qr/DONE install Try-Tiny/;
unlike $r->err, qr/DONE install Devel-CheckBin/;
};

subtest 'suggests' => sub {
Expand All @@ -52,16 +58,29 @@ subtest 'suggests' => sub {
unlike $r->err, qr/DONE install Parallel-Pipes/;
unlike $r->err, qr/DONE install File-pushd/;
unlike $r->err, qr/DONE install Try-Tiny/;
unlike $r->err, qr/DONE install Devel-CheckBin/;
};

subtest 'all' => sub {
subtest 'mix1' => sub {
my $r = cpm_install '--with-configure', '--without-test', '--with-recommends', '--cpanfile', $cpanfile;
is $r->exit, 0;
unlike $r->err, qr/DONE install Process-Status/;
unlike $r->err, qr/DONE install App-ChangeShebang/;
unlike $r->err, qr/DONE install Parallel-Pipes/;
unlike $r->err, qr/DONE install File-pushd/;
unlike $r->err, qr/DONE install Try-Tiny/;
like $r->err, qr/DONE install Devel-CheckBin/;
};

subtest 'mix2' => sub {
my $r = cpm_install '--with-develop', '--with-recommends', '--with-suggests', '--cpanfile', $cpanfile;
is $r->exit, 0;
like $r->err, qr/DONE install Process-Status/;
like $r->err, qr/DONE install App-ChangeShebang/;
like $r->err, qr/DONE install Parallel-Pipes/;
like $r->err, qr/DONE install File-pushd/;
like $r->err, qr/DONE install Try-Tiny/;
like $r->err, qr/DONE install Process-Status/;
like $r->err, qr/DONE install App-ChangeShebang/;
like $r->err, qr/DONE install Parallel-Pipes/;
like $r->err, qr/DONE install File-pushd/;
like $r->err, qr/DONE install Try-Tiny/;
unlike $r->err, qr/DONE install Devel-CheckBin/;
};

done_testing;

0 comments on commit 9af2c7d

Please sign in to comment.