Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set arity on all functions #176

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ matrix:
allow_failures:
- rvm: 2.0.0
- rvm: ruby-head
include:
- rvm: 1.8.7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes tests fail on 2.7,but that's not really supported by
stdlib 4.x anyway
On 11 Sep 2013 14:15, "Adrien Thebo" notifications@github.com wrote:

In .travis.yml:

@@ -12,7 +12,6 @@ matrix:
allow_failures:
- rvm: 2.0.0
- rvm: ruby-head

  • include:

Why is this necessary?


Reply to this email directly or view it on GitHubhttps://github.com//pull/176/files#r6301930
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dalen Unfortunately we still need to do our best effort to make stdlib 4.x work with Puppet 2.7 even though we said we'd be breaking backwards compatibility with the 4 major release.

The reason for this best effort is that we don't currently have an effective way to make sure modules that are compatible with Puppet 2.7 don't accidentally bring in the latest version of stdlib which would break compatibility with Puppet 2.7.

For example, on a Puppet 2.7 system, if an end user installs module "foo" from the forge and "foo" specifies a generic (not locked to a major or minor version) dependency on stdlib, then the latest version of stdlib will be pulled in, which will be incompatible with Puppet 2.7.

Until we sort out a way to resolve dependencies taking into account the base version of Puppet, then we need to be extra-careful about breaking compatibility with Puppet 2.7 even though we technically said we already did so in stdlib 4.

Does this make sense?

-Jeff

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but would it be acceptable to skip all the affected test cases on puppet 2.7?

There are some other test cases already that are only run on certain puppet versions.

env: PUPPET_GEM_VERSION="~> 2.7"
notifications:
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/abs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
#

