]> gitweb.fluxo.info Git - puppet-stdlib.git/commitdiff
Fix the stdlib functions that fail tests
authorHunter Haugen <hunter@puppetlabs.com>
Thu, 8 May 2014 21:43:06 +0000 (14:43 -0700)
committerHunter Haugen <hunter@puppetlabs.com>
Thu, 8 May 2014 21:55:23 +0000 (14:55 -0700)
lib/puppet/parser/functions/floor.rb
lib/puppet/parser/functions/is_domain_name.rb
lib/puppet/parser/functions/is_float.rb
lib/puppet/parser/functions/is_function_available.rb
spec/acceptance/getparam_spec.rb
spec/acceptance/is_float_spec.rb
spec/acceptance/is_string_spec.rb

index a4019234998802a6e57214df734d792ff1f90266..9a6f014d7c1f25ed98983581971e50f67514b8cc 100644 (file)
@@ -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
index 5826dc0d9a37e53ad63954923863f8ee7986744d..b3fee965a0bee88a8497e32d7a6166ba63fb1c24 100644 (file)
@@ -20,6 +20,9 @@ Returns true if the string passed to this function is a syntactically correct do
     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 == '.'
 
index 911f3c2dcdcc6e94f1e864c08c3720e88a02087c..a2da94385be23590e69414dc5c8a19253c839951 100644 (file)
@@ -15,6 +15,9 @@ Returns true if the variable passed to this function is a float.
 
     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
index 6cbd35c3db270ed0ee96e5e722e6a9a700a76173..6da82c8c1706eebdcaf878f3f25785477418e2a6 100644 (file)
@@ -15,6 +15,9 @@ true if the function exists, false if not.
         "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
index a84b2d12e9aa00dd16051fba683b78a433a95c1a..91fc9a00f3474f2a9a35c065d7bdd66357d94a8b 100755 (executable)
@@ -13,7 +13,7 @@ describe 'getparam function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
       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
index 79b01f065edb1df40eb2426fb0dd9cb9d4b91baa..338ba58d46803a6f965487aac13414453e2dc073 100755 (executable)
@@ -7,7 +7,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
       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|
@@ -18,7 +18,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
       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|
@@ -75,7 +75,7 @@ describe 'is_float function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('op
       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
index bda6cd7f6ceec329fb3da67f7441d36c2eb6f4cb..94d8e96783019e76264a78297abff03ddbb742fa 100755 (executable)
@@ -50,7 +50,7 @@ describe 'is_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o
       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