From 50a626daa1bef956ea63c405fddeaeab8a9a0756 Mon Sep 17 00:00:00 2001 From: Luke Kanies Date: Thu, 10 Jun 2010 19:21:05 -0700 Subject: Fixing #1545 - Adding 'caller_module_name' variable This will produce the name of the module that a given resource is defined in, rather than the module that the resource type itself is defined in. For instance: # in one/manifests/onedef.pp define one::onedef { notice "Called $name from $caller_module_name" } # in two/manifests/init.pp class two { one::onedef { yay: } } produces: Called yay from two This could obviously be extended to actually build a caller stack, as frightening as that seems. Signed-off-by: Luke Kanies --- spec/unit/parser/scope.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb index b14b2d3b6..4f30ff0cc 100755 --- a/spec/unit/parser/scope.rb +++ b/spec/unit/parser/scope.rb @@ -28,6 +28,21 @@ describe Puppet::Parser::Scope do @scope.class_scope(klass).should == "myscope" end + it "should be able to retrieve its parent module name from the source of its parent type" do + @topscope.source = Puppet::Resource::Type.new(:hostclass, :foo) + @topscope.source.module_name = "foo" + + @scope.parent_module_name.should == "foo" + end + + it "should return a nil parent module name if it has no parent" do + @topscope.parent_module_name.should be_nil + end + + it "should return a nil parent module name if its parent has no source" do + @scope.parent_module_name.should be_nil + end + # #620 - Nodes and classes should conflict, else classes don't get evaluated describe "when evaluating nodes and classes with the same name (#620)" do -- cgit