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

Markus Roberts Markus at reality.com
Tue Jul 20 07:42:41 UTC 2010


The following commit has been merged in the upstream branch:
commit 539d71635132bd5f772a550b7bfff530e8b59b68
Author: Matt Robinson <matt at puppetlabs.com>
Date:   Mon Jul 19 14:57:23 2010 -0700

    [#4287] Fix the undefined evaluate_match error when comparing functions
    
    Ticket #4238 introduced a problem that a function couldn't compare to
    another value until after it was evaluated, and AST::Function didn't have the
    evaluate_match method.  This change moves that method from AST::Leaf to AST.
    
    The special casing necessary for doing comparisons between AST objects
    feels messy and could probably be encapsulated better.  I've created
    ticket #4291 to remind us to refactor this at some point.
    
    Paired with: Nick Lewis
    
    Signed-off-by: Matt Robinson <matt at puppetlabs.com>

diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
index 2773a24..54e034a 100644
--- a/lib/puppet/parser/ast.rb
+++ b/lib/puppet/parser/ast.rb
@@ -87,6 +87,20 @@ class Puppet::Parser::AST
   def initialize(args)
     set_options(args)
   end
+
+  # evaluate ourselves, and match
+  def evaluate_match(value, scope)
+    obj = self.safeevaluate(scope)
+
+    obj   = obj.downcase   if obj.respond_to?(:downcase)
+    value = value.downcase if value.respond_to?(:downcase)
+
+    obj   = Puppet::Parser::Scope.number?(obj)   || obj
+    value = Puppet::Parser::Scope.number?(value) || value
+
+    # "" == undef for case/selector/if
+    obj == value or (obj == "" and value == :undef)
+  end
 end
 
 # And include all of the AST subclasses.
diff --git a/lib/puppet/parser/ast/leaf.rb b/lib/puppet/parser/ast/leaf.rb
index 49f4302..db9788f 100644
--- a/lib/puppet/parser/ast/leaf.rb
+++ b/lib/puppet/parser/ast/leaf.rb
@@ -10,20 +10,6 @@ class Puppet::Parser::AST
       @value
     end
 
-    # evaluate ourselves, and match
-    def evaluate_match(value, scope)
-      obj = self.safeevaluate(scope)
-
-      obj   = obj.downcase   if obj.respond_to?(:downcase)
-      value = value.downcase if value.respond_to?(:downcase)
-
-      obj   = Puppet::Parser::Scope.number?(obj)   || obj
-      value = Puppet::Parser::Scope.number?(value) || value
-
-      # "" == undef for case/selector/if
-      obj == value or (obj == "" and value == :undef)
-    end
-
     def match(value)
       @value == value
     end
diff --git a/spec/unit/parser/ast/leaf_spec.rb b/spec/unit/parser/ast/leaf_spec.rb
index d21cbf5..6729cd2 100755
--- a/spec/unit/parser/ast/leaf_spec.rb
+++ b/spec/unit/parser/ast/leaf_spec.rb
@@ -13,63 +13,6 @@ describe Puppet::Parser::AST::Leaf do
     Puppet::Parser::AST::Leaf.new(:value => "value").should respond_to(:evaluate_match)
   end
 
-  describe "when evaluate_match is called" do
-    it "should evaluate itself" do
-      @leaf.expects(:safeevaluate).with(@scope)
-
-      @leaf.evaluate_match("value", @scope)
-    end
-
-    it "should match values by equality" do
-      @value.stubs(:==).returns(false)
-      @leaf.stubs(:safeevaluate).with(@scope).returns(@value)
-      @value.expects(:==).with("value")
-
-      @leaf.evaluate_match("value", @scope)
-    end
-
-    it "should downcase the evaluated value if wanted" do
-      @leaf.stubs(:safeevaluate).with(@scope).returns(@value)
-      @value.expects(:downcase).returns("value")
-
-      @leaf.evaluate_match("value", @scope)
-    end
-
-    it "should convert values to number" do
-      @leaf.stubs(:safeevaluate).with(@scope).returns(@value)
-      Puppet::Parser::Scope.expects(:number?).with(@value).returns(2)
-      Puppet::Parser::Scope.expects(:number?).with("23").returns(23)
-
-      @leaf.evaluate_match("23", @scope)
-    end
-
-    it "should compare 'numberized' values" do
-      @leaf.stubs(:safeevaluate).with(@scope).returns(@value)
-      two = stub_everything 'two'
-      one = stub_everything 'one'
-
-      Puppet::Parser::Scope.stubs(:number?).with(@value).returns(one)
-      Puppet::Parser::Scope.stubs(:number?).with("2").returns(two)
-
-      one.expects(:==).with(two)
-
-      @leaf.evaluate_match("2", @scope)
-    end
-
-    it "should match undef if value is an empty string" do
-      @leaf.stubs(:safeevaluate).with(@scope).returns("")
-
-      @leaf.evaluate_match(:undef, @scope).should be_true
-    end
-
-    it "should downcase the parameter value if wanted" do
-      parameter = stub 'parameter'
-      parameter.expects(:downcase).returns("value")
-
-      @leaf.evaluate_match(parameter, @scope)
-    end
-  end
-
   describe "when converting to string" do
     it "should transform its value to string" do
       value = stub 'value', :is_a? => true
diff --git a/spec/unit/parser/ast_spec.rb b/spec/unit/parser/ast_spec.rb
index b743cea..29dce2b 100644
--- a/spec/unit/parser/ast_spec.rb
+++ b/spec/unit/parser/ast_spec.rb
@@ -39,3 +39,73 @@ describe Puppet::Parser::AST do
   end
 
 end
+
+describe 'AST Generic Child' do
+  before :each do
+    @value = stub 'value'
+    class Evaluateable < Puppet::Parser::AST
+      attr_accessor :value
+      def safeevaluate(*options)
+        return value
+      end
+    end
+    @evaluateable = Evaluateable.new(:value => @value)
+    @scope = stubs 'scope'
+  end
+
+  describe "when evaluate_match is called" do
+    it "should evaluate itself" do
+      @evaluateable.expects(:safeevaluate).with(@scope)
+
+      @evaluateable.evaluate_match("value", @scope)
+    end
+
+    it "should match values by equality" do
+      @value.expects(:==).with("value").returns(true)
+
+      @evaluateable.evaluate_match("value", @scope)
+    end
+
+    it "should downcase the evaluated value if wanted" do
+      @value.expects(:downcase).returns("value")
+
+      @evaluateable.evaluate_match("value", @scope)
+    end
+
+    it "should convert values to number" do
+      Puppet::Parser::Scope.expects(:number?).with(@value).returns(2)
+      Puppet::Parser::Scope.expects(:number?).with("23").returns(23)
+
+      @evaluateable.evaluate_match("23", @scope)
+    end
+
+    it "should compare 'numberized' values" do
+      two = stub_everything 'two'
+      one = stub_everything 'one'
+
+      Puppet::Parser::Scope.stubs(:number?).with(@value).returns(one)
+      Puppet::Parser::Scope.stubs(:number?).with("2").returns(two)
+
+      one.expects(:==).with(two)
+
+      @evaluateable.evaluate_match("2", @scope)
+    end
+
+    it "should match undef if value is an empty string" do
+      @evaluateable.value = ''
+      @evaluateable.evaluate_match(:undef, @scope).should be_true
+    end
+
+    it "should downcase the parameter value if wanted" do
+      parameter = stub 'parameter'
+      parameter.expects(:downcase).returns("value")
+
+      @evaluateable.evaluate_match(parameter, @scope)
+    end
+
+    it "should not match '' if value is undef" do
+      @evaluateable.value = :undef
+      @evaluateable.evaluate_match('', @scope).should be_false
+    end
+  end
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list