Merge pull request #533 from HelenCampbell/MODULES-2614-Improved

Modules 2614 improved numeric value handling on empty function
This commit is contained in:
David Schmitt 2015-09-28 17:11:10 +01:00
commit 76db98120a
4 changed files with 24 additions and 6 deletions

View file

@ -224,7 +224,7 @@ Converts the case of a string or of all strings in an array to lowercase. *Type*
#### `empty`
Returns true if the argument is an array or hash that contains no elements, or an empty string. *Type*: rvalue.
Returns true if the argument is an array or hash that contains no elements, or an empty string. Returns false when the argument is a numerical value. *Type*: rvalue.
#### `ensure_packages`

View file

@ -13,14 +13,18 @@ Returns true if the variable is empty.
value = arguments[0]
unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String)
unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) || value.is_a?(Numeric)
raise(Puppet::ParseError, 'empty(): Requires either ' +
'array, hash or string to work with')
'array, hash, string or integer to work with')
end
result = value.empty?
if value.is_a?(Numeric)
return false
else
result = value.empty?
return result
return result
end
end
end

View file

@ -27,6 +27,20 @@ describe 'empty function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('opera
}
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end
end
it 'handles numerical values' do
pp = <<-EOS
$a = 7
$b = false
$o = empty($a)
if $o == $b {
notify { 'output correct': }
}
EOS
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/Notice: output correct/)
end

View file

@ -3,11 +3,11 @@ require 'spec_helper'
describe 'empty' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError) }
it { is_expected.to run.with_params(0).and_raise_error(Puppet::ParseError) }
it {
pending("Current implementation ignores parameters after the first.")
is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError)
}
it { is_expected.to run.with_params(0).and_return(false) }
it { is_expected.to run.with_params('').and_return(true) }
it { is_expected.to run.with_params('one').and_return(false) }