diff options
author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-10-30 01:12:03 +0000 |
---|---|---|
committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2005-10-30 01:12:03 +0000 |
commit | e605a5c181ef8cd2ec57384c7816bf1f7980aedb (patch) | |
tree | 0586a1fdf8850eb4350ee4f0369b7ae9a2b0aadb /test | |
parent | 526deef2c44ac66edce85e18257f5341bd4ecb9c (diff) | |
download | puppet-e605a5c181ef8cd2ec57384c7816bf1f7980aedb.tar.gz puppet-e605a5c181ef8cd2ec57384c7816bf1f7980aedb.tar.xz puppet-e605a5c181ef8cd2ec57384c7816bf1f7980aedb.zip |
The language now verifies some resemblance to closurehood. I now only need to fix the library to expect this behaviour.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@736 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test')
-rwxr-xr-x | test/language/ast.rb | 134 | ||||
-rwxr-xr-x | test/language/scope.rb | 113 | ||||
-rw-r--r-- | test/puppettest.rb | 106 |
3 files changed, 239 insertions, 114 deletions
diff --git a/test/language/ast.rb b/test/language/ast.rb index d78ce382c..6aa89c225 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -14,109 +14,7 @@ require 'test/unit' require 'puppettest' class TestAST < Test::Unit::TestCase - include TestPuppet - AST = Puppet::Parser::AST - - def astarray - AST::ASTArray.new( - :children => [] - ) - end - - def classobj(name, args = {}) - unless args.include?(:name) - args[:name] = nameobj(name) - end - unless args.include?(:code) - args[:code] = AST::ASTArray.new( - :children => [ - varobj("%svar" % name, "%svalue" % name), - fileobj("/%s" % name) - ] - ) - end - assert_nothing_raised("Could not create class %s" % name) { - return AST::ClassDef.new(args) - } - end - - def compobj(name, args = {}) - args[:name] = nameobj(name) - args[:code] = AST::ASTArray.new( - :children => [ - varobj("%svar" % name, "%svalue" % name), - fileobj("/%s" % name) - ] - ) - assert_nothing_raised("Could not create compdef %s" % name) { - return AST::CompDef.new(args) - } - end - - def fileobj(path, hash = {"owner" => "root"}) - assert_nothing_raised("Could not create file %s" % path) { - return AST::ObjectDef.new( - :name => stringobj(path), - :type => nameobj("file"), - :params => objectinst(hash) - ) - } - end - - def nameobj(name) - assert_nothing_raised("Could not create name %s" % name) { - return AST::Name.new( - :value => name - ) - } - end - - def nodeobj(name) - assert_nothing_raised("Could not create node %s" % name) { - return AST::NodeDef.new( - :names => nameobj(name), - :code => AST::ASTArray.new( - :children => [ - varobj("%svar" % name, "%svalue" % name), - fileobj("/%s" % name) - ] - ) - ) - } - end - - def objectinst(hash) - assert_nothing_raised("Could not create object instance") { - params = hash.collect { |param, value| - objectparam(param, value) - } - return AST::ObjectInst.new( - :children => params - ) - } - end - - def objectparam(param, value) - assert_nothing_raised("Could not create param %s" % param) { - return AST::ObjectParam.new( - :param => nameobj(param), - :value => stringobj(value) - ) - } - end - - def stringobj(value) - AST::String.new(:value => value) - end - - def varobj(name, value) - assert_nothing_raised("Could not create %s code" % name) { - return AST::VarDef.new( - :name => nameobj(name), - :value => stringobj(value) - ) - } - end + include ParserTesting # Test that classes behave like singletons def test_classsingleton @@ -441,7 +339,7 @@ class TestAST < Test::Unit::TestCase end # Test that node inheritance works correctly - def test_nodeinheritance + def test_znodeinheritance children = [] # create the base node @@ -487,14 +385,28 @@ class TestAST < Test::Unit::TestCase } assert(objects, "Could not retrieve node definition") - # And now verify that we got the subnode file - assert_nothing_raised("Could not find basenode file") { - assert_equal("/basenode", objects[0][0][:name]) - } + assert_nothing_raised { + inner = objects[0] + + # And now verify that we got the subnode file + assert_nothing_raised("Could not find basenode file") { + base = inner[0] + assert_equal("/basenode", base[:name]) + } - # and the parent node file - assert_nothing_raised("Could not find subnode file") { - assert_equal("/subnode", objects[0][1][:name]) + # and the parent node file + assert_nothing_raised("Could not find subnode file") { + sub = inner[1] + assert_equal("/subnode", sub[:name]) + } + + inner.each { |obj| + %w{basenode subnode}.each { |tag| + assert(obj.tags.include?(tag), + "%s did not include %s tag" % [obj[:name], tag] + ) + } + } } end end diff --git a/test/language/scope.rb b/test/language/scope.rb index 38bcdce5a..3937ad361 100755 --- a/test/language/scope.rb +++ b/test/language/scope.rb @@ -23,8 +23,8 @@ require 'puppettest' # and test whether we've got things in the right scopes class TestScope < Test::Unit::TestCase - include TestPuppet - AST = Puppet::Parser::AST + include ParserTesting + def to_ary(hash) hash.collect { |key,value| [key,value] @@ -260,7 +260,7 @@ class TestScope < Test::Unit::TestCase end # Test some of the host manipulations - def test_zhostlookup + def test_hostlookup top = Puppet::Parser::Scope.new(nil) # Create a deep scope tree, so that we know we're doing a deeply recursive @@ -302,4 +302,111 @@ class TestScope < Test::Unit::TestCase assert(host, "Could not find host") assert(host.code == :notused, "Host is not what we stored") end + + # Verify that two statements about a file within the same scope tree + # will cause a conflict. + def test_noconflicts + filename = tempfile() + children = [] + + # create the parent class + children << classobj("one", :code => AST::ASTArray.new( + :children => [ + fileobj(filename, "owner" => "root") + ] + )) + + # now create a child class with differ values + children << classobj("two", + :code => AST::ASTArray.new( + :children => [ + fileobj(filename, "owner" => "bin") + ] + )) + + # Now call the child class + assert_nothing_raised("Could not add AST nodes for calling") { + children << AST::ObjectDef.new( + :type => nameobj("two"), + :name => nameobj("yayness"), + :params => astarray() + ) << AST::ObjectDef.new( + :type => nameobj("one"), + :name => nameobj("yayness"), + :params => astarray() + ) + } + + top = nil + assert_nothing_raised("Could not create top object") { + top = AST::ASTArray.new( + :children => children + ) + } + + objects = nil + scope = nil + + # Here's where we should encounter the failure. It should find that + # it has already created an object with that name, and this should result + # in some pukey-pukeyness. + assert_raise(Puppet::ParseError) { + scope = Puppet::Parser::Scope.new() + objects = scope.evaluate(top) + } + end + + # Verify that we override statements that we find within our scope + def test_zsuboverrides + filename = tempfile() + children = [] + + # create the parent class + children << classobj("parent", :code => AST::ASTArray.new( + :children => [ + fileobj(filename, "owner" => "root") + ] + )) + + # now create a child class with differ values + children << classobj("child", :parentclass => nameobj("parent"), + :code => AST::ASTArray.new( + :children => [ + fileobj(filename, "owner" => "bin") + ] + )) + + # Now call the child class + assert_nothing_raised("Could not add AST nodes for calling") { + children << AST::ObjectDef.new( + :type => nameobj("child"), + :name => nameobj("yayness"), + :params => astarray() + ) + } + + top = nil + assert_nothing_raised("Could not create top object") { + top = AST::ASTArray.new( + :children => children + ) + } + + objects = nil + scope = nil + assert_nothing_raised("Could not evaluate") { + scope = Puppet::Parser::Scope.new() + objects = scope.evaluate(top) + } + + assert_equal(1, objects.length, "Returned too many objects: %s" % + objects.inspect) + assert_equal(1, objects[0].length, "Returned too many objects: %s" % + objects[0].inspect) + assert_nothing_raised { + file = objects[0][0] + + assert_equal("bin", file["owner"], "Value did not override correctly") + } + end end diff --git a/test/puppettest.rb b/test/puppettest.rb index 6f6b961f8..ccaa027cd 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -561,6 +561,112 @@ module FileTesting end end +module ParserTesting + include TestPuppet + AST = Puppet::Parser::AST + + def astarray + AST::ASTArray.new( + :children => [] + ) + end + + def classobj(name, args = {}) + unless args.include?(:name) + args[:name] = nameobj(name) + end + unless args.include?(:code) + args[:code] = AST::ASTArray.new( + :children => [ + varobj("%svar" % name, "%svalue" % name), + fileobj("/%s" % name) + ] + ) + end + assert_nothing_raised("Could not create class %s" % name) { + return AST::ClassDef.new(args) + } + end + + def compobj(name, args = {}) + args[:name] = nameobj(name) + args[:code] = AST::ASTArray.new( + :children => [ + varobj("%svar" % name, "%svalue" % name), + fileobj("/%s" % name) + ] + ) + assert_nothing_raised("Could not create compdef %s" % name) { + return AST::CompDef.new(args) + } + end + + def fileobj(path, hash = {"owner" => "root"}) + assert_nothing_raised("Could not create file %s" % path) { + return AST::ObjectDef.new( + :name => stringobj(path), + :type => nameobj("file"), + :params => objectinst(hash) + ) + } + end + + def nameobj(name) + assert_nothing_raised("Could not create name %s" % name) { + return AST::Name.new( + :value => name + ) + } + end + + def nodeobj(name) + assert_nothing_raised("Could not create node %s" % name) { + return AST::NodeDef.new( + :names => nameobj(name), + :code => AST::ASTArray.new( + :children => [ + varobj("%svar" % name, "%svalue" % name), + fileobj("/%s" % name) + ] + ) + ) + } + end + + def objectinst(hash) + assert_nothing_raised("Could not create object instance") { + params = hash.collect { |param, value| + objectparam(param, value) + } + return AST::ObjectInst.new( + :children => params + ) + } + end + + def objectparam(param, value) + assert_nothing_raised("Could not create param %s" % param) { + return AST::ObjectParam.new( + :param => nameobj(param), + :value => stringobj(value) + ) + } + end + + def stringobj(value) + AST::String.new(:value => value) + end + + def varobj(name, value) + assert_nothing_raised("Could not create %s code" % name) { + return AST::VarDef.new( + :name => nameobj(name), + :value => stringobj(value) + ) + } + end +end + class PuppetTestSuite attr_accessor :subdir |