[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585
Brice Figureau
brice-puppet at daysofwonder.com
Fri Jan 23 14:21:34 UTC 2009
The following commit has been merged in the master branch:
commit 9f30306d2c768bad3327ecb7748669afb10cd4aa
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date: Tue Oct 28 14:15:08 2008 +0100
Fix #857 - Multiple class of the same name don't append code
The following manifest wasn't working:
class one {
notice('class one')
}
class one {
notice('second class one')
}
include one
It all boiled down to class code not being arrays.
Encapsulating code in ASTArray when needed is enough to append code,
because of the property of ASTArray to evaluate all their members in
turn.
Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 853d6aa..1583973 100644
--- a/lib/puppet/parser/parser_support.rb
+++ b/lib/puppet/parser/parser_support.rb
@@ -291,10 +291,14 @@ class Puppet::Parser::Parser
if tmp == ""
tmp = "main"
end
-
+
Puppet.debug addcontext("Adding code to %s" % tmp)
# Else, add our code to it.
if other.code and code
+ # promote if neededcodes to ASTArray so that we can append code
+ # ASTArray knows how to evaluate its members.
+ other.code = ast AST::ASTArray, :children => [other.code] unless other.code.is_a?(AST::ASTArray)
+ code = ast AST::ASTArray, :children => [code] unless code.is_a?(AST::ASTArray)
other.code.children += code.children
else
other.code ||= code
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 07aad58..077f93d 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -171,6 +171,34 @@ describe Puppet::Parser do
it "should not raise errors with a trailing comma" do
lambda { @parser.parse("$a = [1,2,]") }.should_not raise_error
end
+ end
+
+ describe Puppet::Parser, "when instantiating class of same name" do
+
+ before :each do
+ @one = stub 'one', :is_a? => true
+ @one.stubs(:is_a?).with(AST::ASTArray).returns(false)
+ @one.stubs(:is_a?).with(AST).returns(true)
+
+ @two = stub 'two'
+ @two.stubs(:is_a?).with(AST::ASTArray).returns(false)
+ @two.stubs(:is_a?).with(AST).returns(true)
+ end
+
+ it "should return the first class" do
+
+ klass1 = @parser.newclass("one", { :code => @one })
+
+ @parser.newclass("one", { :code => @two }).should == klass1
+ end
+
+ it "should concatenate code" do
+ klass1 = @parser.newclass("one", { :code => @one })
+
+ @parser.newclass("one", { :code => @two })
+
+ klass1.code.children.should == [@one, at two]
+ end
end
diff --git a/test/data/snippets/multipleclass.pp b/test/data/snippets/multipleclass.pp
new file mode 100644
index 0000000..ae02edc
--- /dev/null
+++ b/test/data/snippets/multipleclass.pp
@@ -0,0 +1,9 @@
+class one {
+ file { "/tmp/multipleclassone": content => "one" }
+}
+
+class one {
+ file { "/tmp/multipleclasstwo": content => "two" }
+}
+
+include one
diff --git a/test/language/snippets.rb b/test/language/snippets.rb
index ebc9773..1003ded 100755
--- a/test/language/snippets.rb
+++ b/test/language/snippets.rb
@@ -460,6 +460,11 @@ class TestSnippets < Test::Unit::TestCase
"Did not make second file from array")
end
+ def snippet_multipleclass
+ assert_file("/tmp/multipleclassone", "one")
+ assert_file("/tmp/multipleclasstwo", "two")
+ end
+
# Iterate across each of the snippets and create a test.
Dir.entries(snippetdir).sort.each { |file|
next if file =~ /^\./
--
Puppet packaging for Debian
More information about the Pkg-puppet-devel
mailing list