Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the stdlib functions that fail tests #251

Merged
merged 1 commit into from
May 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/puppet/parser/functions/floor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size != 1

arg = arguments[0]
begin
arg = Float(arguments[0])
rescue TypeError, ArgumentError => e
raise(Puppet::ParseError, "floor(): Wrong argument type " +
"given (#{arguments[0]} for Numeric)")
end

raise(Puppet::ParseError, "floor(): Wrong argument type " +
"given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false
Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/parser/functions/is_domain_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ module Puppet::Parser::Functions
label_min_length=1
label_max_length=63

# Only allow string types
return false unless domain.is_a?(String)

# Allow ".", it is the top level domain
return true if domain == '.'

Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/parser/functions/is_float.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module Puppet::Parser::Functions

value = arguments[0]

# Only allow Numeric or String types
return false unless value.is_a?(Numeric) or value.is_a?(String)

if value != value.to_f.to_s and !value.is_a? Float then
return false
else
Expand Down
3 changes: 3 additions & 0 deletions lib/puppet/parser/functions/is_function_available.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ module Puppet::Parser::Functions
"given #{arguments.size} for 1")
end

# Only allow String types
return false unless arguments[0].is_a?(String)

function = Puppet::Parser::Functions.function(arguments[0].to_sym)
function.is_a?(String) and not function.empty?
end
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/getparam_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
notice(inline_template('getparam is <%= @o.inspect %>'))
EOS

apply_manifest(pp, :expect_changes => true) do |r|
apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/getparam is true/)
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/acceptance/is_float_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
pp = <<-EOS
$a = ['aaa.com','bbb','ccc']
$o = is_float($a)
notice(inline_template('is_floats is <%= @o.inspect %>'))
notice(inline_template('is_float is <%= @o.inspect %>'))
EOS

apply_manifest(pp, :catch_failures => true) do |r|
Expand All @@ -18,7 +18,7 @@
pp = <<-EOS
$a = true
$o = is_float($a)
notice(inline_template('is_floats is <%= @o.inspect %>'))
notice(inline_template('is_float is <%= @o.inspect %>'))
EOS

apply_manifest(pp, :catch_failures => true) do |r|
Expand Down Expand Up @@ -75,7 +75,7 @@
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/is_floats is false/)
expect(r.stdout).to match(/is_float is false/)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/acceptance/is_string_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
EOS

apply_manifest(pp, :catch_failures => true) do |r|
expect(r.stdout).to match(/is_string is true/)
expect(r.stdout).to match(/is_string is false/)
end
end
it 'is_strings floats' do
Expand Down