summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-17 04:58:04 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2006-11-17 04:58:04 +0000
commitb3c3de22fd5f46e762c6a7c650a50b169b1e6089 (patch)
treecbb8734b017ae53dd75d1defeab52cb8c53c538a
parent407610138972c02266420c8ff76a55ce19537f96 (diff)
downloadpuppet-b3c3de22fd5f46e762c6a7c650a50b169b1e6089.tar.gz
puppet-b3c3de22fd5f46e762c6a7c650a50b169b1e6089.tar.xz
puppet-b3c3de22fd5f46e762c6a7c650a50b169b1e6089.zip
Fixing #342. Classes needed to have their namespaces set to their fully qualified names, so that contained code and definitions looked for definitions starting with that fq name.
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@1890 980ebf18-57e1-0310-9a29-db15c13687c0
-rw-r--r--lib/puppet/parser/interpreter.rb6
-rwxr-xr-xtest/language/ast.rb34
2 files changed, 39 insertions, 1 deletions
diff --git a/lib/puppet/parser/interpreter.rb b/lib/puppet/parser/interpreter.rb
index fe8e17084..4480a123a 100644
--- a/lib/puppet/parser/interpreter.rb
+++ b/lib/puppet/parser/interpreter.rb
@@ -505,7 +505,11 @@ class Puppet::Parser::Interpreter
else
# Define it anew.
ns, name = namesplit(fqname)
- args = {:type => name, :namespace => ns, :fqname => fqname, :interp => self}
+
+ # Note we're doing something somewhat weird here -- we're setting
+ # the class's namespace to its fully qualified name. This means
+ # anything inside that class starts looking in that namespace first.
+ args = {:type => name, :namespace => fqname, :fqname => fqname, :interp => self}
args[:code] = code if code
args[:parentclass] = parent if parent
@classtable[fqname] = @parser.ast AST::HostClass, args
diff --git a/test/language/ast.rb b/test/language/ast.rb
index 2f657e5c8..d414a4f96 100755
--- a/test/language/ast.rb
+++ b/test/language/ast.rb
@@ -323,6 +323,40 @@ class TestAST < Test::Unit::TestCase
assert_equal("755", secondobj[:mode])
end
+ # Make sure that classes set their namespaces to themselves. This
+ # way they start looking for definitions in their own namespace.
+ def test_hostclass_namespace
+ interp, scope, source = mkclassframing
+
+ # Create a new class
+ klass = nil
+ assert_nothing_raised do
+ klass = interp.newclass "funtest"
+ end
+
+ # Now define a definition in that namespace
+
+ define = nil
+ assert_nothing_raised do
+ define = interp.newdefine "funtest::mydefine"
+ end
+
+ assert_equal("funtest", klass.namespace,
+ "component namespace was not set in the class")
+
+ assert_equal("funtest", define.namespace,
+ "component namespace was not set in the definition")
+
+ newscope = klass.subscope(scope)
+
+ assert_equal("funtest", newscope.namespace,
+ "Scope did not inherit namespace")
+
+ # Now make sure we can find the define
+ assert(newscope.finddefine("mydefine"),
+ "Could not find definition in my enclosing class")
+ end
+
def test_node
interp = mkinterp
scope = mkscope(:interp => interp)