diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-15 20:59:42 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-15 20:59:42 +0000 |
commit | 9d6166e964d188fb0c9232413d9da41f15fd1bf4 (patch) | |
tree | 4c6ee1ea9b1255b63da42e90e9bf253e8831639e | |
parent | a0bcf5a355569633de420e109bce493cc8808a26 (diff) | |
download | puppet-9d6166e964d188fb0c9232413d9da41f15fd1bf4.tar.gz |
adding a test to make sure that defaults get taken up by components
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1199 980ebf18-57e1-0310-9a29-db15c13687c0
-rwxr-xr-x | test/language/scope.rb | 32 | ||||
-rw-r--r-- | test/puppettest.rb | 25 |
2 files changed, 56 insertions, 1 deletions
diff --git a/test/language/scope.rb b/test/language/scope.rb index be95808db..79ec65552 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -665,6 +665,38 @@ class TestScope < Test::Unit::TestCase end + # Make sure components acquire defaults. + def test_defaultswithcomponents + children = [] + + # Create a component + filename = tempfile() + args = AST::ASTArray.new( + :file => tempfile(), + :line => rand(100), + :children => [nameobj("argument")] + ) + children << compobj("comp", :args => args, :code => AST::ASTArray.new( + :children => [ + fileobj(filename, "owner" => varref("argument") ) + ] + )) + + # Create a default + children << defaultobj("comp", "argument" => "yayness") + + # lastly, create an object that calls our third component + children << objectdef("comp", "boo", {"argument" => "parentfoo"}) + + trans = assert_evaluate(children) + + flat = trans.flatten + + assert(!flat.empty?, "Got no objects back") + + assert_equal("parentfoo", flat[0]["owner"], "default did not take") + end + if defined? ActiveRecord # Verify that we recursively mark as collectable the results of collectable # components. diff --git a/test/puppettest.rb b/test/puppettest.rb index c509055d1..ce1a2918a 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -867,12 +867,16 @@ module ParserTesting end def objectparam(param, value) + # Allow them to pass non-strings in + if value.is_a?(String) + value = stringobj(value) + end assert_nothing_raised("Could not create param %s" % param) { return AST::ObjectParam.new( :file => tempfile(), :line => rand(100), :param => nameobj(param), - :value => stringobj(value) + :value => value ) } end @@ -1042,6 +1046,25 @@ module ParserTesting return top end + + # Take a list of AST objects, evaluate them, and return the results + def assert_evaluate(children) + top = nil + assert_nothing_raised("Could not create top object") { + top = AST::ASTArray.new( + :children => children + ) + } + + trans = nil + scope = nil + assert_nothing_raised { + scope = Puppet::Parser::Scope.new() + trans = scope.evaluate(:ast => top) + } + + return trans + end end class PuppetTestSuite |