diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-23 05:05:58 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-12-23 05:05:58 +0000 |
| commit | 311aba94792c2984d2944c9ac99a4ff5d79db697 (patch) | |
| tree | b497a94947be18a63bf35796654cc468fcc36bb5 | |
| parent | 9bb5c50d0b30b4dfb82b6b705dfcbf0e126a9d61 (diff) | |
| download | puppet-311aba94792c2984d2944c9ac99a4ff5d79db697.tar.gz puppet-311aba94792c2984d2944c9ac99a4ff5d79db697.tar.xz puppet-311aba94792c2984d2944c9ac99a4ff5d79db697.zip | |
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
| -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$ |
