From 311aba94792c2984d2944c9ac99a4ff5d79db697 Mon Sep 17 00:00:00 2001 From: luke Date: Sat, 23 Dec 2006 05:05:58 +0000 Subject: Fixing #66. The "defined" function previously checked for definitions and types, but since types and classes can't have the same name anyway, the function now works for classes. git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1965 980ebf18-57e1-0310-9a29-db15c13687c0 --- lib/puppet/parser/functions.rb | 2 +- test/language/functions.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) 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$ -- cgit