Skip to content

Commit

Permalink
add flags param to perlbrew::perl
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Joshua Hoblitt committed Oct 17, 2014
1 parent c20ffd3 commit de60e1f
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 13 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ the `.bashrc` file located under the `install` root. Eg.
perlbrew::perl { 'perl-5.18.2':
target => '/home/moe', # required
version => 'perl-5.18.2',
flags => "--notest -j ${::processorcount}",
}
```

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

##### `flags`

`String` Defaults to `--notest -j ${::processorcount}`

The option flag(s) passed to `perlbrew install` command. Note that the
`--notest` flag dramatically speeds up the ammount of time require to install a
perl version.

#### `perlbrew::cpanm`

**Warning**: This defined type has parse order dependent behavior. The
Expand Down
8 changes: 6 additions & 2 deletions manifests/perl.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
define perlbrew::perl (
$target,
$version = $name,
$flags = "--notest -j ${::processorcount}",
) {
validate_string($name)
validate_string($target)
validate_string($version)
validate_string($flags)

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

Expand Down Expand Up @@ -33,8 +35,10 @@
'/usr/bin',
]

$command = regsubst("perlbrew install ${flags} ${version}", '\s+', ' ', 'G')

exec { "${target}_install_${version}":
command => "perlbrew install ${version}",
command => $command,
path => $perlbrew_path,
environment => $perlbrew_env,
cwd => $install_root,
Expand Down
123 changes: 112 additions & 11 deletions spec/unit/defines/perlbrew_perl_spec.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,129 @@
require 'spec_helper'

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

context 'default params' do
it { should contain_exec('foo_install_perl-5.18.2').with(
:command => 'perlbrew install perl-5.18.2',
let(:install_root) { '/dne' }
let(:version) { 'perl-5.18.2' }
let(:target) { 'foo' }
let(:flags) { "--notest -j #{facts[:processorcount]}" }

let(:title) { version }
let(:params) {{ :target => target }}
let(:pre_condition) { "perlbrew { '#{target}': install_root => '#{install_root}' }" }

let(:perlbrew_env) { [
"HOME=#{install_root}",
'PERLBREW_VERSION=0.71',
"PERLBREW_PERL=#{version}",
'PERLBREW_BASHRC_VERSION=0.71',
"PERLBREW_ROOT=#{install_root}/perl5/perlbrew",
"PERLBREW_HOME=#{install_root}/.perlbrew",
"PERLBREW_MANPATH=#{install_root}/perl5/perlbrew/perls/#{version}/man",
"PERLBREW_PATH=#{install_root}/perl5/perlbrew/bin:#{install_root}/perl5/perlbrew/perls/#{version}/bin",
]}
let(:perlbrew_path) {[
"#{install_root}/perl5/perlbrew/bin",
"#{install_root}/perl5/perlbrew/perls/#{version}/bin",
'/bin',
'/usr/bin',
]}

shared_examples 'guts' do
it { should contain_perlbrew__perl(title).that_requires("Perlbrew[#{target}]") }

it { should contain_exec("#{target}_install_#{version}").with(
:command => "perlbrew install #{flags} #{version}",
:path => perlbrew_path,
:environment => perlbrew_env,
:cwd => '/dne',
:user => nil,
:group => nil,
:logoutput => true,
:creates => "/dne/perl5/perlbrew/perls/#{version}",
:timeout => 3600
)
}

it { should contain_exec("#{target}_install-cpanm-#{version}").with(
:command => 'perlbrew install-cpanm',
:path => perlbrew_path,
:environment => perlbrew_env,
:cwd => '/dne',
:user => nil,
:group => nil,
:logoutput => true,
:creates => '/dne/perl5/perlbrew/perls/perl-5.18.2'
:unless => 'which cpanm'
)
}
it { should contain_exec('foo_switch_perl-5.18.2').with(
:command => 'perlbrew switch perl-5.18.2',
it { should contain_exec("#{target}_install-cpanm-#{version}").that_requires("Exec[#{target}_install_#{version}]") }

it { should contain_exec("#{target}_switch_#{version}").with(
:command => "perlbrew switch #{version}",
:path => perlbrew_path,
:environment => perlbrew_env,
:cwd => '/dne',
:user => nil,
:group => nil,
:logoutput => true,
:unless => "grep PERLBREW_PERL=\\\"perl-5.18.2\\\" /dne/.perlbrew/init"
:unless => "grep PERLBREW_PERL=\\\"#{version}\\\" /dne/.perlbrew/init"
)
}
end
it { should contain_exec("#{target}_switch_#{version}").that_requires("Exec[#{target}_install-cpanm-#{version}]") }
end # guts

context 'default params' do
it_behaves_like 'guts'
end # default params

context 'target =>' do
context 'bar' do
let(:target) { 'foo' }
before { params[:target] = target }

it_behaves_like 'guts'
end

context '[]' do
let(:params) {{ :target => [] }}

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # target =>

context 'version =>' do
context '2.18.5-lrep' do
let(:version) { '2.18.5-lrep' }
before { params[:version] = version }

it_behaves_like 'guts'
end

context '[]' do
before { params[:version] = [] }

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # version =>

context 'flags =>' do
context '--ponies' do
let(:flags) { '--ponies' }
before { params[:flags] = flags }

it_behaves_like 'guts'
end

context '[]' do
before { params[:flags] = [] }

it 'should fail' do
expect { should }.to raise_error(Puppet::Error, /is not a string/)
end
end
end # flags =>
end

0 comments on commit de60e1f

Please sign in to comment.