[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

James Turnbull james at lovedthanlost.net
Fri Jan 23 14:21:33 UTC 2009


The following commit has been merged in the master branch:
commit c7ccc4ba7c42d56595564491ae578a1604c628d1
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Tue Oct 28 14:12:36 2008 +0100

    Fix #1682 - ASTArray should flatten product of evaluation of its children
    
    If the ASTArray contains children that evaluate to arrays themselves,
    they aren't flattened.

diff --git a/lib/puppet/parser/ast/astarray.rb b/lib/puppet/parser/ast/astarray.rb
index 8f09aa9..0fccbca 100644
--- a/lib/puppet/parser/ast/astarray.rb
+++ b/lib/puppet/parser/ast/astarray.rb
@@ -30,10 +30,9 @@ class Puppet::Parser::AST
                     items << child
                 end
             }
-
             rets = items.flatten.collect { |child|
                 child.safeevaluate(scope)
-            }
+            }.flatten
             return rets.reject { |o| o.nil? }
         end
 
diff --git a/spec/unit/parser/ast/astarray.rb b/spec/unit/parser/ast/astarray.rb
new file mode 100755
index 0000000..f1c28ce
--- /dev/null
+++ b/spec/unit/parser/ast/astarray.rb
@@ -0,0 +1,66 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::ASTArray do
+    before :each do
+        @scope = Puppet::Parser::Scope.new()
+    end
+
+    it "should have a [] accessor" do
+        array = Puppet::Parser::AST::ASTArray.new :children => []
+        array.should respond_to(:[])
+    end
+    
+    it "should evaluate all its children" do
+        item1 = stub "item1", :is_a? => true
+        item2 = stub "item2", :is_a? => true
+
+        item1.expects(:safeevaluate).with(@scope).returns(123)
+        item2.expects(:safeevaluate).with(@scope).returns(246)
+        
+        operator = Puppet::Parser::AST::ASTArray.new :children => [item1,item2]
+        operator.evaluate(@scope)
+    end
+
+    it "should evaluate childrens of type ASTArray" do
+        item1 = stub "item1", :is_a? => true
+        item2 = stub "item2"
+        item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
+        item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
+        item2.stubs(:each).yields(item1)
+        
+        item1.expects(:safeevaluate).with(@scope).returns(123)
+        
+        operator = Puppet::Parser::AST::ASTArray.new :children => [item2]
+        operator.evaluate(@scope).should == [123]
+    end
+
+    it "should flatten children coming from children ASTArray" do
+        item1 = stub "item1", :is_a? => true
+        item2 = stub "item2"
+        item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
+        item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
+        item2.stubs(:each).yields([item1])
+        
+        item1.expects(:safeevaluate).with(@scope).returns(123)
+        
+        operator = Puppet::Parser::AST::ASTArray.new :children => [item2]
+        operator.evaluate(@scope).should == [123]
+    end
+
+    it "should flatten the results of children evaluation" do
+        item1 = stub "item1", :is_a? => true
+        item2 = stub "item2"
+        item2.stubs(:is_a?).with(Puppet::Parser::AST).returns(true)
+        item2.stubs(:instance_of?).with(Puppet::Parser::AST::ASTArray).returns(true)
+        item2.stubs(:each).yields([item1])
+        
+        item1.expects(:safeevaluate).with(@scope).returns([123])
+        
+        operator = Puppet::Parser::AST::ASTArray.new :children => [item2]
+        operator.evaluate(@scope).should == [123]
+    end
+    
+    
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list