From b664fec30f8b7d8a4dd8621d8064df9b9789169b Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 23 Apr 2015 16:37:01 -0700 Subject: specs: loosen certain error expectations to make tests pass on future parser --- spec/functions/validate_integer_spec.rb | 6 +++--- spec/functions/validate_ipv4_address_spec.rb | 4 +--- spec/functions/validate_ipv6_address_spec.rb | 4 +--- spec/functions/validate_numeric_spec.rb | 6 +++--- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/spec/functions/validate_integer_spec.rb b/spec/functions/validate_integer_spec.rb index dff3415..3865c4f 100755 --- a/spec/functions/validate_integer_spec.rb +++ b/spec/functions/validate_integer_spec.rb @@ -43,7 +43,7 @@ describe Puppet::Parser::Functions.function(:validate_integer) do it "should not compile when #{the_number} is a bare word" do Puppet[:code] = "validate_integer(#{the_number})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be an Integer/) + expect { scope.compiler.compile }.to raise_error end end @@ -117,7 +117,7 @@ describe Puppet::Parser::Functions.function(:validate_integer) do it "should not compile when a non-Integer maximum #{the_max} bare word is passed" do Puppet[:code] = "validate_integer(1,#{the_max})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/) + expect { scope.compiler.compile }.to raise_error end end @@ -212,7 +212,7 @@ describe Puppet::Parser::Functions.function(:validate_integer) do it "should not compile when a non-Integer minimum #{the_min} bare word is passed" do Puppet[:code] = "validate_integer(1,#{max},#{the_min})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or an Integer/) + expect { scope.compiler.compile }.to raise_error end end end diff --git a/spec/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb index 45401a4..27ea4fe 100755 --- a/spec/functions/validate_ipv4_address_spec.rb +++ b/spec/functions/validate_ipv4_address_spec.rb @@ -39,9 +39,7 @@ describe Puppet::Parser::Functions.function(:validate_ipv4_address) do describe "when given numbers" do it "should not compile" do Puppet[:code] = "validate_ipv4_address(1, 2)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /is not a valid IPv4 address/) + expect { scope.compiler.compile }.to raise_error end end diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb index a839d90..e87b372 100755 --- a/spec/functions/validate_ipv6_address_spec.rb +++ b/spec/functions/validate_ipv6_address_spec.rb @@ -41,9 +41,7 @@ describe Puppet::Parser::Functions.function(:validate_ipv6_address) do describe "when given numbers" do it "should not compile" do Puppet[:code] = "validate_ipv6_address(1, 2)" - expect { - scope.compiler.compile - }.to raise_error(Puppet::ParseError, /not a valid IPv6 address/) + expect { scope.compiler.compile }.to raise_error end end end diff --git a/spec/functions/validate_numeric_spec.rb b/spec/functions/validate_numeric_spec.rb index c8b0e4d..1623a3d 100755 --- a/spec/functions/validate_numeric_spec.rb +++ b/spec/functions/validate_numeric_spec.rb @@ -43,7 +43,7 @@ describe Puppet::Parser::Functions.function(:validate_numeric) do it "should not compile when #{the_number} is a bare word" do Puppet[:code] = "validate_numeric(#{the_number})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be a Numeric/) + expect { scope.compiler.compile }.to raise_error end end @@ -115,7 +115,7 @@ describe Puppet::Parser::Functions.function(:validate_numeric) do it "should not compile when a non-Numeric maximum #{the_max} bare word is passed" do Puppet[:code] = "validate_numeric(1,#{the_max})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or a Numeric/) + expect { scope.compiler.compile }.to raise_error end end @@ -210,7 +210,7 @@ describe Puppet::Parser::Functions.function(:validate_numeric) do it "should not compile when a non-Numeric minimum #{the_min} bare word is passed" do Puppet[:code] = "validate_numeric(1,#{max},#{the_min})" - expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /to be unset or a Numeric/) + expect { scope.compiler.compile }.to raise_error end end end -- cgit v1.2.3 From a3016c45c5aaa979c9d148eb88bb3f7d1369a507 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 15 Apr 2015 16:55:28 -0700 Subject: specs: move function specs to where rspec-puppet expects them --- spec/functions/basename_spec.rb | 46 ++++++++++++++++++++++ spec/functions/bool2str_spec.rb | 46 ++++++++++++++++++++++ spec/functions/camelcase_spec.rb | 24 +++++++++++ spec/functions/type_of_spec.rb | 33 ++++++++++++++++ spec/unit/puppet/functions/type_of_spec.rb | 33 ---------------- spec/unit/puppet/parser/functions/basename_spec.rb | 46 ---------------------- spec/unit/puppet/parser/functions/bool2str_spec.rb | 46 ---------------------- .../unit/puppet/parser/functions/camelcase_spec.rb | 24 ----------- 8 files changed, 149 insertions(+), 149 deletions(-) create mode 100755 spec/functions/basename_spec.rb create mode 100755 spec/functions/bool2str_spec.rb create mode 100755 spec/functions/camelcase_spec.rb create mode 100644 spec/functions/type_of_spec.rb delete mode 100644 spec/unit/puppet/functions/type_of_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/basename_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/bool2str_spec.rb delete mode 100755 spec/unit/puppet/parser/functions/camelcase_spec.rb diff --git a/spec/functions/basename_spec.rb b/spec/functions/basename_spec.rb new file mode 100755 index 0000000..8a2d0dc --- /dev/null +++ b/spec/functions/basename_spec.rb @@ -0,0 +1,46 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the basename function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("basename").should == "function_basename" + end + + it "should raise a ParseError if there is less than 1 argument" do + lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if there are more than 2 arguments" do + lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError)) + end + + it "should return basename for an absolute path" do + result = scope.function_basename(['/path/to/a/file.ext']) + result.should(eq('file.ext')) + end + + it "should return basename for a relative path" do + result = scope.function_basename(['path/to/a/file.ext']) + result.should(eq('file.ext')) + end + + it "should strip extention when extension specified (absolute path)" do + result = scope.function_basename(['/path/to/a/file.ext', '.ext']) + result.should(eq('file')) + end + + it "should strip extention when extension specified (relative path)" do + result = scope.function_basename(['path/to/a/file.ext', '.ext']) + result.should(eq('file')) + end + + it "should complain about non-string first argument" do + lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError)) + end + + it "should complain about non-string second argument" do + lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError)) + end +end diff --git a/spec/functions/bool2str_spec.rb b/spec/functions/bool2str_spec.rb new file mode 100755 index 0000000..b878891 --- /dev/null +++ b/spec/functions/bool2str_spec.rb @@ -0,0 +1,46 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the bool2str function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + expect(Puppet::Parser::Functions.function("bool2str")).to eq("function_bool2str") + end + + it "should raise a ParseError if there is less than 1 arguments" do + expect { scope.function_bool2str([]) }.to( raise_error(Puppet::ParseError)) + end + + it "should convert true to 'true'" do + result = scope.function_bool2str([true]) + expect(result).to(eq('true')) + end + + it "should convert true to a string" do + result = scope.function_bool2str([true]) + expect(result.class).to(eq(String)) + end + + it "should convert false to 'false'" do + result = scope.function_bool2str([false]) + expect(result).to(eq('false')) + end + + it "should convert false to a string" do + result = scope.function_bool2str([false]) + expect(result.class).to(eq(String)) + end + + it "should not accept a string" do + expect { scope.function_bool2str(["false"]) }.to( raise_error(Puppet::ParseError)) + end + + it "should not accept a nil value" do + expect { scope.function_bool2str([nil]) }.to( raise_error(Puppet::ParseError)) + end + + it "should not accept an undef" do + expect { scope.function_bool2str([:undef]) }.to( raise_error(Puppet::ParseError)) + end +end diff --git a/spec/functions/camelcase_spec.rb b/spec/functions/camelcase_spec.rb new file mode 100755 index 0000000..70382ad --- /dev/null +++ b/spec/functions/camelcase_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the camelcase function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + expect(Puppet::Parser::Functions.function("camelcase")).to eq("function_camelcase") + end + + it "should raise a ParseError if there is less than 1 arguments" do + expect { scope.function_camelcase([]) }.to( raise_error(Puppet::ParseError)) + end + + it "should capitalize the beginning of a normal string" do + result = scope.function_camelcase(["abc"]) + expect(result).to(eq("Abc")) + end + + it "should camelcase an underscore-delimited string" do + result = scope.function_camelcase(["aa_bb_cc"]) + expect(result).to(eq("AaBbCc")) + end +end diff --git a/spec/functions/type_of_spec.rb b/spec/functions/type_of_spec.rb new file mode 100644 index 0000000..8afb624 --- /dev/null +++ b/spec/functions/type_of_spec.rb @@ -0,0 +1,33 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +if ENV["FUTURE_PARSER"] == 'yes' or Puppet.version >= "4" + require 'puppet/pops' + require 'puppet/loaders' + + describe 'the type_of function' do + before(:all) do + loaders = Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, [File.join(fixtures, "modules")])) + Puppet.push_context({:loaders => loaders}, "test-examples") + end + + after(:all) do + Puppet::Pops::Loaders.clear + Puppet::pop_context() + end + + let(:func) do + # Load the function from the environment modulepath's modules (ie, fixtures) + Puppet.lookup(:loaders).private_environment_loader.load(:function, 'type_of') + end + + it 'gives the type of a string' do + expect(func.call({}, 'hello world')).to be_kind_of(Puppet::Pops::Types::PStringType) + end + + it 'gives the type of an integer' do + expect(func.call({}, 5)).to be_kind_of(Puppet::Pops::Types::PIntegerType) + end + end +end diff --git a/spec/unit/puppet/functions/type_of_spec.rb b/spec/unit/puppet/functions/type_of_spec.rb deleted file mode 100644 index 8afb624..0000000 --- a/spec/unit/puppet/functions/type_of_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -#! /usr/bin/env ruby -S rspec - -require 'spec_helper' - -if ENV["FUTURE_PARSER"] == 'yes' or Puppet.version >= "4" - require 'puppet/pops' - require 'puppet/loaders' - - describe 'the type_of function' do - before(:all) do - loaders = Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, [File.join(fixtures, "modules")])) - Puppet.push_context({:loaders => loaders}, "test-examples") - end - - after(:all) do - Puppet::Pops::Loaders.clear - Puppet::pop_context() - end - - let(:func) do - # Load the function from the environment modulepath's modules (ie, fixtures) - Puppet.lookup(:loaders).private_environment_loader.load(:function, 'type_of') - end - - it 'gives the type of a string' do - expect(func.call({}, 'hello world')).to be_kind_of(Puppet::Pops::Types::PStringType) - end - - it 'gives the type of an integer' do - expect(func.call({}, 5)).to be_kind_of(Puppet::Pops::Types::PIntegerType) - end - end -end diff --git a/spec/unit/puppet/parser/functions/basename_spec.rb b/spec/unit/puppet/parser/functions/basename_spec.rb deleted file mode 100755 index 8a2d0dc..0000000 --- a/spec/unit/puppet/parser/functions/basename_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the basename function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - Puppet::Parser::Functions.function("basename").should == "function_basename" - end - - it "should raise a ParseError if there is less than 1 argument" do - lambda { scope.function_basename([]) }.should( raise_error(Puppet::ParseError)) - end - - it "should raise a ParseError if there are more than 2 arguments" do - lambda { scope.function_basename(['a', 'b', 'c']) }.should( raise_error(Puppet::ParseError)) - end - - it "should return basename for an absolute path" do - result = scope.function_basename(['/path/to/a/file.ext']) - result.should(eq('file.ext')) - end - - it "should return basename for a relative path" do - result = scope.function_basename(['path/to/a/file.ext']) - result.should(eq('file.ext')) - end - - it "should strip extention when extension specified (absolute path)" do - result = scope.function_basename(['/path/to/a/file.ext', '.ext']) - result.should(eq('file')) - end - - it "should strip extention when extension specified (relative path)" do - result = scope.function_basename(['path/to/a/file.ext', '.ext']) - result.should(eq('file')) - end - - it "should complain about non-string first argument" do - lambda { scope.function_basename([[]]) }.should( raise_error(Puppet::ParseError)) - end - - it "should complain about non-string second argument" do - lambda { scope.function_basename(['/path/to/a/file.ext', []]) }.should( raise_error(Puppet::ParseError)) - end -end diff --git a/spec/unit/puppet/parser/functions/bool2str_spec.rb b/spec/unit/puppet/parser/functions/bool2str_spec.rb deleted file mode 100755 index b878891..0000000 --- a/spec/unit/puppet/parser/functions/bool2str_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the bool2str function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("bool2str")).to eq("function_bool2str") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_bool2str([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should convert true to 'true'" do - result = scope.function_bool2str([true]) - expect(result).to(eq('true')) - end - - it "should convert true to a string" do - result = scope.function_bool2str([true]) - expect(result.class).to(eq(String)) - end - - it "should convert false to 'false'" do - result = scope.function_bool2str([false]) - expect(result).to(eq('false')) - end - - it "should convert false to a string" do - result = scope.function_bool2str([false]) - expect(result.class).to(eq(String)) - end - - it "should not accept a string" do - expect { scope.function_bool2str(["false"]) }.to( raise_error(Puppet::ParseError)) - end - - it "should not accept a nil value" do - expect { scope.function_bool2str([nil]) }.to( raise_error(Puppet::ParseError)) - end - - it "should not accept an undef" do - expect { scope.function_bool2str([:undef]) }.to( raise_error(Puppet::ParseError)) - end -end diff --git a/spec/unit/puppet/parser/functions/camelcase_spec.rb b/spec/unit/puppet/parser/functions/camelcase_spec.rb deleted file mode 100755 index 70382ad..0000000 --- a/spec/unit/puppet/parser/functions/camelcase_spec.rb +++ /dev/null @@ -1,24 +0,0 @@ -#! /usr/bin/env ruby -S rspec -require 'spec_helper' - -describe "the camelcase function" do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - it "should exist" do - expect(Puppet::Parser::Functions.function("camelcase")).to eq("function_camelcase") - end - - it "should raise a ParseError if there is less than 1 arguments" do - expect { scope.function_camelcase([]) }.to( raise_error(Puppet::ParseError)) - end - - it "should capitalize the beginning of a normal string" do - result = scope.function_camelcase(["abc"]) - expect(result).to(eq("Abc")) - end - - it "should camelcase an underscore-delimited string" do - result = scope.function_camelcase(["aa_bb_cc"]) - expect(result).to(eq("AaBbCc")) - end -end -- cgit v1.2.3 From c0cf14e77405ba3a0b7ae471d1ee1c249c7d4da8 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Thu, 9 Apr 2015 15:56:43 +0100 Subject: spec_helper_acceptance: fix FUTURE_PARSER usage Use the more common "yes", instead of "true" to detect FUTURE_PARSER. --- spec/spec_helper_acceptance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 3203ce9..79b1390 100755 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -33,7 +33,7 @@ RSpec.configure do |c| # Configure all nodes in nodeset c.before :suite do - if ENV['FUTURE_PARSER'] == 'true' + if ENV['FUTURE_PARSER'] == 'yes' default[:default_apply_opts] ||= {} default[:default_apply_opts].merge!({:parser => 'future'}) end -- cgit v1.2.3 From 29f09e2181a56ec801b39e56bd28119709495dd9 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 15 Apr 2015 16:46:09 -0700 Subject: spec_helper: set parser config if requested --- spec/lib/puppet_spec/compiler.rb | 1 + spec/spec_helper.rb | 2 ++ 2 files changed, 3 insertions(+) diff --git a/spec/lib/puppet_spec/compiler.rb b/spec/lib/puppet_spec/compiler.rb index 2f0ae4d..1f322ca 100755 --- a/spec/lib/puppet_spec/compiler.rb +++ b/spec/lib/puppet_spec/compiler.rb @@ -2,6 +2,7 @@ module PuppetSpec::Compiler def compile_to_catalog(string, node = Puppet::Node.new('foonode')) Puppet[:code] = string + Puppet[:parser] = 'future' if ENV['FUTURE_PARSER'] == 'yes' Puppet::Parser::Compiler.compile(node) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b490ca3..13014ab 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -30,5 +30,7 @@ RSpec.configure do |config| Facter::Util::Loader.any_instance.stubs(:load_all) Facter.clear Facter.clear_messages + + Puppet[:parser] = 'future' if ENV['FUTURE_PARSER'] == 'yes' end end -- cgit v1.2.3 From 24680aceec28df9e6dbe8c07a1136bfb78cad2fa Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 5 May 2015 13:30:54 +0100 Subject: spec_helper: use proper mocha import to avoid warning --- Gemfile | 1 + spec/spec_helper.rb | 4 +--- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 2d19594..82a5204 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ group :development, :unit_tests do gem 'rake', '~> 10.1.0', :require => false gem 'rspec', '~> 3.1.0', :require => false gem 'rspec-puppet', :require => false + gem 'mocha', :require => false gem 'puppetlabs_spec_helper', :require => false gem 'puppet-lint', :require => false gem 'pry', :require => false diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 13014ab..d3c9847 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,9 +17,7 @@ require 'puppet_spec/fixtures' require 'puppet_spec/matchers' require 'puppet_spec/database' require 'monkey_patches/alias_should_to_must' -require 'mocha/setup' - - +require 'mocha/api' RSpec.configure do |config| config.before :each do -- cgit v1.2.3 From 6a0a6153d59715d07f6bc50135df4adbae3d1334 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Tue, 5 May 2015 10:53:04 +0100 Subject: spec_helper: Remove unneccesary stubbing This only roots all Facter instances into memory, while something already creates a new Facter instance each run. --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d3c9847..896cb83 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -25,7 +25,6 @@ RSpec.configure do |config| # test cases. This requires each example group to explicitly load the # facts being exercised with something like # Facter.collection.loader.load(:ipaddress) - Facter::Util::Loader.any_instance.stubs(:load_all) Facter.clear Facter.clear_messages -- cgit v1.2.3 From 9bae8356fded9d1c7aaea96cba246709bfe1a516 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 22 Apr 2015 16:04:00 -0700 Subject: pw_hash: avoid ruby magic when running on java --- lib/puppet/parser/functions/pw_hash.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/puppet/parser/functions/pw_hash.rb b/lib/puppet/parser/functions/pw_hash.rb index ad3e393..4682a63 100644 --- a/lib/puppet/parser/functions/pw_hash.rb +++ b/lib/puppet/parser/functions/pw_hash.rb @@ -42,15 +42,13 @@ Puppet::Parser::Functions::newfunction( if 'test'.crypt('$1$1') != '$1$1$Bp8CU9Oujr9SSEw53WV6G.' # JRuby < 1.7.17 if RUBY_PLATFORM == 'java' - # override String#crypt for password variable - def password.crypt(salt) - # puppetserver bundles Apache Commons Codec - org.apache.commons.codec.digest.Crypt.crypt(self.to_java_bytes, salt) - end + # puppetserver bundles Apache Commons Codec + org.apache.commons.codec.digest.Crypt.crypt(password.to_java_bytes, salt) else # MS Windows and other systems that don't support enhanced salts raise Puppet::ParseError, 'system does not support enhanced salts' end + else + password.crypt("$#{hash_type}$#{args[2]}") end - password.crypt("$#{hash_type}$#{args[2]}") end -- cgit v1.2.3 From 063c58a992c1b5441b7e7b2a2e4886531035bb25 Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 22 Apr 2015 16:21:21 -0700 Subject: range: remove dead code Since a ParseError is always thrown for zero arguments, the if and all dependent code can be removed. --- lib/puppet/parser/functions/range.rb | 36 ++++++------------------------------ 1 file changed, 6 insertions(+), 30 deletions(-) diff --git a/lib/puppet/parser/functions/range.rb b/lib/puppet/parser/functions/range.rb index 49fba21..16d189f 100644 --- a/lib/puppet/parser/functions/range.rb +++ b/lib/puppet/parser/functions/range.rb @@ -41,29 +41,9 @@ Will return: [0,2,4,6,8] raise(Puppet::ParseError, "range(): Wrong number of " + "arguments given (#{arguments.size} for 1)") if arguments.size < 1 - if arguments.size > 1 - start = arguments[0] - stop = arguments[1] - step = arguments[2].nil? ? 1 : arguments[2].to_i.abs - - type = '..' # We select simplest type for Range available in Ruby ... - - elsif arguments.size > 0 - value = arguments[0] - - if m = value.match(/^(\w+)(\.\.\.?|\-)(\w+)$/) - start = m[1] - stop = m[3] - - type = m[2] - - elsif value.match(/^.+$/) - raise(Puppet::ParseError, 'range(): Unable to compute range ' + - 'from the value given') - else - raise(Puppet::ParseError, 'range(): Unknown format of range given') - end - end + start = arguments[0] + stop = arguments[1] + step = arguments[2].nil? ? 1 : arguments[2].to_i.abs # Check whether we have integer value if so then make it so ... if start.to_s.match(/^\d+$/) @@ -74,14 +54,10 @@ Will return: [0,2,4,6,8] stop = stop.to_s end - range = case type - when /^(\.\.|\-)$/ then (start .. stop) - when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ... - end - - result = range.step(step).collect { |i| i } # Get them all ... Pokemon ... + # We select simplest type for Range available in Ruby ... + range = (start .. stop) - return result + range.step(step).collect { |i| i } # Get them all ... Pokemon ... end end -- cgit v1.2.3 From d4f3d57f1678ae03a58a17181f863c44c248f09b Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Wed, 29 Apr 2015 12:13:08 +0100 Subject: validate_augeas: fix URL to docs --- lib/puppet/parser/functions/validate_augeas.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/parser/functions/validate_augeas.rb b/lib/puppet/parser/functions/validate_augeas.rb index 4ea4fe0..2196c3e 100644 --- a/lib/puppet/parser/functions/validate_augeas.rb +++ b/lib/puppet/parser/functions/validate_augeas.rb @@ -31,7 +31,7 @@ module Puppet::Parser::Functions ENDHEREDOC unless Puppet.features.augeas? - raise Puppet::ParseError, ("validate_augeas(): this function requires the augeas feature. See http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas#Pre-requisites for how to activate it.") + raise Puppet::ParseError, ("validate_augeas(): this function requires the augeas feature. See http://docs.puppetlabs.com/guides/augeas.html#pre-requisites for how to activate it.") end if (args.length < 2) or (args.length > 4) then -- cgit v1.2.3