[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.7-1-98-gf19c0e5

James Turnbull james at lovedthanlost.net
Wed Apr 8 21:48:24 UTC 2009


The following commit has been merged in the master branch:
commit 991f82c9a50c8486f5dd9b273570568e9df6e982
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Fri Dec 19 17:38:50 2008 +0100

    Fix #1829 - Add puppet function versioncmp to compare versions
    
    Signed-off-by: Brice Figureau <brice-puppet at daysofwonder.com>

diff --git a/lib/puppet/parser/functions/versioncmp.rb b/lib/puppet/parser/functions/versioncmp.rb
new file mode 100644
index 0000000..62df38f
--- /dev/null
+++ b/lib/puppet/parser/functions/versioncmp.rb
@@ -0,0 +1,10 @@
+require 'puppet/util/package'
+
+Puppet::Parser::Functions::newfunction(:versioncmp,  :doc => "Compares two versions.") do |args|
+
+    unless args.length == 2
+        raise Puppet::ParseError, "versioncmp should have 2 arguments"
+    end
+
+    return Puppet::Util::Package.versioncmp(args[0], args[1])
+end
diff --git a/spec/unit/parser/functions/versioncmp.rb b/spec/unit/parser/functions/versioncmp.rb
new file mode 100755
index 0000000..06b125e
--- /dev/null
+++ b/spec/unit/parser/functions/versioncmp.rb
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe "the versioncmp function" do
+
+    before :each do
+        @scope = Puppet::Parser::Scope.new()
+    end
+
+    it "should exist" do
+        Puppet::Parser::Functions.function("versioncmp").should == "function_versioncmp"
+    end
+
+    it "should raise a ParseError if there is less than 2 arguments" do
+        lambda { @scope.function_versioncmp(["1.2"]) }.should raise_error(Puppet::ParseError)
+    end
+    
+    it "should raise a ParseError if there is more than 2 arguments" do
+        lambda { @scope.function_versioncmp(["1.2", "2.4.5", "3.5.6"]) }.should raise_error(Puppet::ParseError)
+    end
+    
+    it "should call Puppet::Util::Package.versioncmp (included in scope)" do
+        Puppet::Util::Package.expects(:versioncmp).with("1.2", "1.3").returns(-1)
+
+        @scope.function_versioncmp(["1.2", "1.3"])
+    end
+
+end

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list