summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-10-28 14:15:08 +0100
committerBrice Figureau <brice-puppet@daysofwonder.com>2008-10-29 10:28:32 +0100
commit9f30306d2c768bad3327ecb7748669afb10cd4aa (patch)
tree94eb572fc97edd80968549bcb7fe599193bb09f0
parent649a9e009a3a5bd070051b972c2cf26989af8e8c (diff)
downloadpuppet-9f30306d2c768bad3327ecb7748669afb10cd4aa.tar.gz
puppet-9f30306d2c768bad3327ecb7748669afb10cd4aa.tar.xz
puppet-9f30306d2c768bad3327ecb7748669afb10cd4aa.zip
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@daysofwonder.com>
-rw-r--r--lib/puppet/parser/parser_support.rb6
-rwxr-xr-xspec/unit/parser/parser.rb28
-rw-r--r--test/data/snippets/multipleclass.pp9
-rwxr-xr-xtest/language/snippets.rb5
4 files changed, 47 insertions, 1 deletions
diff --git a/lib/puppet/parser/parser_support.rb b/lib/puppet/parser/parser_support.rb
index 853d6aa86..1583973a7 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 07aad588d..077f93d98 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,@two]
+ end
end
diff --git a/test/data/snippets/multipleclass.pp b/test/data/snippets/multipleclass.pp
new file mode 100644
index 000000000..ae02edc38
--- /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 ebc977388..1003ded9f 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 =~ /^\./