diff options
| -rw-r--r-- | lib/puppet/parser/functions.rb | 2 | ||||
| -rwxr-xr-x | test/language/functions.rb | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index ad5f53080..854f3ac9f 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -153,7 +153,7 @@ module Functions newfunction(:defined, :type => :rvalue, :doc => "Determine whether a given type is defined, either as a native type or a defined type.") do |vals| # For some reason, it doesn't want me to return from here. - if vals.detect do |val| Puppet::Type.type(val) or finddefine(val) end + if vals.detect do |val| Puppet::Type.type(val) or finddefine(val) or findclass(val) end true else false diff --git a/test/language/functions.rb b/test/language/functions.rb index b69c2bfa2..322f3033d 100755 --- a/test/language/functions.rb +++ b/test/language/functions.rb @@ -353,6 +353,29 @@ class TestLangFunctions < Test::Unit::TestCase @scope.collections.each do |coll| coll.evaluate end end end + + def test_defined + interp = mkinterp + scope = mkscope(:interp => interp) + + interp.newclass("yayness") + interp.newdefine("rahness") + + assert_nothing_raised do + assert(scope.function_defined("yayness"), "yayness class was not considered defined") + assert(scope.function_defined("rahness"), "rahness definition was not considered defined") + assert(scope.function_defined("service"), "service type was not considered defined") + assert(! scope.function_defined("fakness"), "fakeness was considered defined") + end + + # Now make sure any match in a list will work + assert(scope.function_defined(["booness", "yayness", "fakeness"]), + "A single answer was not sufficient to return true") + + # and make sure multiple falses are still false + assert(! scope.function_defined(%w{no otherno stillno}), + "Multiple falses were somehow true") + end end # $Id$ |
