summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gemfile5
-rw-r--r--.gitignore3
-rw-r--r--.travis.yml25
-rw-r--r--lib/puppet/parser/functions/flatten.rb2
-rw-r--r--lib/puppet/parser/functions/max.rb10
-rw-r--r--lib/puppet/parser/functions/min.rb10
-rw-r--r--lib/puppet/parser/functions/str2bool.rb5
-rw-r--r--lib/puppet/provider/file_line/ruby.rb2
-rwxr-xr-xspec/unit/puppet/parser/functions/flatten_spec.rb4
-rwxr-xr-xspec/unit/puppet/parser/functions/max_spec.rb4
-rwxr-xr-xspec/unit/puppet/parser/functions/min_spec.rb4
-rw-r--r--spec/unit/puppet/parser/functions/str2bool_spec.rb7
12 files changed, 65 insertions, 16 deletions
diff --git a/.gemfile b/.gemfile
deleted file mode 100644
index 9aad840..0000000
--- a/.gemfile
+++ /dev/null
@@ -1,5 +0,0 @@
-source :rubygems
-
-puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
-gem 'puppet', puppetversion
-gem 'puppetlabs_spec_helper', '>= 0.1.0'
diff --git a/.gitignore b/.gitignore
index db949df..a7ea5fd 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
pkg/
.DS_Store
coverage/
+Gemfile.lock
+.bundle/
+vendor/bundle/
diff --git a/.travis.yml b/.travis.yml
index 0ec5a08..7e40b3f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,16 +1,27 @@
language: ruby
+bundler_args: --without development
+script: "bundle exec rake spec SPEC_OPTS='--color --format documentation'"
rvm:
- 1.8.7
-before_script:
-after_script:
-script: "rake spec_full"
-branches:
- only:
- - master
env:
+ - PUPPET_VERSION=">= 3.0.0"
+ - PUPPET_VERSION="~> 2.7.0"
- PUPPET_VERSION=2.7.13
- PUPPET_VERSION=2.7.6
- PUPPET_VERSION=2.6.9
+matrix:
+ allow_failures:
+ - rvm: 2.0.0
+ include:
+ - rvm: 2.0.0
+ env: PUPPET_VERSION=">= 3.0.0"
+ - rvm: 1.9.3
+ env: PUPPET_VERSION=">= 3.0.0"
notifications:
email: false
-gemfile: .gemfile
+ webhooks:
+ urls:
+ - https://puppet-dev-community.herokuapp.com/event/travis-ci/
+ on_success: always
+ on_failure: always
+ on_start: yes
diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb
index 781da78..a1ed183 100644
--- a/lib/puppet/parser/functions/flatten.rb
+++ b/lib/puppet/parser/functions/flatten.rb
@@ -16,7 +16,7 @@ Would return: ['a','b','c']
) do |arguments|
raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
- "given (#{arguments.size} for 1)") if arguments.size < 1
+ "given (#{arguments.size} for 1)") if arguments.size != 1
array = arguments[0]
diff --git a/lib/puppet/parser/functions/max.rb b/lib/puppet/parser/functions/max.rb
index 10b6f74..60fb94a 100644
--- a/lib/puppet/parser/functions/max.rb
+++ b/lib/puppet/parser/functions/max.rb
@@ -8,6 +8,14 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "max(): Wrong number of arguments " +
"need at least one") if args.size == 0
- return args.max
+ # Sometimes we get numbers as numerics and sometimes as strings.
+ # We try to compare them as numbers when possible
+ return args.max do |a,b|
+ if a.to_s =~ /\A-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
+ a.to_f <=> b.to_f
+ else
+ a.to_s <=> b.to_s
+ end
+ end
end
end
diff --git a/lib/puppet/parser/functions/min.rb b/lib/puppet/parser/functions/min.rb
index abf1b62..6bd6ebf 100644
--- a/lib/puppet/parser/functions/min.rb
+++ b/lib/puppet/parser/functions/min.rb
@@ -8,6 +8,14 @@ module Puppet::Parser::Functions
raise(Puppet::ParseError, "min(): Wrong number of arguments " +
"need at least one") if args.size == 0
- return args.min
+ # Sometimes we get numbers as numerics and sometimes as strings.
+ # We try to compare them as numbers when possible
+ return args.min do |a,b|
+ if a.to_s =~ /\A^-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then
+ a.to_f <=> b.to_f
+ else
+ a.to_s <=> b.to_s
+ end
+ end
end
end
diff --git a/lib/puppet/parser/functions/str2bool.rb b/lib/puppet/parser/functions/str2bool.rb
index c320da6..9ea6dd5 100644
--- a/lib/puppet/parser/functions/str2bool.rb
+++ b/lib/puppet/parser/functions/str2bool.rb
@@ -14,6 +14,11 @@ like: 0, f, n, false, no to 'false'.
"given (#{arguments.size} for 1)") if arguments.size < 1
string = arguments[0]
+
+ # If string is already Boolean, return it
+ if !!string == string
+ return string
+ end
unless string.is_a?(String)
raise(Puppet::ParseError, 'str2bool(): Requires either ' +
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index e21eaa8..a3219d3 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -34,7 +34,7 @@ Puppet::Type.type(:file_line).provide(:ruby) do
def handle_create_with_match()
regex = resource[:match] ? Regexp.new(resource[:match]) : nil
- match_count = lines.select { |l| regex.match(l) }.count
+ match_count = lines.select { |l| regex.match(l) }.size
if match_count > 1
raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'"
end
diff --git a/spec/unit/puppet/parser/functions/flatten_spec.rb b/spec/unit/puppet/parser/functions/flatten_spec.rb
index d4dfd20..dba7a6b 100755
--- a/spec/unit/puppet/parser/functions/flatten_spec.rb
+++ b/spec/unit/puppet/parser/functions/flatten_spec.rb
@@ -11,6 +11,10 @@ describe "the flatten function" do
lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError))
end
+ it "should raise a ParseError if there is more than 1 argument" do
+ lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError))
+ end
+
it "should flatten a complex data structure" do
result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]])
result.should(eq(["a","b","c","d","e","f","g"]))
diff --git a/spec/unit/puppet/parser/functions/max_spec.rb b/spec/unit/puppet/parser/functions/max_spec.rb
index 604927e..ff6f2b3 100755
--- a/spec/unit/puppet/parser/functions/max_spec.rb
+++ b/spec/unit/puppet/parser/functions/max_spec.rb
@@ -20,4 +20,8 @@ describe "the max function" do
it "should be able to compare numbers" do
scope.function_max([6,8,4]).should(eq(8))
end
+
+ it "should be able to compare a number with a stringified number" do
+ scope.function_max([1,"2"]).should(eq("2"))
+ end
end
diff --git a/spec/unit/puppet/parser/functions/min_spec.rb b/spec/unit/puppet/parser/functions/min_spec.rb
index 781422c..71d593e 100755
--- a/spec/unit/puppet/parser/functions/min_spec.rb
+++ b/spec/unit/puppet/parser/functions/min_spec.rb
@@ -20,4 +20,8 @@ describe "the min function" do
it "should be able to compare numbers" do
scope.function_min([6,8,4]).should(eq(4))
end
+
+ it "should be able to compare a number with a stringified number" do
+ scope.function_min([1,"2"]).should(eq(1))
+ end
end
diff --git a/spec/unit/puppet/parser/functions/str2bool_spec.rb b/spec/unit/puppet/parser/functions/str2bool_spec.rb
index 2782bbe..ef6350f 100644
--- a/spec/unit/puppet/parser/functions/str2bool_spec.rb
+++ b/spec/unit/puppet/parser/functions/str2bool_spec.rb
@@ -21,4 +21,11 @@ describe "the str2bool function" do
result = scope.function_str2bool(["undef"])
result.should(eq(false))
end
+
+ it "should return the boolean it was called with" do
+ result = scope.function_str2bool([true])
+ result.should(eq(true))
+ result = scope.function_str2bool([false])
+ result.should(eq(false))
+ end
end