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 <[EMAIL PROTECTED]>
---
 lib/puppet/parser/parser_support.rb |    6 +++++-
 spec/unit/parser/parser.rb          |   29 +++++++++++++++++++++++++++++
 test/data/snippets/multipleclass.pp |    9 +++++++++
 3 files changed, 43 insertions(+), 1 deletions(-)
 create mode 100644 test/data/snippets/multipleclass.pp

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 c0d22a2..100f6dd 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -142,4 +142,33 @@ describe Puppet::Parser do
 
     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 == [EMAIL PROTECTED],@two]
+        end
+
+    end
+
  end
diff --git a/test/data/snippets/multipleclass.pp 
b/test/data/snippets/multipleclass.pp
new file mode 100644
index 0000000..fb363a1
--- /dev/null
+++ b/test/data/snippets/multipleclass.pp
@@ -0,0 +1,9 @@
+class one {
+notice('class one')
+}
+
+class one {
+notice('second class one')
+}
+
+include one
\ No newline at end of file
-- 
1.6.0.2


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to