-
Notifications
You must be signed in to change notification settings - Fork 220
/
Copy pathcommand-install-from-archive.t
121 lines (96 loc) · 3.09 KB
/
command-install-from-archive.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
#!/usr/bin/env perl
use Test2::V0;
use Test2::Tools::Spec;
use FindBin;
use lib $FindBin::Bin;
use App::perlbrew;
require 'test2_helpers.pl';
sub arrange_file;
sub expect_dispatch_via;
sub should_install_from_archive;
describe "command install <archive>" => sub {
should_install_from_archive "with perl source archive" => (
filename => 'perl-5.28.0.tar.gz',
dist_version => '5.28.0',
installation_name => 'perl-5.28.0',
);
should_install_from_archive "with perfixed perl source archive" => (
filename => 'downloaded-perl-5.28.0.tar.gz',
dist_version => '5.28.0',
installation_name => 'perl-5.28.0',
);
should_install_from_archive "with cperl source archive" => (
filename => 'cperl-5.28.0.tar.gz',
dist_version => '5.28.0',
installation_name => 'cperl-5.28.0',
);
should_install_from_archive "with prefixed cperl source archive" => (
filename => 'downloaded-cperl-5.28.0.tar.gz',
dist_version => '5.28.0',
installation_name => 'cperl-5.28.0',
);
};
done_testing;
sub should_install_from_archive {
my ($title, %params) = @_;
describe $title => sub {
my %shared;
before_each 'arrange file', sub {
my $file = $shared{file} = arrange_file
name => $params{filename},
tempdir => 1,
;
$shared{app} = App::perlbrew->new(install => "$file");
};
expect_dispatch_via
shared => \%shared,
method => 'do_install_archive',
with_args => [ object { call 'basename' => $params{filename} } ];
expect_dispatch_via
shared => \%shared,
method => 'do_extract_tarball',
with_args => [ object { call 'basename' => $params{filename} } ],
stubs => { do_install_this => '' };
expect_dispatch_via
shared => \%shared,
method => 'do_install_this',
with_args => [
object { call basename => 'foo' },
$params{dist_version},
$params{installation_name},
],
stubs => { do_extract_tarball => sub { $_[-1]->dirname->child('foo') } };
};
};
sub arrange_file {
my (%params) = @_;
my $dir;
$dir ||= $params{dir} if $params{dir};
$dir ||= tempdir (CLEANUP => 1) if $params{tempdir};
$dir ||= '.';
my $file = file ($dir, $params{name});
open my $fh, '>', $file;
close $fh;
return $file;
}
sub expect_dispatch_via {
my (%params) = @_;
tests "should dispatch via $params{method}()" => sub {
my $app = $params{shared}{app};
my $mock = mocked($app);
if ($params{stubs}) {
$mock->stubs($params{stubs});
}
if ($params{with_args}) {
$mock->expects($params{method})
->with(@{ $params{with_args} })
->returns(undef);
} else {
$mock->expects($params{method})
->returns(undef);
}
$app->run;
$mock->verify;
$mock->reset;
};
}