Skip to content
Draft
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
25 changes: 1 addition & 24 deletions lib/puppet/functions/empty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
# * `Array`, `Hash` - having zero entries
# * `String`, `Binary` - having zero length
#
# For backwards compatibility with the stdlib function with the same name the
# following data types are also accepted by the function instead of raising an error.
# Using these is deprecated and will raise a warning:
#
# * `Numeric` - `false` is returned for all `Numeric` values.
# * `Undef` - `true` is returned for all `Undef` values.
# For backwards compatibility, `Undef` is also accepted and returns `true`.
#
# @example Using `empty`
#
Expand All @@ -36,10 +31,6 @@
param 'String', :str
end

dispatch :numeric_empty do
param 'Numeric', :num
end

dispatch :binary_empty do
param 'Binary', :bin
end
Expand All @@ -60,14 +51,6 @@ def string_empty(str)
str.empty?
end

# For compatibility reasons - return false rather than error on floats and integers
# (Yes, it is strange)
#
def numeric_empty(num)
deprecation_warning_for('Numeric')
false
end

def binary_empty(bin)
bin.length == 0
end
Expand All @@ -78,10 +61,4 @@ def binary_empty(bin)
def undef_empty(x)
true
end

def deprecation_warning_for(arg_type)
file, line = Puppet::Pops::PuppetStack.top_of_stack
msg = _("Calling function empty() with %{arg_type} value is deprecated.") % { arg_type: arg_type }
Puppet.warn_once('deprecations', "empty-from-#{file}-#{line}", msg, file, line)
end
end
16 changes: 0 additions & 16 deletions spec/unit/functions/empty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@
end
end

context 'for numeric values it' do
it 'always returns false for integer values (including 0)' do
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
expect(compile_to_catalog("notify { String(empty(0)): }")).to have_resource('Notify[false]')
end
expect(warnings).to include(/Calling function empty\(\) with Numeric value is deprecated/)
end

it 'always returns false for float values (including 0.0)' do
Puppet::Util::Log.with_destination(Puppet::Test::LogCollector.new(logs)) do
expect(compile_to_catalog("notify { String(empty(0.0)): }")).to have_resource('Notify[false]')
end
expect(warnings).to include(/Calling function empty\(\) with Numeric value is deprecated/)
end
end

context 'for a string it' do
it 'returns true when empty' do
expect(compile_to_catalog("notify { String(empty('')): }")).to have_resource('Notify[true]')
Expand Down