Skip to content

Commit 0804121

Browse files
committed
Fix the stdlib functions that fail tests
1 parent e2297a1 commit 0804121

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

lib/puppet/parser/functions/floor.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ module Puppet::Parser::Functions
88
raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
99
"given (#{arguments.size} for 1)") if arguments.size != 1
1010

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

1318
raise(Puppet::ParseError, "floor(): Wrong argument type " +
1419
"given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false

lib/puppet/parser/functions/is_domain_name.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ module Puppet::Parser::Functions
2020
label_min_length=1
2121
label_max_length=63
2222

23+
# Only allow string types
24+
return false unless domain.is_a?(String)
25+
2326
# Allow ".", it is the top level domain
2427
return true if domain == '.'
2528

lib/puppet/parser/functions/is_float.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ module Puppet::Parser::Functions
1515

1616
value = arguments[0]
1717

18+
# Only allow Numeric or String types
19+
return false unless value.is_a?(Numeric) or value.is_a?(String)
20+
1821
if value != value.to_f.to_s and !value.is_a? Float then
1922
return false
2023
else

lib/puppet/parser/functions/is_function_available.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ module Puppet::Parser::Functions
1515
"given #{arguments.size} for 1")
1616
end
1717

18+
# Only allow String types
19+
return false unless arguments[0].is_a?(String)
20+
1821
function = Puppet::Parser::Functions.function(arguments[0].to_sym)
1922
function.is_a?(String) and not function.empty?
2023
end

spec/acceptance/getparam_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
notice(inline_template('getparam is <%= @o.inspect %>'))
1414
EOS
1515

16-
apply_manifest(pp, :expect_changes => true) do |r|
16+
apply_manifest(pp, :catch_failures => true) do |r|
1717
expect(r.stdout).to match(/getparam is true/)
1818
end
1919
end

spec/acceptance/is_float_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
pp = <<-EOS
88
$a = ['aaa.com','bbb','ccc']
99
$o = is_float($a)
10-
notice(inline_template('is_floats is <%= @o.inspect %>'))
10+
notice(inline_template('is_float is <%= @o.inspect %>'))
1111
EOS
1212

1313
apply_manifest(pp, :catch_failures => true) do |r|
@@ -18,7 +18,7 @@
1818
pp = <<-EOS
1919
$a = true
2020
$o = is_float($a)
21-
notice(inline_template('is_floats is <%= @o.inspect %>'))
21+
notice(inline_template('is_float is <%= @o.inspect %>'))
2222
EOS
2323

2424
apply_manifest(pp, :catch_failures => true) do |r|
@@ -75,7 +75,7 @@
7575
EOS
7676

7777
apply_manifest(pp, :catch_failures => true) do |r|
78-
expect(r.stdout).to match(/is_floats is false/)
78+
expect(r.stdout).to match(/is_float is false/)
7979
end
8080
end
8181
end

spec/acceptance/is_string_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
EOS
5151

5252
apply_manifest(pp, :catch_failures => true) do |r|
53-
expect(r.stdout).to match(/is_string is true/)
53+
expect(r.stdout).to match(/is_string is false/)
5454
end
5555
end
5656
it 'is_strings floats' do

0 commit comments

Comments
 (0)