Skip to content

Commit de60e1f

Browse files
author
Joshua Hoblitt
committed
add flags param to perlbrew::perl
The flags param defaults to including the `--notest` flag which should dramatically shorten the time required to install a new perl version. + greatly improved test coverage of perlbrew::perl
1 parent c20ffd3 commit de60e1f

File tree

3 files changed

+127
-13
lines changed

3 files changed

+127
-13
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ the `.bashrc` file located under the `install` root. Eg.
156156
perlbrew::perl { 'perl-5.18.2':
157157
target => '/home/moe', # required
158158
version => 'perl-5.18.2',
159+
flags => "--notest -j ${::processorcount}",
159160
}
160161
```
161162

@@ -184,6 +185,14 @@ The version string of perl 5 release to be installed. Eg.
184185
perl5.004_05
185186
perl5.003_07
186187

188+
##### `flags`
189+
190+
`String` Defaults to `--notest -j ${::processorcount}`
191+
192+
The option flag(s) passed to `perlbrew install` command. Note that the
193+
`--notest` flag dramatically speeds up the ammount of time require to install a
194+
perl version.
195+
187196
#### `perlbrew::cpanm`
188197

189198
**Warning**: This defined type has parse order dependent behavior. The

manifests/perl.pp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
define perlbrew::perl (
44
$target,
55
$version = $name,
6+
$flags = "--notest -j ${::processorcount}",
67
) {
7-
validate_string($name)
88
validate_string($target)
9+
validate_string($version)
10+
validate_string($flags)
911

1012
Perlbrew[$target] -> Perlbrew::Perl[$name]
1113

@@ -33,8 +35,10 @@
3335
'/usr/bin',
3436
]
3537

38+
$command = regsubst("perlbrew install ${flags} ${version}", '\s+', ' ', 'G')
39+
3640
exec { "${target}_install_${version}":
37-
command => "perlbrew install ${version}",
41+
command => $command,
3842
path => $perlbrew_path,
3943
environment => $perlbrew_env,
4044
cwd => $install_root,
Lines changed: 112 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,129 @@
11
require 'spec_helper'
22

33
describe 'perlbrew::perl', :type => :define do
4-
let(:title) { 'perl-5.18.2' }
5-
let(:params) {{ :target => 'foo' }}
6-
let(:pre_condition) { "perlbrew { 'foo': install_root => '/dne' }" }
4+
let(:facts) {{ :processorcount => 42 }}
75

8-
context 'default params' do
9-
it { should contain_exec('foo_install_perl-5.18.2').with(
10-
:command => 'perlbrew install perl-5.18.2',
6+
let(:install_root) { '/dne' }
7+
let(:version) { 'perl-5.18.2' }
8+
let(:target) { 'foo' }
9+
let(:flags) { "--notest -j #{facts[:processorcount]}" }
10+
11+
let(:title) { version }
12+
let(:params) {{ :target => target }}
13+
let(:pre_condition) { "perlbrew { '#{target}': install_root => '#{install_root}' }" }
14+
15+
let(:perlbrew_env) { [
16+
"HOME=#{install_root}",
17+
'PERLBREW_VERSION=0.71',
18+
"PERLBREW_PERL=#{version}",
19+
'PERLBREW_BASHRC_VERSION=0.71',
20+
"PERLBREW_ROOT=#{install_root}/perl5/perlbrew",
21+
"PERLBREW_HOME=#{install_root}/.perlbrew",
22+
"PERLBREW_MANPATH=#{install_root}/perl5/perlbrew/perls/#{version}/man",
23+
"PERLBREW_PATH=#{install_root}/perl5/perlbrew/bin:#{install_root}/perl5/perlbrew/perls/#{version}/bin",
24+
]}
25+
let(:perlbrew_path) {[
26+
"#{install_root}/perl5/perlbrew/bin",
27+
"#{install_root}/perl5/perlbrew/perls/#{version}/bin",
28+
'/bin',
29+
'/usr/bin',
30+
]}
31+
32+
shared_examples 'guts' do
33+
it { should contain_perlbrew__perl(title).that_requires("Perlbrew[#{target}]") }
34+
35+
it { should contain_exec("#{target}_install_#{version}").with(
36+
:command => "perlbrew install #{flags} #{version}",
37+
:path => perlbrew_path,
38+
:environment => perlbrew_env,
39+
:cwd => '/dne',
40+
:user => nil,
41+
:group => nil,
42+
:logoutput => true,
43+
:creates => "/dne/perl5/perlbrew/perls/#{version}",
44+
:timeout => 3600
45+
)
46+
}
47+
48+
it { should contain_exec("#{target}_install-cpanm-#{version}").with(
49+
:command => 'perlbrew install-cpanm',
50+
:path => perlbrew_path,
51+
:environment => perlbrew_env,
1152
:cwd => '/dne',
1253
:user => nil,
1354
:group => nil,
1455
:logoutput => true,
15-
:creates => '/dne/perl5/perlbrew/perls/perl-5.18.2'
56+
:unless => 'which cpanm'
1657
)
1758
}
18-
it { should contain_exec('foo_switch_perl-5.18.2').with(
19-
:command => 'perlbrew switch perl-5.18.2',
59+
it { should contain_exec("#{target}_install-cpanm-#{version}").that_requires("Exec[#{target}_install_#{version}]") }
60+
61+
it { should contain_exec("#{target}_switch_#{version}").with(
62+
:command => "perlbrew switch #{version}",
63+
:path => perlbrew_path,
64+
:environment => perlbrew_env,
2065
:cwd => '/dne',
2166
:user => nil,
2267
:group => nil,
2368
:logoutput => true,
24-
:unless => "grep PERLBREW_PERL=\\\"perl-5.18.2\\\" /dne/.perlbrew/init"
69+
:unless => "grep PERLBREW_PERL=\\\"#{version}\\\" /dne/.perlbrew/init"
2570
)
2671
}
27-
end
72+
it { should contain_exec("#{target}_switch_#{version}").that_requires("Exec[#{target}_install-cpanm-#{version}]") }
73+
end # guts
74+
75+
context 'default params' do
76+
it_behaves_like 'guts'
77+
end # default params
78+
79+
context 'target =>' do
80+
context 'bar' do
81+
let(:target) { 'foo' }
82+
before { params[:target] = target }
83+
84+
it_behaves_like 'guts'
85+
end
86+
87+
context '[]' do
88+
let(:params) {{ :target => [] }}
89+
90+
it 'should fail' do
91+
expect { should }.to raise_error(Puppet::Error, /is not a string/)
92+
end
93+
end
94+
end # target =>
95+
96+
context 'version =>' do
97+
context '2.18.5-lrep' do
98+
let(:version) { '2.18.5-lrep' }
99+
before { params[:version] = version }
100+
101+
it_behaves_like 'guts'
102+
end
103+
104+
context '[]' do
105+
before { params[:version] = [] }
106+
107+
it 'should fail' do
108+
expect { should }.to raise_error(Puppet::Error, /is not a string/)
109+
end
110+
end
111+
end # version =>
112+
113+
context 'flags =>' do
114+
context '--ponies' do
115+
let(:flags) { '--ponies' }
116+
before { params[:flags] = flags }
117+
118+
it_behaves_like 'guts'
119+
end
120+
121+
context '[]' do
122+
before { params[:flags] = [] }
123+
124+
it 'should fail' do
125+
expect { should }.to raise_error(Puppet::Error, /is not a string/)
126+
end
127+
end
128+
end # flags =>
28129
end

0 commit comments

Comments
 (0)