diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-26 16:02:41 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-04-26 16:02:41 +0000 |
| commit | baa412c6ed30d19ee43bf37b3bba60bf372fac5a (patch) | |
| tree | 2f851138572ec687b7e7b116fe415aed4163b542 | |
| parent | 46ce36b175962ce89e06af4863d2c9dc50f2a02f (diff) | |
| download | puppet-baa412c6ed30d19ee43bf37b3bba60bf372fac5a.tar.gz puppet-baa412c6ed30d19ee43bf37b3bba60bf372fac5a.tar.xz puppet-baa412c6ed30d19ee43bf37b3bba60bf372fac5a.zip | |
Adding "defined" functino to puppet, so you can now test whether a given class or definition is defined.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1135 980ebf18-57e1-0310-9a29-db15c13687c0
| -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 |
