diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-12 22:22:45 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2006-05-12 22:22:45 +0000 |
| commit | 678e14286f441524955c76fcfca6abace7106774 (patch) | |
| tree | 06d37afc1841edcefeae23d5ad9f245df5ebdfa8 | |
| parent | 578cf7e575c4bb3a297506c75035aed2b2ef607b (diff) | |
| download | puppet-678e14286f441524955c76fcfca6abace7106774.tar.gz puppet-678e14286f441524955c76fcfca6abace7106774.tar.xz puppet-678e14286f441524955c76fcfca6abace7106774.zip | |
Fixing #141. It was a problem related to the recent parser changes I made.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1185 980ebf18-57e1-0310-9a29-db15c13687c0
| -rw-r--r-- | examples/code/snippets/deepclassheirarchy.pp | 23 | ||||
| -rw-r--r-- | lib/puppet/parser/ast/hostclass.rb | 32 | ||||
| -rw-r--r-- | lib/puppet/parser/scope.rb | 1 | ||||
| -rwxr-xr-x | test/language/ast.rb | 75 | ||||
| -rwxr-xr-x | test/language/functions.rb | 73 | ||||
| -rwxr-xr-x | test/language/snippets.rb | 8 | ||||
| -rw-r--r-- | test/puppettest.rb | 6 |
7 files changed, 163 insertions, 55 deletions
diff --git a/examples/code/snippets/deepclassheirarchy.pp b/examples/code/snippets/deepclassheirarchy.pp new file mode 100644 index 000000000..249e6334d --- /dev/null +++ b/examples/code/snippets/deepclassheirarchy.pp @@ -0,0 +1,23 @@ +# $Id$ + +class base { + file { "/tmp/deepclassheir1": ensure => file, mode => 755 } +} + +class sub1 inherits base { + file { "/tmp/deepclassheir2": ensure => file, mode => 755 } +} + +class sub2 inherits sub1 { + file { "/tmp/deepclassheir3": ensure => file, mode => 755 } +} + +class sub3 inherits sub2 { + file { "/tmp/deepclassheir4": ensure => file, mode => 755 } +} + +class sub4 inherits sub3 { + file { "/tmp/deepclassheir5": ensure => file, mode => 755 } +} + +include sub4 diff --git a/lib/puppet/parser/ast/hostclass.rb b/lib/puppet/parser/ast/hostclass.rb index a69d185e0..85beecfe7 100644 --- a/lib/puppet/parser/ast/hostclass.rb +++ b/lib/puppet/parser/ast/hostclass.rb @@ -9,7 +9,6 @@ class Puppet::Parser::AST #def evaluate(scope,hash,objtype,objname) def evaluate(hash) scope = hash[:scope] - objtype = hash[:type] objname = hash[:name] args = hash[:arguments] # Verify that we haven't already been evaluated @@ -24,22 +23,25 @@ class Puppet::Parser::AST # during the evaluation and can be inspected. scope.setclass(self.object_id, @type) + origscope = scope + # Default to creating a new context newcontext = true - transscope = nil - if parentscope = self.evalparent( + + # If we've got a parent, then we pass it the original scope we + # received. It will get passed all the way up to the top class, + # which will create a subscope and pass that subscope to its + # subclass. + if @parentscope = self.evalparent( :scope => scope, :arguments => args, :name => objname ) - # Override our scope binding with the parent scope - # binding. This is quite hackish, but I can't think - # of another way to make sure our scopes end up under - # our parent scopes. - if parentscope.is_a? Puppet::TransBucket + if @parentscope.is_a? Puppet::TransBucket raise Puppet::DevError, "Got a bucket instead of a scope" end - scope = parentscope - transscope = parentscope + # Override our scope binding with the parent scope + # binding. + scope = @parentscope # But don't create a new context if our parent created one newcontext = false @@ -67,6 +69,16 @@ class Puppet::Parser::AST # If we're a parent class, then return the scope object itself. return result else + transscope = nil + if @parentscope + transscope = @parentscope + until transscope.parent.object_id == origscope.object_id + transscope = transscope.parent + end + else + transscope = result + end + # But if we're the final subclass, translate the whole scope tree # into TransObjects and TransBuckets. return transscope.to_trans diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index 98ebe593a..03370558d 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -810,7 +810,6 @@ module Puppet::Parser results = [] @children.dup.each do |child| - if @@done.include?(child) raise Puppet::DevError, "Already translated %s" % child.object_id else diff --git a/test/language/ast.rb b/test/language/ast.rb index c3753a9e5..781e9ddd0 100755 --- a/test/language/ast.rb +++ b/test/language/ast.rb @@ -712,57 +712,46 @@ class TestAST < Test::Unit::TestCase assert(scope.classlist.include?("node"), "Node's name did not get set") end - def test_functions - assert_raise(Puppet::ParseError) do - Puppet::Parser::AST::Function.new( - :name => "fakefunction", - :arguments => AST::ASTArray.new( - :children => [nameobj("avalue")] - ) - ) - end - - assert_nothing_raised do - Puppet::Parser::Functions.newfunction(:fakefunction, :rvalue) do |input| - return "output %s" % input[0] - end - end + # Make sure that deep class parentage works + def test_classparentage + children = [] + files = [] + base = classobj("base") + files << "/base" - func = nil - assert_nothing_raised do - func = Puppet::Parser::AST::Function.new( - :name => "fakefunction", - :ftype => :rvalue, - :arguments => AST::ASTArray.new( - :children => [nameobj("avalue")] - ) - ) - end + children << base - scope = Puppet::Parser::Scope.new() - val = nil - assert_nothing_raised do - val = func.evaluate(:scope => scope) - end + parent = "base" + 5.times { |i| + name = "child%s" % i + files << "/%s" % name + children << classobj(name, :parentclass => nameobj(parent)) - assert_equal("output avalue", val) - end + parent = name + } - def test_taggedfunction - scope = Puppet::Parser::Scope.new() + children << functionobj("include", parent) - tag = "yayness" - scope.setclass(tag.object_id, tag) + top = nil + assert_nothing_raised("Could not create top object") { + top = AST::ASTArray.new( + :children => children + ) + } - {"yayness" => true, "booness" => false}.each do |tag, retval| - func = taggedobj(tag, :rvalue) + objects = nil + assert_nothing_raised("Could not evaluate") { + scope = Puppet::Parser::Scope.new() + objects = scope.evaluate(:ast => top) + } - val = nil - assert_nothing_raised do - val = func.evaluate(:scope => scope) - end + objects = objects.flatten - assert_equal(retval, val, "'tagged' returned %s for %s" % [val, tag]) + files.each do |file| + assert(objects.find { |o| o.name == file }, + "Could not find file %s" % file) end end end + +# $Id$ diff --git a/test/language/functions.rb b/test/language/functions.rb new file mode 100755 index 000000000..e39e23df7 --- /dev/null +++ b/test/language/functions.rb @@ -0,0 +1,73 @@ +#!/usr/bin/ruby + +if __FILE__ == $0 + $:.unshift '../../lib' + $:.unshift '..' + $puppetbase = "../.." +end + +require 'puppet' +require 'puppet/parser/interpreter' +require 'puppet/parser/parser' +require 'puppet/client' +require 'test/unit' +require 'puppettest' + +class TestLangFunctions < Test::Unit::TestCase + include ParserTesting + def test_functions + assert_raise(Puppet::ParseError) do + Puppet::Parser::AST::Function.new( + :name => "fakefunction", + :arguments => AST::ASTArray.new( + :children => [nameobj("avalue")] + ) + ) + end + + assert_nothing_raised do + Puppet::Parser::Functions.newfunction(:fakefunction, :rvalue) do |input| + return "output %s" % input[0] + end + end + + func = nil + assert_nothing_raised do + func = Puppet::Parser::AST::Function.new( + :name => "fakefunction", + :ftype => :rvalue, + :arguments => AST::ASTArray.new( + :children => [nameobj("avalue")] + ) + ) + end + + scope = Puppet::Parser::Scope.new() + val = nil + assert_nothing_raised do + val = func.evaluate(:scope => scope) + end + + assert_equal("output avalue", val) + end + + def test_taggedfunction + scope = Puppet::Parser::Scope.new() + + tag = "yayness" + scope.setclass(tag.object_id, tag) + + {"yayness" => true, "booness" => false}.each do |tag, retval| + func = taggedobj(tag, :rvalue) + + val = nil + assert_nothing_raised do + val = func.evaluate(:scope => scope) + end + + assert_equal(retval, val, "'tagged' returned %s for %s" % [val, tag]) + end + end +end + +# $Id$ diff --git a/test/language/snippets.rb b/test/language/snippets.rb index 287bc615b..0ba2fb6ed 100755 --- a/test/language/snippets.rb +++ b/test/language/snippets.rb @@ -453,6 +453,14 @@ class TestSnippets < Test::Unit::TestCase assert_equal(0755, filemode(file)) end + def snippet_deepclassheirarchy(trans) + 5.times { |i| + i += 1 + file = "/tmp/deepclassheir%s" % i + assert(FileTest.exists?(file), "File %s does not exist" % file) + } + end + def snippet_emptyclass(trans) # There's nothing to check other than that it works end diff --git a/test/puppettest.rb b/test/puppettest.rb index 2ebe85a33..375098d10 100644 --- a/test/puppettest.rb +++ b/test/puppettest.rb @@ -927,10 +927,14 @@ module ParserTesting end def taggedobj(name, ftype = :statement) + functionobj("tagged", name, ftype) + end + + def functionobj(function, name, ftype = :statement) func = nil assert_nothing_raised do func = Puppet::Parser::AST::Function.new( - :name => "tagged", + :name => function, :ftype => ftype, :arguments => AST::ASTArray.new( :children => [nameobj(name)] |
