[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

James Turnbull james at lovedthanlost.net
Wed Jul 14 10:29:30 UTC 2010


The following commit has been merged in the upstream branch:
commit 53be6f81261db1b7a022ec683e1a637cd2c5c93e
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Tue Nov 10 18:19:59 2009 +0100

    Fix #2796 - Fix puppetdoc rdoc selector parsing
    
    This patch fix this bug by adding more to_s methods to ast member
    so that puppetdoc can just to_s the AST to reconstruct the original
    puppet code.
    Of course this is not perfect, but should work most of the time.
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 153120a..b73c781 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -150,6 +150,10 @@ class Puppet::Parser::AST
                 return scope.lookupvar(@value)
             end
         end
+
+        def to_s
+            "\$#{value}"
+        end
     end
 
     class Regex < AST::Leaf
diff --git a/lib/puppet/parser/ast/resourceparam.rb b/lib/puppet/parser/ast/resourceparam.rb
index c552a7e..e6d9df1 100644
--- a/lib/puppet/parser/ast/resourceparam.rb
+++ b/lib/puppet/parser/ast/resourceparam.rb
@@ -18,5 +18,9 @@ class Puppet::Parser::AST
                 :add => self.add
             )
         end
+
+        def to_s
+            "#{@param} => #{@value.to_s}"
+        end
     end
 end
diff --git a/lib/puppet/parser/ast/selector.rb b/lib/puppet/parser/ast/selector.rb
index 1b05f57..84bc2a7 100644
--- a/lib/puppet/parser/ast/selector.rb
+++ b/lib/puppet/parser/ast/selector.rb
@@ -41,5 +41,9 @@ class Puppet::Parser::AST
         ensure
             scope.unset_ephemeral_var
         end
+
+        def to_s
+            param.to_s + " ? { " + values.collect { |v| v.to_s }.join(', ') + " }"
+        end
     end
 end
diff --git a/lib/puppet/util/rdoc/parser.rb b/lib/puppet/util/rdoc/parser.rb
index 61c08b4..416711d 100644
--- a/lib/puppet/util/rdoc/parser.rb
+++ b/lib/puppet/util/rdoc/parser.rb
@@ -274,12 +274,15 @@ class Parser
         declaration = ""
         define.arguments.each do |arg,value|
             declaration << "\$#{arg}"
-            if !value.nil?
+            unless value.nil?
                 declaration << " => "
-                if !value.is_a?(Puppet::Parser::AST::ASTArray)
+                case value
+                when Puppet::Parser::AST::Leaf
                     declaration << "'#{value.value}'"
-                else
+                when Puppet::Parser::AST::ASTArray
                     declaration << "[%s]" % value.children.collect { |v| "'#{v}'" }.join(", ")
+                else
+                    declaration << "#{value.to_s}"
                 end
             end
             declaration << ", "
diff --git a/spec/unit/parser/ast/leaf.rb b/spec/unit/parser/ast/leaf.rb
index e968150..fecfba3 100755
--- a/spec/unit/parser/ast/leaf.rb
+++ b/spec/unit/parser/ast/leaf.rb
@@ -72,6 +72,15 @@ describe Puppet::Parser::AST::String do
     end
 end
 
+describe Puppet::Parser::AST::Variable do
+    describe "when converting to string" do
+        it "should transform its value to a variable" do
+            value = stub 'value', :is_a? => true, :to_s => "myvar"
+            Puppet::Parser::AST::Variable.new( :value => value ).to_s.should == "\$myvar"
+        end
+    end
+end
+
 describe Puppet::Parser::AST::Regex do
     before :each do
         @scope = stub 'scope'
diff --git a/spec/unit/parser/ast/selector.rb b/spec/unit/parser/ast/selector.rb
index 8b00577..2ba83ad 100755
--- a/spec/unit/parser/ast/selector.rb
+++ b/spec/unit/parser/ast/selector.rb
@@ -151,6 +151,13 @@ describe Puppet::Parser::AST::Selector do
                 @selector.evaluate(@scope)
             end
         end
-
+    end
+    describe "when converting to string" do
+        it "should produce a string version of this selector" do
+            values = Puppet::Parser::AST::ASTArray.new :children => [ Puppet::Parser::AST::ResourceParam.new(:param => "type", :value => "value", :add => false) ]
+            param = Puppet::Parser::AST::Variable.new :value => "myvar"
+            selector = Puppet::Parser::AST::Selector.new :param => param, :values => values
+            selector.to_s.should == "$myvar ? { type => value }"
+        end
     end
 end
diff --git a/spec/unit/util/rdoc/parser.rb b/spec/unit/util/rdoc/parser.rb
index 558dac4..85a62e7 100755
--- a/spec/unit/util/rdoc/parser.rb
+++ b/spec/unit/util/rdoc/parser.rb
@@ -234,6 +234,18 @@ describe RDoc::Parser do
 
             lambda { @parser.document_define("mydef", @define, @class) }.should raise_error(Puppet::ParseError, /in file at line 42/)
         end
+
+        it "should convert all definition parameter to string" do
+            arg = stub 'arg'
+            val = stub 'val'
+
+            @define.stubs(:arguments).returns({arg => val})
+
+            arg.expects(:to_s).returns("arg")
+            val.expects(:to_s).returns("val")
+
+            @parser.document_define("mydef", @define, @class)
+        end
     end
 
     describe "when documenting nodes" do

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list