summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortphoney <tp@puppet.com>2016-08-08 17:35:13 +0100
committertphoney <tp@puppet.com>2016-08-08 17:46:11 +0100
commit22fbe723acd22ae3491c41beeacbc76853c6820e (patch)
treec91448e5face966d92d713b537316adcd08fbac3
parente39fe01ea01719b97110341cacc4b4e2784a7d1a (diff)
(modules-3532) deprecate string type checks
-rw-r--r--lib/puppet/parser/functions/is_absolute_path.rb4
-rw-r--r--lib/puppet/parser/functions/is_array.rb4
-rw-r--r--lib/puppet/parser/functions/is_bool.rb4
-rw-r--r--lib/puppet/parser/functions/is_string.rb2
-rw-r--r--lib/puppet/parser/functions/validate_absolute_path.rb2
-rw-r--r--lib/puppet/parser/functions/validate_array.rb2
-rw-r--r--lib/puppet/parser/functions/validate_bool.rb2
-rw-r--r--lib/puppet/parser/functions/validate_re.rb3
-rw-r--r--lib/puppet/parser/functions/validate_string.rb2
-rw-r--r--spec/aliases/absolute_path_spec.rb62
-rw-r--r--spec/aliases/array_spec.rb34
-rw-r--r--spec/aliases/bool_spec.rb32
-rw-r--r--spec/aliases/string_spec.rb31
-rw-r--r--spec/fixtures/modules/test/manifests/absolute_path.pp6
-rw-r--r--spec/fixtures/modules/test/manifests/array.pp8
-rw-r--r--spec/fixtures/modules/test/manifests/bool.pp8
-rw-r--r--spec/fixtures/modules/test/manifests/string.pp8
-rwxr-xr-xspec/functions/is_array_spec.rb5
-rwxr-xr-xspec/functions/is_bool_spec.rb5
-rwxr-xr-xspec/functions/is_string_spec.rb5
-rwxr-xr-xspec/functions/validate_absolute_path_spec.rb7
-rwxr-xr-xspec/functions/validate_array_spec.rb5
-rwxr-xr-xspec/functions/validate_bool_spec.rb7
-rwxr-xr-xspec/functions/validate_re_spec.rb6
-rwxr-xr-xspec/functions/validate_string_spec.rb6
-rw-r--r--types/compat/absolute_path.pp7
-rw-r--r--types/compat/array.pp2
-rw-r--r--types/compat/bool.pp2
-rw-r--r--types/compat/re.pp3
-rw-r--r--types/compat/string.pp2
30 files changed, 270 insertions, 6 deletions
diff --git a/lib/puppet/parser/functions/is_absolute_path.rb b/lib/puppet/parser/functions/is_absolute_path.rb
index 53a5445..2e37414 100644
--- a/lib/puppet/parser/functions/is_absolute_path.rb
+++ b/lib/puppet/parser/functions/is_absolute_path.rb
@@ -23,7 +23,7 @@ module Puppet::Parser::Functions
is_absolute_path($undefined)
ENDHEREDOC
-
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.'])
require 'puppet/util'
path = args[0]
@@ -47,4 +47,4 @@ module Puppet::Parser::Functions
end
value
end
-end \ No newline at end of file
+end
diff --git a/lib/puppet/parser/functions/is_array.rb b/lib/puppet/parser/functions/is_array.rb
index b39e184..d1bb58a 100644
--- a/lib/puppet/parser/functions/is_array.rb
+++ b/lib/puppet/parser/functions/is_array.rb
@@ -8,6 +8,8 @@ Returns true if the variable passed to this function is an array.
EOS
) do |arguments|
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.'])
+
raise(Puppet::ParseError, "is_array(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
@@ -18,5 +20,3 @@ Returns true if the variable passed to this function is an array.
return result
end
end
-
-# vim: set ts=2 sw=2 et :
diff --git a/lib/puppet/parser/functions/is_bool.rb b/lib/puppet/parser/functions/is_bool.rb
index 8bbdbc8..48aaa08 100644
--- a/lib/puppet/parser/functions/is_bool.rb
+++ b/lib/puppet/parser/functions/is_bool.rb
@@ -8,6 +8,8 @@ Returns true if the variable passed to this function is a boolean.
EOS
) do |arguments|
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.'])
+
raise(Puppet::ParseError, "is_bool(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size != 1
@@ -18,5 +20,3 @@ Returns true if the variable passed to this function is a boolean.
return result
end
end
-
-# vim: set ts=2 sw=2 et :
diff --git a/lib/puppet/parser/functions/is_string.rb b/lib/puppet/parser/functions/is_string.rb
index f5bef04..144cf51 100644
--- a/lib/puppet/parser/functions/is_string.rb
+++ b/lib/puppet/parser/functions/is_string.rb
@@ -8,6 +8,8 @@ Returns true if the variable passed to this function is a string.
EOS
) do |arguments|
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
+
raise(Puppet::ParseError, "is_string(): Wrong number of arguments " +
"given (#{arguments.size} for 1)") if arguments.size < 1
diff --git a/lib/puppet/parser/functions/validate_absolute_path.rb b/lib/puppet/parser/functions/validate_absolute_path.rb
index 5f85f72..d5f5443 100644
--- a/lib/puppet/parser/functions/validate_absolute_path.rb
+++ b/lib/puppet/parser/functions/validate_absolute_path.rb
@@ -26,6 +26,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.'])
+
require 'puppet/util'
unless args.length > 0 then
diff --git a/lib/puppet/parser/functions/validate_array.rb b/lib/puppet/parser/functions/validate_array.rb
index 34b5118..97bd41d 100644
--- a/lib/puppet/parser/functions/validate_array.rb
+++ b/lib/puppet/parser/functions/validate_array.rb
@@ -18,6 +18,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Array. There is further documentation for validate_legacy function in the README.'])
+
unless args.length > 0 then
raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)")
end
diff --git a/lib/puppet/parser/functions/validate_bool.rb b/lib/puppet/parser/functions/validate_bool.rb
index 59a0805..4e52ffd 100644
--- a/lib/puppet/parser/functions/validate_bool.rb
+++ b/lib/puppet/parser/functions/validate_bool.rb
@@ -19,6 +19,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Bool. There is further documentation for validate_legacy function in the README.'])
+
unless args.length > 0 then
raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)")
end
diff --git a/lib/puppet/parser/functions/validate_re.rb b/lib/puppet/parser/functions/validate_re.rb
index efee7f8..6bdc858 100644
--- a/lib/puppet/parser/functions/validate_re.rb
+++ b/lib/puppet/parser/functions/validate_re.rb
@@ -29,6 +29,9 @@ module Puppet::Parser::Functions
validate_re("${::operatingsystemmajrelease}", '^[57]$')
ENDHEREDOC
+
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Re. There is further documentation for validate_legacy function in the README.'])
+
if (args.length < 2) or (args.length > 3) then
raise Puppet::ParseError, "validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)"
end
diff --git a/lib/puppet/parser/functions/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb
index c841f6a..e92a2fc 100644
--- a/lib/puppet/parser/functions/validate_string.rb
+++ b/lib/puppet/parser/functions/validate_string.rb
@@ -23,6 +23,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:puppet_3_type_check, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::String. There is further documentation for validate_legacy function in the README.'])
+
unless args.length > 0 then
raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)")
end
diff --git a/spec/aliases/absolute_path_spec.rb b/spec/aliases/absolute_path_spec.rb
new file mode 100644
index 0000000..0bcdf85
--- /dev/null
+++ b/spec/aliases/absolute_path_spec.rb
@@ -0,0 +1,62 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::absolute_path', type: :class do
+ describe 'valid paths handling' do
+ %w{
+ C:/
+ C:\\
+ C:\\WINDOWS\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\foo\\bar
+ \\\\host\\windows
+ //host/windows
+ /
+ /var/tmp
+ /var/opt/../lib/puppet
+ }.each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'invalid path handling' do
+ context 'garbage inputs' do
+ [
+ nil,
+ [ nil ],
+ [ nil, nil ],
+ { 'foo' => 'bar' },
+ { },
+ '',
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Compat::Absolute_path/) }
+ end
+ end
+ end
+
+ context 'relative paths' do
+ %w{
+ relative1
+ .
+ ..
+ ./foo
+ ../foo
+ etc/puppetlabs/puppet
+ opt/puppet/bin
+ relative\\windows
+ }.each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a match for Stdlib::Compat::Absolute_path/) }
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/array_spec.rb b/spec/aliases/array_spec.rb
new file mode 100644
index 0000000..8bbb8b3
--- /dev/null
+++ b/spec/aliases/array_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::array', type: :class do
+ describe 'accepts arrays' do
+ [
+ [],
+ ['one'],
+ [1],
+ [{}],
+ [[]],
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [
+ '',
+ 'one',
+ '1',
+ {},
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::Array/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/bool_spec.rb b/spec/aliases/bool_spec.rb
new file mode 100644
index 0000000..f664457
--- /dev/null
+++ b/spec/aliases/bool_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::bool', type: :class do
+ describe 'accepts booleans' do
+ [
+ true,
+ false,
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [
+ [1],
+ [{}],
+ [true],
+ 'true',
+ 'false',
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::Bool/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/string_spec.rb b/spec/aliases/string_spec.rb
new file mode 100644
index 0000000..8e01d55
--- /dev/null
+++ b/spec/aliases/string_spec.rb
@@ -0,0 +1,31 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'test::string', type: :class do
+ describe 'accepts strings' do
+ [
+ '',
+ 'one',
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [
+ [],
+ {},
+ 1,
+ true,
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a Stdlib::Compat::String = String/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/fixtures/modules/test/manifests/absolute_path.pp b/spec/fixtures/modules/test/manifests/absolute_path.pp
new file mode 100644
index 0000000..d77f6bd
--- /dev/null
+++ b/spec/fixtures/modules/test/manifests/absolute_path.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Absolute_path type alias
+class test::absolute_path(
+ Stdlib::Compat::Absolute_path $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/modules/test/manifests/array.pp b/spec/fixtures/modules/test/manifests/array.pp
new file mode 100644
index 0000000..84b6a5b
--- /dev/null
+++ b/spec/fixtures/modules/test/manifests/array.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::Array type alias
+class test::array(
+ Stdlib::Compat::Array $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/fixtures/modules/test/manifests/bool.pp b/spec/fixtures/modules/test/manifests/bool.pp
new file mode 100644
index 0000000..ab5b5ea
--- /dev/null
+++ b/spec/fixtures/modules/test/manifests/bool.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::Bool type alias
+class test::bool(
+ Stdlib::Compat::Bool $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/fixtures/modules/test/manifests/string.pp b/spec/fixtures/modules/test/manifests/string.pp
new file mode 100644
index 0000000..6508c70
--- /dev/null
+++ b/spec/fixtures/modules/test/manifests/string.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::String type alias
+class test::string(
+ Stdlib::Compat::String $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb
index 7dd21c2..e35ca44 100755
--- a/spec/functions/is_array_spec.rb
+++ b/spec/functions/is_array_spec.rb
@@ -2,6 +2,11 @@ require 'spec_helper'
describe 'is_array' do
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params([])
+ end
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it {
pending("Current implementation ignores parameters after the first.")
diff --git a/spec/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb
index 76d619b..9569856 100755
--- a/spec/functions/is_bool_spec.rb
+++ b/spec/functions/is_bool_spec.rb
@@ -2,6 +2,11 @@ require 'spec_helper'
describe 'is_bool' do
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(true)
+ end
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it { is_expected.to run.with_params(true, false).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it { is_expected.to run.with_params(true).and_return(true) }
diff --git a/spec/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb
index 8e459cc..8056ed4 100755
--- a/spec/functions/is_string_spec.rb
+++ b/spec/functions/is_string_spec.rb
@@ -2,6 +2,11 @@ require 'spec_helper'
describe 'is_string' do
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('ha')
+ end
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it {
pending("Current implementation ignores parameters after the first.")
diff --git a/spec/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb
index 4a8404d..ffdb2c8 100755
--- a/spec/functions/validate_absolute_path_spec.rb
+++ b/spec/functions/validate_absolute_path_spec.rb
@@ -1,6 +1,13 @@
require 'spec_helper'
describe 'validate_absolute_path' do
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ # called twice because validate_absolute_path calls is_absolute_path
+ scope.expects(:warn).with(includes('This method is deprecated')).twice
+ is_expected.to run.with_params('c:/')
+ end
+
describe 'signature validation' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
diff --git a/spec/functions/validate_array_spec.rb b/spec/functions/validate_array_spec.rb
index 4ee7754..0ba7108 100755
--- a/spec/functions/validate_array_spec.rb
+++ b/spec/functions/validate_array_spec.rb
@@ -3,6 +3,11 @@ require 'spec_helper'
describe 'validate_array' do
describe 'signature validation' do
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params([])
+ end
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
describe 'valid inputs' do
diff --git a/spec/functions/validate_bool_spec.rb b/spec/functions/validate_bool_spec.rb
index d9cdf57..b0f41a8 100755
--- a/spec/functions/validate_bool_spec.rb
+++ b/spec/functions/validate_bool_spec.rb
@@ -1,6 +1,13 @@
require 'spec_helper'
describe 'validate_bool' do
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ #called twice, because validate_bool calls is_bool
+ scope.expects(:warn).with(includes('This method is deprecated')).twice
+ is_expected.to run.with_params(true)
+ end
+
describe 'signature validation' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
diff --git a/spec/functions/validate_re_spec.rb b/spec/functions/validate_re_spec.rb
index 3f90143..f6fa931 100755
--- a/spec/functions/validate_re_spec.rb
+++ b/spec/functions/validate_re_spec.rb
@@ -1,6 +1,12 @@
require 'spec_helper'
describe 'validate_re' do
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('', '')
+ end
+
describe 'signature validation' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
diff --git a/spec/functions/validate_string_spec.rb b/spec/functions/validate_string_spec.rb
index f0c500e..9bfef66 100755
--- a/spec/functions/validate_string_spec.rb
+++ b/spec/functions/validate_string_spec.rb
@@ -1,6 +1,12 @@
require 'spec_helper'
describe 'validate_string' do
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ scope.expects(:warn).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('', '')
+ end
+
describe 'signature validation' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
diff --git a/types/compat/absolute_path.pp b/types/compat/absolute_path.pp
new file mode 100644
index 0000000..d11784e
--- /dev/null
+++ b/types/compat/absolute_path.pp
@@ -0,0 +1,7 @@
+# Emulate the is_absolute_path and validate_absolute_path functions
+#
+# The first pattern is originally from is_absolute_path, which had it from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path?
+# slash = '[\\\\/]'
+# name = '[^\\\\/]+'
+# %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i,
+type Stdlib::Compat::Absolute_path = Variant[Pattern[/^(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+))/], Pattern[/^\//]]
diff --git a/types/compat/array.pp b/types/compat/array.pp
new file mode 100644
index 0000000..ba65dc4
--- /dev/null
+++ b/types/compat/array.pp
@@ -0,0 +1,2 @@
+# Emulate the is_array and validate_array functions
+type Stdlib::Compat::Array = Array[Any]
diff --git a/types/compat/bool.pp b/types/compat/bool.pp
new file mode 100644
index 0000000..dda5f4b
--- /dev/null
+++ b/types/compat/bool.pp
@@ -0,0 +1,2 @@
+ # Emulate the is_bool and validate_bool functions
+ type Stdlib::Compat::Bool = Boolean
diff --git a/types/compat/re.pp b/types/compat/re.pp
new file mode 100644
index 0000000..e4b5f30
--- /dev/null
+++ b/types/compat/re.pp
@@ -0,0 +1,3 @@
+# Emulate the validate_re function
+# validate_re(value, re) translates to Pattern[re], which is not directly mappable as a type alias, but can be specified as Pattern[re].
+# Therefore this needs to be translated directly.
diff --git a/types/compat/string.pp b/types/compat/string.pp
new file mode 100644
index 0000000..4c36e5f
--- /dev/null
+++ b/types/compat/string.pp
@@ -0,0 +1,2 @@
+# Emulate the is_string and validate_string functions
+type Stdlib::Compat::String = String