-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathcommand-lib.t
168 lines (144 loc) · 5.94 KB
/
command-lib.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env perl
use Test2::V0;
use Test2::Tools::Spec;
use Test2::Plugin::IOEvents;
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.14.2");
mock_perlbrew_install("perl-5.14.3");
describe "lib command," => sub {
describe "when invoked with unknown action name,", sub {
it "should display error" => sub {
my $x = "correcthorsebatterystaple";
my $app = App::perlbrew->new("lib", $x);
my $events = intercept { $app->run() };
like(
$events,
[
{info => [{tag => 'STDOUT', details => qr/Unknown command: $x/}]}
],
'Unknown command'
);
}
};
describe "without lib name" => sub {
it "create errs gracefully showing usage" => sub {
my $app = App::perlbrew->new;
like dies {
$app->{args} = [ "lib", "create"];
$app->run;
}, qr/ERROR: /i, 'lib create';
};
it "delete errs gracefully showing usage" => sub {
my $app = App::perlbrew->new;
like dies {
$app->{args} = [ "lib", "delete"];
$app->run;
}, qr/ERROR: /i, 'lib delete';
};
};
describe "`create` sub-command," => sub {
my ($app, $libdir);
my $mock = mock "App::perlbrew";
$mock->override("current_perl", sub { "perl-5.14.2" });
before_each setup_path => sub {
$app = $mock->class->new;
$libdir = App::Perlbrew::Path->new($App::perlbrew::PERLBREW_HOME, "libs", 'perl-5.14.2@nobita');
};
after_each remove_path => sub {
$libdir->rmpath;
};
describe "with a bare lib name," => sub {
it "creates the lib folder for current perl" => sub {
my $events = intercept {
$app->{args} = [ "lib", "create", "nobita" ];
$app->run;
};
like $events, [
{info => [{tag => 'STDOUT', details => qr{lib 'perl-5.14.2\@nobita' is created.}}]}
], 'stdout matches';
ok -d $libdir, "libdir exists";
};
};
describe "with \@ in the beginning of lib name," => sub {
it "creates the lib folder for current perl" => sub {
ok ! -d $libdir, "libdir do not exist";
my $events = intercept {
$app->{args} = [ "lib", "create", '@nobita' ];
$app->run;
};
like $events, [
{info => [{tag => 'STDOUT', details => qr{lib 'perl-5.14.2\@nobita' is created.}}]}
], 'stdout matches';
ok -d $libdir;
}
};
describe "with perl name and \@ as part of lib name," => sub {
it "creates the lib folder for the specified perl" => sub {
my $events = intercept {
$app->{args} = [ "lib", "create", 'perl-5.14.2@nobita' ];
$app->run;
};
like $events, [
{info => [{tag => 'STDOUT', details => qr{lib 'perl-5.14.2\@nobita' is created.}}]}
], 'stdout matches';
ok -d $libdir;
};
it "creates the lib folder for the specified perl" => sub {
my $events = intercept {
$app->{args} = [ "lib", "create", 'perl-5.14.1@nobita' ];
$app->run;
};
like $events, [
{info => [{tag => 'STDOUT', details => qr{lib 'perl-5.14.1\@nobita' is created.}}]}
], 'stdout matches';
$libdir = App::Perlbrew::Path->new($App::perlbrew::PERLBREW_HOME, "libs", 'perl-5.14.1@nobita');
ok -d $libdir;
};
it "shows errors if the specified perl does not exist." => sub {
like dies {
## perl-5.8.8 is not mock-installed
$app->{args} = [ "lib", "create", 'perl-5.8.8@nobita' ];
$app->run;
}, qr{^ERROR: 'perl-5.8.8' is not installed yet, 'perl-5.8.8\@nobita' cannot be created.\n},
'dies with error message';
$libdir = App::Perlbrew::Path->new($App::perlbrew::PERLBREW_HOME, "libs", 'perl-5.8.8@nobita');
ok !-d $libdir;
};
};
};
describe "`delete` sub-command," => sub {
my $nobita = App::Perlbrew::Path->new($App::perlbrew::PERLBREW_HOME, "libs", 'perl-5.14.2@nobita');
before_each mkpath => sub {
$nobita->mkpath;
};
after_each rmpath => sub {
$nobita->rmpath;
};
it "deletes the local::lib folder" => sub {
like intercept {
my $mock = mock "App::perlbrew";
$mock->override("current_perl", sub { "perl-5.14.2" });
my $app = $mock->class->new("lib", "delete", "nobita");
$app->run;
}, [
{info => [{tag => 'STDOUT', details => qr{lib 'perl-5.14.2\@nobita' is deleted.}}]}
], 'stdout matches';
ok !-d App::Perlbrew::Path->new($App::perlbrew::PERLBREW_HOME, "libs", 'perl-5.14.2@nobita');
ok !-e App::Perlbrew::Path->new($App::perlbrew::PERLBREW_HOME, "libs", 'perl-5.14.2@nobita');
};
it "shows errors when the given lib does not exists " => sub {
like dies {
my $mock = mock "App::perlbrew";
$mock->override("current_perl", sub { "perl-5.14.2" });
my $app = $mock->class->new("lib", "delete", "yoga");
$app->run;
}, qr{^ERROR: 'perl-5\.14\.2\@yoga' does not exist\.},
'dies with error message';
};
};
};
done_testing;