module Puppet::Parser::Functions
newfunction(:abs, :type => :rvalue, :doc => <<-EOS
newfunction(:abs, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns the absolute value of a number, for example -34.56 becomes
34.56. Takes a single integer and float value as an argument.
EOS
) do |arguments|

raise(Puppet::ParseError, "abs(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]

# Numbers in Puppet are often string-encoded which is troublesome ...
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/any2array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:any2array, :type => :rvalue, :doc => <<-EOS
newfunction(:any2array, :type => :rvalue, :arity => -1, :doc => <<-EOS
This converts any object to an array containing that object. Empty argument
lists are converted to an empty array. Arrays are left untouched. Hashes are
converted to arrays of alternating keys and values.
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/parser/functions/base64.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Puppet::Parser::Functions

newfunction(:base64, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args|
newfunction(:base64, :type => :rvalue, :arity => 2, :doc => <<-'ENDHEREDOC') do |args|

Base64 encode or decode a string based on the command and the string submitted

Expand All @@ -13,8 +13,6 @@ module Puppet::Parser::Functions

require 'base64'

raise Puppet::ParseError, ("base64(): Wrong number of arguments (#{args.length}; must be = 2)") unless args.length == 2

actions = ['encode','decode']

unless actions.include?(args[0])
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/bool2num.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
#

module Puppet::Parser::Functions
newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS
newfunction(:bool2num, :type => :rvalue, :arity => 1, :doc => <<-EOS
Converts a boolean to a number. Converts the values:
false, f, 0, n, and no to 0
true, t, 1, y, and yes to 1
Requires a single boolean or string as an input.
EOS
) do |arguments|

raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/capitalize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
#

module Puppet::Parser::Functions
newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS
newfunction(:capitalize, :type => :rvalue, :arity => 1, :doc => <<-EOS
Capitalizes the first letter of a string or array of strings.
Requires either a single string or an array as an input.
EOS
) do |arguments|

raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/chomp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,13 @@
#

module Puppet::Parser::Functions
newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS'
newfunction(:chomp, :type => :rvalue, :arity => 1, :doc => <<-'EOS'
Removes the record separator from the end of a string or an array of
strings, for example `hello\n` becomes `hello`.
Requires a single string or array as an input.
EOS
) do |arguments|

raise(Puppet::ParseError, "chomp(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/chop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:chop, :type => :rvalue, :doc => <<-'EOS'
newfunction(:chop, :type => :rvalue, :arity => 1, :doc => <<-'EOS'
Returns a new string with the last character removed. If the string ends
with `\r\n`, both characters are removed. Applying chop to an empty
string returns an empty string. If you wish to merely remove record
Expand All @@ -12,9 +12,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

raise(Puppet::ParseError, "chop(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/concat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:concat, :type => :rvalue, :doc => <<-EOS
newfunction(:concat, :type => :rvalue, :arity => 2, :doc => <<-EOS
Appends the contents of array 2 onto array 1.

*Example:*
Expand All @@ -16,10 +16,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

# Check that 2 arguments have been given ...
raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
"given (#{arguments.size} for 2)") if arguments.size != 2

a = arguments[0]
b = arguments[1]

Expand Down
1 change: 1 addition & 0 deletions lib/puppet/parser/functions/defined_with_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Puppet::Parser::Functions.newfunction(:defined_with_params,
:type => :rvalue,
:arity => -1,
:doc => <<-'ENDOFDOC'
Takes a resource reference and an optional hash of attributes.

Expand Down
7 changes: 1 addition & 6 deletions lib/puppet/parser/functions/delete.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# TODO(Krzysztof Wilczynski): We need to add support for regular expression ...

module Puppet::Parser::Functions
newfunction(:delete, :type => :rvalue, :doc => <<-EOS
newfunction(:delete, :type => :rvalue, :arity => 2, :doc => <<-EOS
Deletes all instances of a given element from an array, substring from a
string, or key from a hash.

Expand All @@ -22,11 +22,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

if (arguments.size != 2) then
raise(Puppet::ParseError, "delete(): Wrong number of arguments "+
"given #{arguments.size} for 2.")
end

collection = arguments[0]
item = arguments[1]

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/delete_at.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS
newfunction(:delete_at, :type => :rvalue, :arity => 2, :doc => <<-EOS
Deletes a determined indexed value from an array.

*Examples:*
Expand All @@ -14,9 +14,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " +
"given (#{arguments.size} for 2)") if arguments.size < 2

array = arguments[0]

unless array.is_a?(Array)
Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/delete_undef_values.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Puppet::Parser::Functions
newfunction(:delete_undef_values, :type => :rvalue, :doc => <<-EOS
newfunction(:delete_undef_values, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns a copy of input hash or array with all undefs deleted.

*Examples:*
Expand All @@ -15,10 +15,6 @@ module Puppet::Parser::Functions
EOS
) do |args|

raise(Puppet::ParseError,
"delete_undef_values(): Wrong number of arguments given " +
"(#{args.size})") if args.size < 1

result = args[0]
if result.is_a?(Hash)
result.delete_if {|key, val| val.equal? :undef}
Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/delete_values.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Puppet::Parser::Functions
newfunction(:delete_values, :type => :rvalue, :doc => <<-EOS
newfunction(:delete_values, :type => :rvalue, :arity => 2, :doc => <<-EOS
Deletes all instances of a given value from a hash.

*Examples:*
Expand All @@ -11,10 +11,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

raise(Puppet::ParseError,
"delete_values(): Wrong number of arguments given " +
"(#{arguments.size} of 2)") if arguments.size != 2

hash, item = arguments

if not hash.is_a?(Hash)
Expand Down
6 changes: 1 addition & 5 deletions lib/puppet/parser/functions/difference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:difference, :type => :rvalue, :doc => <<-EOS
newfunction(:difference, :type => :rvalue, :arity => 2, :doc => <<-EOS
This function returns the difference between two arrays.
The returned array is a copy of the original array, removing any items that
also appear in the second array.
Expand All @@ -16,10 +16,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

# Two arguments are required
raise(Puppet::ParseError, "difference(): Wrong number of arguments " +
"given (#{arguments.size} for 2)") if arguments.size != 2

first = arguments[0]
second = arguments[1]

Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/dirname.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
module Puppet::Parser::Functions
newfunction(:dirname, :type => :rvalue, :doc => <<-EOS
newfunction(:dirname, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns the dirname of a path.
EOS
) do |arguments|

raise(Puppet::ParseError, "dirname(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

path = arguments[0]
return File.dirname(path)
end
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/downcase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#

module Puppet::Parser::Functions
newfunction(:downcase, :type => :rvalue, :doc => <<-EOS
newfunction(:downcase, :type => :rvalue, :arity => 1, :doc => <<-EOS
Converts the case of a string or all strings in an array to lower case.
EOS
) do |arguments|

raise(Puppet::ParseError, "downcase(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:empty, :type => :rvalue, :doc => <<-EOS
newfunction(:empty, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns true if the variable is empty.
EOS
) do |arguments|
Expand Down
4 changes: 1 addition & 3 deletions lib/puppet/parser/functions/ensure_packages.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
require 'puppet/parser/functions'

module Puppet::Parser::Functions
newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS
newfunction(:ensure_packages, :type => :statement, :arity => 1, :doc => <<-EOS
Takes a list of packages and only installs them if they don't already exist.
EOS
) do |arguments|

raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size != 1
raise(Puppet::ParseError, "ensure_packages(): Requires array " +
"given (#{arguments[0].class})") if !arguments[0].kind_of?(Array)

Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/ensure_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Puppet::Parser::Functions.newfunction(:ensure_resource,
:type => :statement,
:arity => -3,
:doc => <<-'ENDOFDOC'
Takes a resource type, title, and a list of attributes that describe a
resource.
Expand All @@ -27,8 +28,6 @@
ENDOFDOC
) do |vals|
type, title, params = vals
raise(ArgumentError, 'Must specify a type') unless type
raise(ArgumentError, 'Must specify a title') unless title
params ||= {}

items = [title].flatten
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/flatten.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#

module Puppet::Parser::Functions
newfunction(:flatten, :type => :rvalue, :doc => <<-EOS
newfunction(:flatten, :type => :rvalue, :arity => 1, :doc => <<-EOS
This function flattens any deeply nested arrays and returns a single flat array
as a result.

Expand All @@ -15,9 +15,6 @@ module Puppet::Parser::Functions
EOS
) do |arguments|

raise(Puppet::ParseError, "flatten(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size != 1

array = arguments[0]

unless array.is_a?(Array)
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/floor.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
module Puppet::Parser::Functions
newfunction(:floor, :type => :rvalue, :doc => <<-EOS
newfunction(:floor, :type => :rvalue, :arity => 1, :doc => <<-EOS
Returns the largest integer less or equal to the argument.
Takes a single numeric value as an argument.
EOS
) do |arguments|

raise(Puppet::ParseError, "floor(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size != 1

arg = arguments[0]

raise(Puppet::ParseError, "floor(): Wrong argument type " +
Expand Down
5 changes: 1 addition & 4 deletions lib/puppet/parser/functions/fqdn_rotate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
#

module Puppet::Parser::Functions
newfunction(:fqdn_rotate, :type => :rvalue, :doc => <<-EOS
newfunction(:fqdn_rotate, :type => :rvalue, :arity => 1, :doc => <<-EOS
Rotates an array a random number of times based on a nodes fqdn.
EOS
) do |arguments|

raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1

value = arguments[0]
klass = value.class
require 'digest/md5'
Expand Down
3 changes: 1 addition & 2 deletions lib/puppet/parser/functions/get_module_path.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
module Puppet::Parser::Functions
newfunction(:get_module_path, :type =>:rvalue, :doc => <<-EOT
newfunction(:get_module_path, :type =>:rvalue, :arity => 1, :doc => <<-EOT
Returns the absolute path of the specified module for the current
environment.

Example:
$module_path = get_module_path('stdlib')
EOT
) do |args|
raise(Puppet::ParseError, "get_module_path(): Wrong number of arguments, expects one") unless args.size == 1
if module_path = Puppet::Module.find(args[0], compiler.environment.to_s)
module_path.path
else
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/parser/functions/getparam.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Puppet::Parser::Functions.newfunction(:getparam,
:type => :rvalue,
:arity => 2,
:doc => <<-'ENDOFDOC'
Takes a resource reference and name of the parameter and
returns value of resource's parameter.
Expand All @@ -22,7 +23,6 @@
ENDOFDOC
) do |vals|
reference, param = vals
raise(ArgumentError, 'Must specify a reference') unless reference
raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String

return '' if param.empty?
Expand Down
Loading