-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathcommand-clone-modules.t
98 lines (83 loc) · 2.79 KB
/
command-clone-modules.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env perl
use Test2::V0;
use Test2::Tools::Spec;
BEGIN { $ENV{SHELL} = "/bin/bash" }
use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require "test2_helpers.pl";
mock_perlbrew_install("perl-5.14.1");
mock_perlbrew_install("perl-5.16.0");
no warnings;
my ($__from, $__to, $__notest);
sub App::perlbrew::list_modules {
my ($self, $env) = @_;
$__from = $env || $self->current_env;
return ["Foo", "Bar"];
}
sub App::perlbrew::run_command_exec {
my ($self, @args) = @_;
if (grep { $_ eq 'cpanm' } @args) {
$__to = $args[1];
($__notest) = grep { $_ eq '--notest' } @{$self->{original_argv}};
}
return $self;
}
use warnings;
describe "clone-modules command," => sub {
before_each 'cleanup env' => sub {
delete $ENV{PERL_MB_OPT};
delete $ENV{PERL_MM_OPT};
delete $ENV{PERL_LOCAL_LIB_ROOT};
delete $ENV{PERLBREW_LIB};
delete $ENV{PERL5LIB};
$__from = undef;
$__to = undef;
$__notest = undef;
};
describe "when invoked with two arguments, A and B", sub {
it "should display clone modules from A to B", sub {
my $app = App::perlbrew->new(
"clone-modules", "perl-5.14.1", "perl-5.16.0"
);
$app->run;
is $__from, "perl-5.14.1";
is $__to, "perl-5.16.0";
ok(!defined($__notest));
};
};
describe "when invoked with two arguments, A and B, with `--notest`", sub {
it "should display clone modules from A to B", sub {
my $app = App::perlbrew->new(
"clone-modules", "--notest", "perl-5.14.1", "perl-5.16.0"
);
$app->run;
is $__from, "perl-5.14.1";
is $__to, "perl-5.16.0";
ok(defined($__notest));
};
};
describe "when invoked with one argument X", sub {
it "should display clone modules from current-perl to X", sub {
my $app = App::perlbrew->new("clone-modules", "perl-5.14.1");
my $mock = mocked($app)->expects("current_env")->returns("perl-5.16.0")->at_least(1);
$app->run;
is $__from, "perl-5.16.0";
is $__to, "perl-5.14.1";
ok(!defined($__notest));
$mock->verify;
};
};
describe "when invoked with one argument X, with `--notest`", sub {
it "should display clone modules from current-perl to X", sub {
my $app = App::perlbrew->new("clone-modules", "--notest", "perl-5.14.1");
my $mock = mocked($app)->expects("current_env")->returns("perl-5.16.0")->at_least(1);
$app->run;
is $__from, "perl-5.16.0";
is $__to, "perl-5.14.1";
ok(defined($__notest));
$mock->verify;
};
};
};
done_testing;