summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/functions
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2008-12-19 17:38:50 +0100
committerJames Turnbull <james@lovedthanlost.net>2008-12-27 12:46:58 +1100
commitd2d3de5884a66f529101854a42ac52be83cde446 (patch)
tree5ffc33182b341a55891cfcce68c7450d32985c69 /spec/unit/parser/functions
parentbdee116d08e9ed9c5efcf94a92709c061a8b43c2 (diff)
downloadpuppet-d2d3de5884a66f529101854a42ac52be83cde446.tar.gz
puppet-d2d3de5884a66f529101854a42ac52be83cde446.tar.xz
puppet-d2d3de5884a66f529101854a42ac52be83cde446.zip
Fix #1829 - Add puppet function versioncmp to compare versions
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec/unit/parser/functions')
-rwxr-xr-xspec/unit/parser/functions/versioncmp.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/unit/parser/functions/versioncmp.rb b/spec/unit/parser/functions/versioncmp.rb
new file mode 100755
index 000000000..06b125ea0
--- /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