From ed0e741d82cd8f4ddb2f9d6bbc14699d2ef1ed9c Mon Sep 17 00:00:00 2001 From: martyewings Date: Mon, 24 Apr 2023 15:43:53 +0100 Subject: [PATCH] remove puppet 5.5 deprecations --- lib/puppet/functions/length.rb | 29 ----------------- lib/puppet/parser/functions/empty.rb | 32 ------------------- lib/puppet/parser/functions/flatten.rb | 37 ---------------------- lib/puppet/parser/functions/join.rb | 44 -------------------------- lib/puppet/parser/functions/keys.rb | 32 ------------------- lib/puppet/parser/functions/values.rb | 44 -------------------------- spec/functions/empty_spec.rb | 25 --------------- spec/functions/flatten_spec.rb | 18 ----------- spec/functions/join_spec.rb | 22 ------------- spec/functions/keys_spec.rb | 26 --------------- spec/functions/length_spec.rb | 33 ------------------- spec/functions/values_spec.rb | 26 --------------- 12 files changed, 368 deletions(-) delete mode 100644 lib/puppet/functions/length.rb delete mode 100644 lib/puppet/parser/functions/empty.rb delete mode 100644 lib/puppet/parser/functions/flatten.rb delete mode 100644 lib/puppet/parser/functions/join.rb delete mode 100644 lib/puppet/parser/functions/keys.rb delete mode 100644 lib/puppet/parser/functions/values.rb delete mode 100644 spec/functions/empty_spec.rb delete mode 100644 spec/functions/flatten_spec.rb delete mode 100644 spec/functions/join_spec.rb delete mode 100644 spec/functions/keys_spec.rb delete mode 100644 spec/functions/length_spec.rb delete mode 100644 spec/functions/values_spec.rb diff --git a/lib/puppet/functions/length.rb b/lib/puppet/functions/length.rb deleted file mode 100644 index d2e356ca6..000000000 --- a/lib/puppet/functions/length.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# **Deprecated:** A function to eventually replace the old size() function for stdlib -# -# The original size() function did not handle Puppets new type capabilities, so this function -# is a Puppet 4 compatible solution. -# -# > **Note:** **Deprecated** from Puppet 6.0.0, this function has been replaced with a -# built-in [`length`](https://puppet.com/docs/puppet/latest/function.html#length) function. -# -Puppet::Functions.create_function(:length) do - # @param value - # The value whose length is to be found - # - # @return [Integer] - # The length of the given object - dispatch :length do - param 'Variant[String,Array,Hash]', :value - end - def length(value) - if value.is_a?(String) - result = value.length - elsif value.is_a?(Array) || value.is_a?(Hash) - result = value.size - end - result - end -end diff --git a/lib/puppet/parser/functions/empty.rb b/lib/puppet/parser/functions/empty.rb deleted file mode 100644 index ee1dabca2..000000000 --- a/lib/puppet/parser/functions/empty.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -# -# empty.rb -# -module Puppet::Parser::Functions - newfunction(:empty, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns true if the variable is empty. - - @return - Returns `true` if the argument is an array or hash that contains no elements, - or an empty string. Returns `false` when the argument is a numerical value. - - > *Note*: **Deprecated** from Puppet 5.5.0, the built-in - [`empty`](https://puppet.com/docs/puppet/6.4/function.html#empty) function will be used instead. - DOC - ) do |arguments| - raise(Puppet::ParseError, "empty(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? - value = arguments[0] - - unless value.is_a?(Array) || value.is_a?(Hash) || value.is_a?(String) || value.is_a?(Numeric) - raise(Puppet::ParseError, 'empty(): Requires either array, hash, string or integer to work with') - end - - return false if value.is_a?(Numeric) - result = value.empty? - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/flatten.rb b/lib/puppet/parser/functions/flatten.rb deleted file mode 100644 index a544d33fd..000000000 --- a/lib/puppet/parser/functions/flatten.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -# -# flatten.rb -# -module Puppet::Parser::Functions - newfunction(:flatten, type: :rvalue, doc: <<-DOC - @summary - This function flattens any deeply nested arrays and returns a single flat array - as a result. - - @return - convert nested arrays into a single flat array - - @example Example usage - - flatten(['a', ['b', ['c']]])` returns: `['a','b','c'] - - > **Note:** **Deprecated** from Puppet 5.5.0, this function has been replaced with a - built-in [`flatten`](https://puppet.com/docs/puppet/latest/function.html#flatten) function. - DOC - ) 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) - raise(Puppet::ParseError, 'flatten(): Requires array to work with') - end - - result = array.flatten - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/join.rb b/lib/puppet/parser/functions/join.rb deleted file mode 100644 index f1e4bc141..000000000 --- a/lib/puppet/parser/functions/join.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -# -# join.rb -# -module Puppet::Parser::Functions - newfunction(:join, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** This function joins an array into a string using a separator. - - @example Example Usage: - join(['a','b','c'], ",") # Results in: "a,b,c" - - @return [String] - The String containing each of the array values - - > **Note:** **Deprecated** from Puppet 5.4.0 this function has been replaced - with a built-in [`join`](https://puppet.com/docs/puppet/latest/function.html#join) function. - DOC - ) do |arguments| - # Technically we support two arguments but only first is mandatory ... - raise(Puppet::ParseError, "join(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? - - array = arguments[0] - - unless array.is_a?(Array) - raise(Puppet::ParseError, 'join(): Requires array to work with') - end - - suffix = arguments[1] if arguments[1] - - if suffix - unless suffix.is_a?(String) - raise(Puppet::ParseError, 'join(): Requires string to work with') - end - end - - result = suffix ? array.join(suffix) : array.join - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/keys.rb b/lib/puppet/parser/functions/keys.rb deleted file mode 100644 index 10a85477d..000000000 --- a/lib/puppet/parser/functions/keys.rb +++ /dev/null @@ -1,32 +0,0 @@ -# frozen_string_literal: true - -# -# keys.rb -# -module Puppet::Parser::Functions - newfunction(:keys, type: :rvalue, doc: <<-DOC - @summary - **Deprecated:** Returns the keys of a hash as an array. - - @return [Array] - An array containing each of the hashes key values. - - > **Note:** **Deprecated** from Puppet 5.5.0, the built-in [`keys`](https://puppet.com/docs/puppet/latest/function.html#keys) - function will be used instead of this function. - DOC - ) do |arguments| - raise(Puppet::ParseError, "keys(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? - - hash = arguments[0] - - unless hash.is_a?(Hash) - raise(Puppet::ParseError, 'keys(): Requires hash to work with') - end - - result = hash.keys - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/lib/puppet/parser/functions/values.rb b/lib/puppet/parser/functions/values.rb deleted file mode 100644 index a47fe5277..000000000 --- a/lib/puppet/parser/functions/values.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -# -# values.rb -# -module Puppet::Parser::Functions - newfunction(:values, type: :rvalue, doc: <<-DOC - @summary - When given a hash this function will return the values of that hash. - - @return - array of values - - @example **Usage** - $hash = { - 'a' => 1, - 'b' => 2, - 'c' => 3, - } - values($hash) - - This example would return: ```[1,2,3]``` - - > *Note:* - From Puppet 5.5.0, the compatible function with the same name in Puppet core - will be used instead of this function. - - DOC - ) do |arguments| - raise(Puppet::ParseError, "values(): Wrong number of arguments given (#{arguments.size} for 1)") if arguments.empty? - - hash = arguments[0] - - unless hash.is_a?(Hash) - raise(Puppet::ParseError, 'values(): Requires hash to work with') - end - - result = hash.values - - return result - end -end - -# vim: set ts=2 sw=2 et : diff --git a/spec/functions/empty_spec.rb b/spec/functions/empty_spec.rb deleted file mode 100644 index 5b0ba29cd..000000000 --- a/spec/functions/empty_spec.rb +++ /dev/null @@ -1,25 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'empty', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } - it { - pending('Current implementation ignores parameters after the first.') - is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError) - } - it { is_expected.to run.with_params(false).and_raise_error(Puppet::ParseError, %r{Requires either array, hash, string or integer}) } - it { is_expected.to run.with_params(0).and_return(false) } - it { is_expected.to run.with_params('').and_return(true) } - it { is_expected.to run.with_params('one').and_return(false) } - - it { is_expected.to run.with_params(AlsoString.new('')).and_return(true) } - it { is_expected.to run.with_params(AlsoString.new('one')).and_return(false) } - - it { is_expected.to run.with_params([]).and_return(true) } - it { is_expected.to run.with_params(['one']).and_return(false) } - - it { is_expected.to run.with_params({}).and_return(true) } - it { is_expected.to run.with_params('key' => 'value').and_return(false) } -end diff --git a/spec/functions/flatten_spec.rb b/spec/functions/flatten_spec.rb deleted file mode 100644 index 365535baa..000000000 --- a/spec/functions/flatten_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'flatten', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } - it { is_expected.to run.with_params([], []).and_raise_error(Puppet::ParseError, %r{Wrong number of arguments}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires array}) } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Requires array}) } - - it { is_expected.to run.with_params([]).and_return([]) } - it { is_expected.to run.with_params(['one']).and_return(['one']) } - it { is_expected.to run.with_params([['one']]).and_return(['one']) } - it { is_expected.to run.with_params(['a', 'b', 'c', 'd', 'e', 'f', 'g']).and_return(['a', 'b', 'c', 'd', 'e', 'f', 'g']) } - it { is_expected.to run.with_params([['a', 'b', ['c', ['d', 'e'], 'f', 'g']]]).and_return(['a', 'b', 'c', 'd', 'e', 'f', 'g']) } - it { is_expected.to run.with_params(['ã', 'β', ['ĉ', ['đ', 'ẽ', 'ƒ', 'ġ']]]).and_return(['ã', 'β', 'ĉ', 'đ', 'ẽ', 'ƒ', 'ġ']) } -end diff --git a/spec/functions/join_spec.rb b/spec/functions/join_spec.rb deleted file mode 100644 index 2175248ab..000000000 --- a/spec/functions/join_spec.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'join', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { - pending('Current implementation ignores parameters after the second.') - is_expected.to run.with_params([], '', '').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) - } - it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, %r{Requires array to work with}) } - it { is_expected.to run.with_params([], 2).and_raise_error(Puppet::ParseError, %r{Requires string to work with}) } - - it { is_expected.to run.with_params([]).and_return('') } - it { is_expected.to run.with_params([], ':').and_return('') } - it { is_expected.to run.with_params(['one']).and_return('one') } - it { is_expected.to run.with_params(['one'], ':').and_return('one') } - it { is_expected.to run.with_params(['one', 'two', 'three']).and_return('onetwothree') } - it { is_expected.to run.with_params(['one', 'two', 'three'], ':').and_return('one:two:three') } - it { is_expected.to run.with_params(['ōŋể', 'ŧשợ', 'ţђŕẽё'], ':').and_return('ōŋể:ŧשợ:ţђŕẽё') } -end diff --git a/spec/functions/keys_spec.rb b/spec/functions/keys_spec.rb deleted file mode 100644 index befc834cd..000000000 --- a/spec/functions/keys_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'keys', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { - pending('Current implementation ignores parameters after the first.') - is_expected.to run.with_params({}, {}).and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) - } - it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params({}).and_return([]) } - it { is_expected.to run.with_params('key' => 'value').and_return(['key']) } - it 'returns the array of keys' do - result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2' }]) - expect(result).to match_array(['key1', 'key2']) - end - - it 'runs with UTF8 and double byte characters' do - result = subject.call([{ 'ҝểү' => '√ẳŀμệ', 'キー' => '値' }]) - expect(result).to match_array(['ҝểү', 'キー']) - end -end diff --git a/spec/functions/length_spec.rb b/spec/functions/length_spec.rb deleted file mode 100644 index 183a31c4a..000000000 --- a/spec/functions/length_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'length', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(ArgumentError, %r{'length' expects 1 argument, got none}) } - it { is_expected.to run.with_params([], 'extra').and_raise_error(ArgumentError, %r{'length' expects 1 argument, got 2}) } - it { is_expected.to run.with_params(1).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Integer}) } - it { is_expected.to run.with_params(true).and_raise_error(ArgumentError, %r{expects a value of type String, Array, or Hash, got Boolean}) } - it { is_expected.to run.with_params('1').and_return(1) } - it { is_expected.to run.with_params('1.0').and_return(3) } - it { is_expected.to run.with_params([]).and_return(0) } - it { is_expected.to run.with_params(['a']).and_return(1) } - it { is_expected.to run.with_params(['one', 'two', 'three']).and_return(3) } - it { is_expected.to run.with_params(['one', 'two', 'three', 'four']).and_return(4) } - - it { is_expected.to run.with_params({}).and_return(0) } - it { is_expected.to run.with_params('1' => '2').and_return(1) } - it { is_expected.to run.with_params('1' => '2', '4' => '4').and_return(2) } - it { is_expected.to run.with_params('€' => '@', '竹' => 'ǿňè').and_return(2) } - - it { is_expected.to run.with_params('').and_return(0) } - it { is_expected.to run.with_params('a').and_return(1) } - it { is_expected.to run.with_params('abc').and_return(3) } - it { is_expected.to run.with_params('abcd').and_return(4) } - it { is_expected.to run.with_params('万').and_return(1) } - it { is_expected.to run.with_params('āβćđ').and_return(4) } - - context 'when using a class extending String' do - it { is_expected.to run.with_params(AlsoString.new('asdfghjkl')).and_return(9) } - end -end diff --git a/spec/functions/values_spec.rb b/spec/functions/values_spec.rb deleted file mode 100644 index b2c3e4b05..000000000 --- a/spec/functions/values_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'values', if: Puppet::Util::Package.versioncmp(Puppet.version, '5.5.0') < 0 do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - it { - pending('Current implementation ignores parameters after the first.') - is_expected.to run.with_params({}, 'extra').and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) - } - it { is_expected.to run.with_params('').and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params([]).and_raise_error(Puppet::ParseError, %r{Requires hash to work with}) } - it { is_expected.to run.with_params({}).and_return([]) } - it { is_expected.to run.with_params('key' => 'value').and_return(['value']) } - it 'returns the array of values' do - result = subject.call([{ 'key1' => 'value1', 'key2' => 'value2', 'duplicate_value_key' => 'value2' }]) - expect(result).to match_array(['value1', 'value2', 'value2']) - end - - it 'runs with UTF8 and double byte characters' do - result = subject.call([{ 'かぎ' => '使用', 'ҝĕұ' => '√ẩŀứệ', 'ҝĕұďŭрļǐçằťè' => '√ẩŀứệ' }]) - expect(result).to match_array(['使用', '√ẩŀứệ', '√ẩŀứệ']) - end -end