Skip to content

Commit

Permalink
Merge pull request #251 from hunner/fix_tests
Browse files Browse the repository at this point in the history
Fix the stdlib functions that fail tests
  • Loading branch information
Ashley Penney committed May 8, 2014
2 parents e2297a1 + 0804121 commit 14d656d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 6 deletions.
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

0 comments on commit 14d656d

Please sign in to comment.