diff options
| -rw-r--r-- | lib/puppet/parser/functions.rb | 14 | ||||
| -rwxr-xr-x | test/language/scope.rb | 37 |
2 files changed, 51 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions.rb b/lib/puppet/parser/functions.rb index bc7e870ae..61070627f 100644 --- a/lib/puppet/parser/functions.rb +++ b/lib/puppet/parser/functions.rb @@ -97,6 +97,20 @@ module Functions return true end end + + # Test whether a given class or definition is defined + newfunction(:defined, :rvalue) do |vals| + retval = true + + vals.each do |val| + unless builtintype?(val) or lookuptype(val) + retval = false + break + end + end + + return retval + end end end diff --git a/test/language/scope.rb b/test/language/scope.rb index 8e0068c79..da23c4256 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -622,4 +622,41 @@ class TestScope < Test::Unit::TestCase assert(scope.function_tagged("two"), "tagged function incorrectly returned false") end + + def test_definedfunction + scope = Puppet::Parser::Scope.new() + + one = tempfile() + two = tempfile() + + children = [] + + children << classobj("one", :code => AST::ASTArray.new( + :children => [ + fileobj(one, "owner" => "root") + ] + )) + + children << classobj("two", :code => AST::ASTArray.new( + :children => [ + fileobj(two, "owner" => "root") + ] + )) + + top = AST::ASTArray.new(:children => children) + + top.evaluate(:scope => scope) + + assert_nothing_raised { + %w{one two file user}.each do |type| + assert(scope.function_defined([type]), + "Class #{type} was not considered defined") + end + + assert(!scope.function_defined(["nopeness"]), + "Class 'nopeness' was incorrectly considered defined") + } + + + end end |
