summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/ast/component.rb16
-rw-r--r--lib/puppet/parser/ast/objectdef.rb4
-rwxr-xr-xtest/language/scope.rb49
-rw-r--r--test/puppettest.rb27
4 files changed, 68 insertions, 28 deletions
diff --git a/lib/puppet/parser/ast/component.rb b/lib/puppet/parser/ast/component.rb
index 0ecdb1d02..00677e1ea 100644
--- a/lib/puppet/parser/ast/component.rb
+++ b/lib/puppet/parser/ast/component.rb
@@ -24,24 +24,14 @@ class Puppet::Parser::AST
:name => objname,
:keyword => self.keyword
)
- if hash[:newcontext]
+ newcontext = hash[:newcontext]
+
+ unless self.is_a? AST::HostClass and ! newcontext
#scope.warning "Setting context to %s" % self.object_id
scope.context = self.object_id
end
@scope = scope
- # The type is the component or class name
- #scope.type = objtype
-
- # The name is the name the user has chosen or that has
- # been dynamically generated. This is almost never used
- #scope.name = objname
-
- #scope.keyword = self.keyword
-
- #if self.is_a?(Node)
- # scope.isnodescope
- #end
# Additionally, add a tag for whatever kind of class
# we are
diff --git a/lib/puppet/parser/ast/objectdef.rb b/lib/puppet/parser/ast/objectdef.rb
index 0b8d50e6d..59758b982 100644
--- a/lib/puppet/parser/ast/objectdef.rb
+++ b/lib/puppet/parser/ast/objectdef.rb
@@ -285,7 +285,7 @@ class Puppet::Parser::AST
return true unless defined? @scope and @scope
# Unless we can look up the type, throw an error
- unless objtype = @scope.lookuptype(objtype)
+ unless typeobj = @scope.lookuptype(objtype)
error = Puppet::ParseError.new(
"Unknown type '%s'" % objtype
)
@@ -297,7 +297,7 @@ class Puppet::Parser::AST
# Now that we have the type, verify all of the parameters.
# Note that we're now passing an AST Class object or whatever
# as the type, not a simple string.
- self.paramcheck(builtin, objtype)
+ self.paramcheck(builtin, typeobj)
end
end
diff --git a/test/language/scope.rb b/test/language/scope.rb
index 2921afb42..a18b75bff 100755
--- a/test/language/scope.rb
+++ b/test/language/scope.rb
@@ -464,4 +464,53 @@ class TestScope < Test::Unit::TestCase
objects = top.evaluate(:scope => scope)
}
end
+
+ # Verify that definitions have a different context than classes.
+ def test_newsubcontext
+ filename = tempfile()
+ children = []
+
+ # Create a component
+ children << compobj("comp", :code => AST::ASTArray.new(
+ :children => [
+ fileobj(filename, "owner" => "root" )
+ ]
+ ))
+
+ # Now create a class that modifies the same file and also
+ # calls the component
+ children << classobj("klass", :code => AST::ASTArray.new(
+ :children => [
+ fileobj(filename, "owner" => "bin" ),
+ AST::ObjectDef.new(
+ :type => nameobj("comp"),
+ :params => astarray()
+ )
+ ]
+ ))
+
+ # Now call the class
+ children << AST::ObjectDef.new(
+ :type => nameobj("klass"),
+ :params => astarray()
+ )
+
+ top = nil
+ assert_nothing_raised("Could not create top object") {
+ top = AST::ASTArray.new(
+ :children => children
+ )
+ }
+
+ trans = nil
+ scope = nil
+ #assert_nothing_raised {
+ assert_raise(Puppet::ParseError, "A conflict was allowed") {
+ scope = Puppet::Parser::Scope.new()
+ trans = scope.evaluate(:ast => top)
+ }
+ # scope = Puppet::Parser::Scope.new()
+ # trans = scope.evaluate(:ast => top)
+ #}
+ end
end
diff --git a/test/puppettest.rb b/test/puppettest.rb
index 54dfc1f17..a16f4d80b 100644
--- a/test/puppettest.rb
+++ b/test/puppettest.rb
@@ -708,19 +708,15 @@ module ParserTesting
end
def classobj(name, args = {})
- unless args.include?(:name)
- args[:type] = nameobj(name)
- end
- unless args.include?(:code)
- args[:code] = AST::ASTArray.new(
- :file => tempfile(),
- :line => rand(100),
- :children => [
- varobj("%svar" % name, "%svalue" % name),
- fileobj("/%s" % name)
- ]
- )
- end
+ args[:type] ||= nameobj(name)
+ args[:code] ||= AST::ASTArray.new(
+ :file => tempfile(),
+ :line => rand(100),
+ :children => [
+ varobj("%svar" % name, "%svalue" % name),
+ fileobj("/%s" % name)
+ ]
+ )
assert_nothing_raised("Could not create class %s" % name) {
return AST::ClassDef.new(args)
}
@@ -730,6 +726,11 @@ module ParserTesting
args[:file] ||= tempfile()
args[:line] ||= rand(100)
args[:type] ||= nameobj(name)
+ args[:args] ||= AST::ASTArray.new(
+ :file => tempfile(),
+ :line => rand(100),
+ :children => []
+ )
args[:code] ||= AST::ASTArray.new(
:file => tempfile(),
:line => rand(100),