summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.fixtures.yml1
-rw-r--r--.rubocop.yml508
-rw-r--r--.sync.yml11
-rw-r--r--.travis.yml15
-rw-r--r--CHANGELOG.md62
-rw-r--r--Gemfile58
-rw-r--r--README.markdown158
-rw-r--r--Rakefile4
-rw-r--r--lib/facter/puppet_settings.rb35
-rw-r--r--lib/facter/puppet_vardir.rb26
-rw-r--r--lib/puppet/functions/deprecation.rb4
-rw-r--r--lib/puppet/functions/is_absolute_path.rb15
-rw-r--r--lib/puppet/functions/is_array.rb15
-rw-r--r--lib/puppet/functions/is_bool.rb15
-rw-r--r--lib/puppet/functions/is_float.rb15
-rw-r--r--lib/puppet/functions/is_ip_address.rb15
-rw-r--r--lib/puppet/functions/is_ipv4_address.rb15
-rw-r--r--lib/puppet/functions/is_ipv6_address.rb15
-rw-r--r--lib/puppet/functions/is_numeric.rb15
-rw-r--r--lib/puppet/functions/is_string.rb15
-rw-r--r--lib/puppet/functions/validate_absolute_path.rb15
-rw-r--r--lib/puppet/functions/validate_array.rb15
-rw-r--r--lib/puppet/functions/validate_bool.rb15
-rw-r--r--lib/puppet/functions/validate_hash.rb15
-rw-r--r--lib/puppet/functions/validate_integer.rb15
-rw-r--r--lib/puppet/functions/validate_ip_address.rb15
-rw-r--r--lib/puppet/functions/validate_ipv4_address.rb15
-rw-r--r--lib/puppet/functions/validate_ipv6_address.rb15
-rw-r--r--lib/puppet/functions/validate_legacy.rb62
-rw-r--r--lib/puppet/functions/validate_numeric.rb15
-rw-r--r--lib/puppet/functions/validate_re.rb15
-rw-r--r--lib/puppet/functions/validate_slength.rb15
-rw-r--r--lib/puppet/functions/validate_string.rb15
-rw-r--r--lib/puppet/parser/functions/deprecation.rb17
-rw-r--r--lib/puppet/parser/functions/dig44.rb37
-rw-r--r--lib/puppet/parser/functions/ensure_resources.rb2
-rw-r--r--lib/puppet/parser/functions/getparam.rb2
-rw-r--r--lib/puppet/parser/functions/getvar.rb6
-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_float.rb2
-rw-r--r--lib/puppet/parser/functions/is_integer.rb2
-rw-r--r--lib/puppet/parser/functions/is_ip_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_ipv4_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_ipv6_address.rb2
-rw-r--r--lib/puppet/parser/functions/is_numeric.rb4
-rw-r--r--lib/puppet/parser/functions/is_string.rb5
-rw-r--r--lib/puppet/parser/functions/validate_absolute_path.rb3
-rw-r--r--lib/puppet/parser/functions/validate_array.rb2
-rw-r--r--lib/puppet/parser/functions/validate_bool.rb3
-rw-r--r--lib/puppet/parser/functions/validate_hash.rb2
-rw-r--r--lib/puppet/parser/functions/validate_integer.rb4
-rw-r--r--lib/puppet/parser/functions/validate_ip_address.rb6
-rw-r--r--lib/puppet/parser/functions/validate_ipv4_address.rb2
-rw-r--r--lib/puppet/parser/functions/validate_ipv6_address.rb2
-rw-r--r--lib/puppet/parser/functions/validate_numeric.rb4
-rw-r--r--lib/puppet/parser/functions/validate_re.rb3
-rw-r--r--lib/puppet/parser/functions/validate_slength.rb2
-rw-r--r--lib/puppet/parser/functions/validate_string.rb11
-rw-r--r--lib/puppet/provider/file_line/ruby.rb6
-rw-r--r--lib/puppet/type/file_line.rb3
-rw-r--r--metadata.json8
-rw-r--r--spec/acceptance/deprecation_spec.rb58
-rwxr-xr-xspec/acceptance/is_string_spec.rb11
-rw-r--r--spec/acceptance/nodesets/centos-7-x64.yml2
-rwxr-xr-xspec/acceptance/validate_array_spec.rb16
-rwxr-xr-xspec/acceptance/validate_bool_spec.rb16
-rwxr-xr-xspec/acceptance/validate_hash_spec.rb16
-rwxr-xr-xspec/acceptance/validate_string_spec.rb7
-rw-r--r--spec/aliases/absolute_path_spec.rb62
-rw-r--r--spec/aliases/absolutepath_spec.rb49
-rw-r--r--spec/aliases/array_spec.rb34
-rw-r--r--spec/aliases/bool_spec.rb32
-rw-r--r--spec/aliases/float_spec.rb28
-rw-r--r--spec/aliases/httpsurl_spec.rb40
-rw-r--r--spec/aliases/httpurl_spec.rb43
-rw-r--r--spec/aliases/integer_spec.rb28
-rw-r--r--spec/aliases/ip_address.rb34
-rw-r--r--spec/aliases/ipv4_spec.rb22
-rw-r--r--spec/aliases/ipv6_spec.rb30
-rw-r--r--spec/aliases/numeric_spec.rb32
-rw-r--r--spec/aliases/string_spec.rb32
-rw-r--r--spec/aliases/unixpath_spec.rb41
-rw-r--r--spec/aliases/windowspath_spec.rb44
-rw-r--r--spec/fixtures/test/manifests/absolute_path.pp6
-rw-r--r--spec/fixtures/test/manifests/absolutepath.pp6
-rw-r--r--spec/fixtures/test/manifests/array.pp8
-rw-r--r--spec/fixtures/test/manifests/bool.pp8
-rw-r--r--spec/fixtures/test/manifests/float.pp8
-rw-r--r--spec/fixtures/test/manifests/httpsurl.pp6
-rw-r--r--spec/fixtures/test/manifests/httpurl.pp6
-rw-r--r--spec/fixtures/test/manifests/integer.pp8
-rw-r--r--spec/fixtures/test/manifests/ip_address.pp6
-rw-r--r--spec/fixtures/test/manifests/ipv4.pp6
-rw-r--r--spec/fixtures/test/manifests/ipv6.pp6
-rw-r--r--spec/fixtures/test/manifests/numeric.pp8
-rw-r--r--spec/fixtures/test/manifests/string.pp8
-rw-r--r--spec/fixtures/test/manifests/unixpath.pp6
-rw-r--r--spec/fixtures/test/manifests/windowspath.pp6
-rwxr-xr-xspec/functions/assert_private_spec.rb30
-rw-r--r--spec/functions/deprecation_spec.rb22
-rw-r--r--spec/functions/dig44_spec.rb119
-rwxr-xr-xspec/functions/ensure_resource_spec.rb7
-rwxr-xr-xspec/functions/getparam_spec.rb5
-rwxr-xr-xspec/functions/getvar_spec.rb2
-rwxr-xr-xspec/functions/is_array_spec.rb17
-rwxr-xr-xspec/functions/is_bool_spec.rb18
-rwxr-xr-xspec/functions/is_float_spec.rb20
-rwxr-xr-xspec/functions/is_integer_spec.rb22
-rwxr-xr-xspec/functions/is_ip_address_spec.rb17
-rw-r--r--spec/functions/is_ipv4_address_spec.rb32
-rw-r--r--spec/functions/is_ipv6_address_spec.rb30
-rwxr-xr-xspec/functions/is_numeric_spec.rb20
-rwxr-xr-xspec/functions/is_string_spec.rb19
-rwxr-xr-xspec/functions/validate_absolute_path_spec.rb11
-rwxr-xr-xspec/functions/validate_array_spec.rb10
-rwxr-xr-xspec/functions/validate_bool_spec.rb11
-rwxr-xr-xspec/functions/validate_hash_spec.rb12
-rwxr-xr-xspec/functions/validate_integer_spec.rb11
-rw-r--r--spec/functions/validate_ip_address_spec.rb19
-rwxr-xr-xspec/functions/validate_ipv4_address_spec.rb57
-rwxr-xr-xspec/functions/validate_ipv6_address_spec.rb58
-rw-r--r--spec/functions/validate_legacy_spec.rb68
-rwxr-xr-xspec/functions/validate_numeric_spec.rb11
-rwxr-xr-xspec/functions/validate_re_spec.rb27
-rwxr-xr-xspec/functions/validate_slength_spec.rb11
-rwxr-xr-xspec/functions/validate_string_spec.rb12
-rw-r--r--spec/spec_helper_local.rb2
-rw-r--r--spec/support/shared_data.rb38
-rwxr-xr-xspec/unit/puppet/provider/file_line/ruby_spec.rb7
-rw-r--r--types/absolutepath.pp2
-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/float.pp19
-rw-r--r--types/compat/integer.pp23
-rw-r--r--types/compat/ip_address.pp1
-rw-r--r--types/compat/ipv4.pp2
-rw-r--r--types/compat/ipv6.pp1
-rw-r--r--types/compat/numeric.pp23
-rw-r--r--types/compat/re.pp3
-rw-r--r--types/compat/string.pp2
-rw-r--r--types/httpsurl.pp1
-rw-r--r--types/httpurl.pp1
-rw-r--r--types/unixpath.pp2
-rw-r--r--types/windowspath.pp1
147 files changed, 2748 insertions, 283 deletions
diff --git a/.fixtures.yml b/.fixtures.yml
index 37b7377..a28e653 100644
--- a/.fixtures.yml
+++ b/.fixtures.yml
@@ -1,3 +1,4 @@
fixtures:
symlinks:
stdlib: "#{source_dir}"
+ test: "#{source_dir}/spec/fixtures/test"
diff --git a/.rubocop.yml b/.rubocop.yml
new file mode 100644
index 0000000..5aadd1b
--- /dev/null
+++ b/.rubocop.yml
@@ -0,0 +1,508 @@
+require: rubocop-rspec
+AllCops:
+ TargetRubyVersion: 1.9
+ Include:
+ - ./**/*.rb
+ Exclude:
+ - vendor/**/*
+ - .vendor/**/*
+ - pkg/**/*
+ - spec/fixtures/**/*
+Lint/ConditionPosition:
+ Enabled: True
+
+Lint/ElseLayout:
+ Enabled: True
+
+Lint/UnreachableCode:
+ Enabled: True
+
+Lint/UselessComparison:
+ Enabled: True
+
+Lint/EnsureReturn:
+ Enabled: True
+
+Lint/HandleExceptions:
+ Enabled: True
+
+Lint/LiteralInCondition:
+ Enabled: True
+
+Lint/ShadowingOuterLocalVariable:
+ Enabled: True
+
+Lint/LiteralInInterpolation:
+ Enabled: True
+
+Style/HashSyntax:
+ Enabled: True
+
+Style/RedundantReturn:
+ Enabled: True
+
+Lint/AmbiguousOperator:
+ Enabled: True
+
+Lint/AssignmentInCondition:
+ Enabled: True
+
+Style/SpaceBeforeComment:
+ Enabled: True
+
+Style/AndOr:
+ Enabled: True
+
+Style/RedundantSelf:
+ Enabled: True
+
+# Method length is not necessarily an indicator of code quality
+Metrics/MethodLength:
+ Enabled: False
+
+# Module length is not necessarily an indicator of code quality
+Metrics/ModuleLength:
+ Enabled: False
+
+Style/WhileUntilModifier:
+ Enabled: True
+
+Lint/AmbiguousRegexpLiteral:
+ Enabled: True
+
+Lint/Eval:
+ Enabled: True
+
+Lint/BlockAlignment:
+ Enabled: True
+
+Lint/DefEndAlignment:
+ Enabled: True
+
+Lint/EndAlignment:
+ Enabled: True
+
+Lint/DeprecatedClassMethods:
+ Enabled: True
+
+Lint/Loop:
+ Enabled: True
+
+Lint/ParenthesesAsGroupedExpression:
+ Enabled: True
+
+Lint/RescueException:
+ Enabled: True
+
+Lint/StringConversionInInterpolation:
+ Enabled: True
+
+Lint/UnusedBlockArgument:
+ Enabled: True
+
+Lint/UnusedMethodArgument:
+ Enabled: True
+
+Lint/UselessAccessModifier:
+ Enabled: True
+
+Lint/UselessAssignment:
+ Enabled: True
+
+Lint/Void:
+ Enabled: True
+
+Style/AccessModifierIndentation:
+ Enabled: True
+
+Style/AccessorMethodName:
+ Enabled: True
+
+Style/Alias:
+ Enabled: True
+
+Style/AlignArray:
+ Enabled: True
+
+Style/AlignHash:
+ Enabled: True
+
+Style/AlignParameters:
+ Enabled: True
+
+Metrics/BlockNesting:
+ Enabled: True
+
+Style/AsciiComments:
+ Enabled: True
+
+Style/Attr:
+ Enabled: True
+
+Style/BracesAroundHashParameters:
+ Enabled: True
+
+Style/CaseEquality:
+ Enabled: True
+
+Style/CaseIndentation:
+ Enabled: True
+
+Style/CharacterLiteral:
+ Enabled: True
+
+Style/ClassAndModuleCamelCase:
+ Enabled: True
+
+Style/ClassAndModuleChildren:
+ Enabled: False
+
+Style/ClassCheck:
+ Enabled: True
+
+# Class length is not necessarily an indicator of code quality
+Metrics/ClassLength:
+ Enabled: False
+
+Style/ClassMethods:
+ Enabled: True
+
+Style/ClassVars:
+ Enabled: True
+
+Style/WhenThen:
+ Enabled: True
+
+Style/WordArray:
+ Enabled: True
+
+Style/UnneededPercentQ:
+ Enabled: True
+
+Style/Tab:
+ Enabled: True
+
+Style/SpaceBeforeSemicolon:
+ Enabled: True
+
+Style/TrailingBlankLines:
+ Enabled: True
+
+Style/SpaceInsideBlockBraces:
+ Enabled: True
+
+Style/SpaceInsideBrackets:
+ Enabled: True
+
+Style/SpaceInsideHashLiteralBraces:
+ Enabled: True
+
+Style/SpaceInsideParens:
+ Enabled: True
+
+Style/LeadingCommentSpace:
+ Enabled: True
+
+Style/SpaceBeforeFirstArg:
+ Enabled: True
+
+Style/SpaceAfterColon:
+ Enabled: True
+
+Style/SpaceAfterComma:
+ Enabled: True
+
+Style/SpaceAfterMethodName:
+ Enabled: True
+
+Style/SpaceAfterNot:
+ Enabled: True
+
+Style/SpaceAfterSemicolon:
+ Enabled: True
+
+Style/SpaceAroundEqualsInParameterDefault:
+ Enabled: True
+
+Style/SpaceAroundOperators:
+ Enabled: True
+
+Style/SpaceBeforeBlockBraces:
+ Enabled: True
+
+Style/SpaceBeforeComma:
+ Enabled: True
+
+Style/CollectionMethods:
+ Enabled: True
+
+Style/CommentIndentation:
+ Enabled: True
+
+Style/ColonMethodCall:
+ Enabled: True
+
+Style/CommentAnnotation:
+ Enabled: True
+
+# 'Complexity' is very relative
+Metrics/CyclomaticComplexity:
+ Enabled: False
+
+Style/ConstantName:
+ Enabled: True
+
+Style/Documentation:
+ Enabled: False
+
+Style/DefWithParentheses:
+ Enabled: True
+
+Style/PreferredHashMethods:
+ Enabled: True
+
+Style/DotPosition:
+ EnforcedStyle: trailing
+
+Style/DoubleNegation:
+ Enabled: True
+
+Style/EachWithObject:
+ Enabled: True
+
+Style/EmptyLineBetweenDefs:
+ Enabled: True
+
+Style/IndentArray:
+ Enabled: True
+
+Style/IndentHash:
+ Enabled: True
+
+Style/IndentationConsistency:
+ Enabled: True
+
+Style/IndentationWidth:
+ Enabled: True
+
+Style/EmptyLines:
+ Enabled: True
+
+Style/EmptyLinesAroundAccessModifier:
+ Enabled: True
+
+Style/EmptyLiteral:
+ Enabled: True
+
+# Configuration parameters: AllowURI, URISchemes.
+Metrics/LineLength:
+ Enabled: False
+
+Style/MethodCallParentheses:
+ Enabled: True
+
+Style/MethodDefParentheses:
+ Enabled: True
+
+Style/LineEndConcatenation:
+ Enabled: True
+
+Style/TrailingWhitespace:
+ Enabled: True
+
+Style/StringLiterals:
+ Enabled: True
+
+Style/TrailingCommaInArguments:
+ Enabled: True
+
+Style/TrailingCommaInLiteral:
+ Enabled: True
+
+Style/GlobalVars:
+ Enabled: True
+
+Style/GuardClause:
+ Enabled: True
+
+Style/IfUnlessModifier:
+ Enabled: True
+
+Style/MultilineIfThen:
+ Enabled: True
+
+Style/NegatedIf:
+ Enabled: True
+
+Style/NegatedWhile:
+ Enabled: True
+
+Style/Next:
+ Enabled: True
+
+Style/SingleLineBlockParams:
+ Enabled: True
+
+Style/SingleLineMethods:
+ Enabled: True
+
+Style/SpecialGlobalVars:
+ Enabled: True
+
+Style/TrivialAccessors:
+ Enabled: True
+
+Style/UnlessElse:
+ Enabled: True
+
+Style/VariableInterpolation:
+ Enabled: True
+
+Style/VariableName:
+ Enabled: True
+
+Style/WhileUntilDo:
+ Enabled: True
+
+Style/EvenOdd:
+ Enabled: True
+
+Style/FileName:
+ Enabled: True
+
+Style/For:
+ Enabled: True
+
+Style/Lambda:
+ Enabled: True
+
+Style/MethodName:
+ Enabled: True
+
+Style/MultilineTernaryOperator:
+ Enabled: True
+
+Style/NestedTernaryOperator:
+ Enabled: True
+
+Style/NilComparison:
+ Enabled: True
+
+Style/FormatString:
+ Enabled: True
+
+Style/MultilineBlockChain:
+ Enabled: True
+
+Style/Semicolon:
+ Enabled: True
+
+Style/SignalException:
+ Enabled: True
+
+Style/NonNilCheck:
+ Enabled: True
+
+Style/Not:
+ Enabled: True
+
+Style/NumericLiterals:
+ Enabled: True
+
+Style/OneLineConditional:
+ Enabled: True
+
+Style/OpMethod:
+ Enabled: True
+
+Style/ParenthesesAroundCondition:
+ Enabled: True
+
+Style/PercentLiteralDelimiters:
+ Enabled: True
+
+Style/PerlBackrefs:
+ Enabled: True
+
+Style/PredicateName:
+ Enabled: True
+
+Style/RedundantException:
+ Enabled: True
+
+Style/SelfAssignment:
+ Enabled: True
+
+Style/Proc:
+ Enabled: True
+
+Style/RaiseArgs:
+ Enabled: True
+
+Style/RedundantBegin:
+ Enabled: True
+
+Style/RescueModifier:
+ Enabled: True
+
+# based on https://github.com/voxpupuli/modulesync_config/issues/168
+Style/RegexpLiteral:
+ EnforcedStyle: percent_r
+ Enabled: True
+
+Lint/UnderscorePrefixedVariableName:
+ Enabled: True
+
+Metrics/ParameterLists:
+ Enabled: False
+
+Lint/RequireParentheses:
+ Enabled: True
+
+Style/SpaceBeforeFirstArg:
+ Enabled: True
+
+Style/ModuleFunction:
+ Enabled: True
+
+Lint/Debugger:
+ Enabled: True
+
+Style/IfWithSemicolon:
+ Enabled: True
+
+Style/Encoding:
+ Enabled: True
+
+Style/BlockDelimiters:
+ Enabled: True
+
+Style/MultilineBlockLayout:
+ Enabled: True
+
+# 'Complexity' is very relative
+Metrics/AbcSize:
+ Enabled: False
+
+# 'Complexity' is very relative
+Metrics/PerceivedComplexity:
+ Enabled: False
+
+Lint/UselessAssignment:
+ Enabled: True
+
+Style/ClosingParenthesisIndentation:
+ Enabled: False
+
+# RSpec
+
+# We don't use rspec in this way
+RSpec/DescribeClass:
+ Enabled: False
+
+# Example length is not necessarily an indicator of code quality
+RSpec/ExampleLength:
+ Enabled: False
+
+RSpec/NamedSubject:
+ Enabled: False
diff --git a/.sync.yml b/.sync.yml
index 431b9d1..34cfb5f 100644
--- a/.sync.yml
+++ b/.sync.yml
@@ -5,3 +5,14 @@
- 'spec/fixtures/manifests/site.pp'
- 'spec/fixtures/modules/*'
+spec/spec_helper.rb:
+ allow_deprecations: true
+
+.travis.yml:
+ extras:
+   - rvm: 2.1.9
+     env: PUPPET_GEM_VERSION="~> 4.6.0"
+     bundler_args: --without system_tests
+   - rvm: 2.1.9
+     env: PUPPET_GEM_VERSION="~> 4.7.0"
+     bundler_args: --without system_tests
diff --git a/.travis.yml b/.travis.yml
index f631db0..0cde21d 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,21 +7,24 @@ script: "bundle exec rake validate lint spec"
matrix:
fast_finish: true
include:
- - rvm: 2.1.6
+ - rvm: 2.3.1
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/ubuntu-14.04
script: bundle exec rake beaker
services: docker
sudo: required
- - rvm: 2.1.6
+ - rvm: 2.3.1
dist: trusty
env: PUPPET_INSTALL_TYPE=agent BEAKER_debug=true BEAKER_set=docker/centos-7
script: bundle exec rake beaker
services: docker
sudo: required
+ - rvm: 2.3.1
+ bundler_args: --without system_tests
+ env: PUPPET_GEM_VERSION="~> 4.0"
- rvm: 2.1.9
bundler_args: --without system_tests
- env: PUPPET_GEM_VERSION="~> 4.0" STRICT_VARIABLES="yes"
+ env: PUPPET_GEM_VERSION="~> 4.0"
- rvm: 2.1.5
bundler_args: --without system_tests
env: PUPPET_GEM_VERSION="~> 3.0" FUTURE_PARSER="yes"
@@ -31,5 +34,11 @@ matrix:
- rvm: 1.9.3
bundler_args: --without system_tests
env: PUPPET_GEM_VERSION="~> 3.0"
+ - rvm: 2.1.9
+ bundler_args: --without system_tests
+ env: PUPPET_GEM_VERSION="~> 4.6.0"
+ - rvm: 2.1.9
+ bundler_args: --without system_tests
+ env: PUPPET_GEM_VERSION="~> 4.7.0"
notifications:
email: false
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2bc584b..9157b2d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,65 @@
+## Supported Release 4.13.1
+### Summary
+
+This bugfix release addresses the `undefined method 'optional_repeated_param'` error messages seen by users of puppet 3.7.
+
+It also improves the user experience around function deprecations by emitting one warning per function(-name) instead of only one deprecation overall. This allows users to identify all deprecated functions used in one agent run, with less back-and-forth.
+
+#### Bugfixes
+
+* Emit deprecations warnings for each function, instead of once per process. (MODULES-3961)
+* Use a universally available API for the v4 deprecation stubs of `is_*` and `validate_*`. (MODULES-3962)
+* Make `getvar()` compatible to ruby 1.8.7. (MODULES-3969)
+* Add v4 deprecation stubs for the `is_` counterparts of the deprecated functions to emit the deprecations warnings in all cases.
+
+
+## Supported Release 4.13.0
+### Summary
+
+This version of stdlib deprecates a whole host of functions, and provides stepping stones to move to Puppet 4 type validations. Be sure to check out the new `deprecation()` and `validate_legacy()` functions to migrate off the deprecated v3-style data validations.
+
+Many thanks to all community contributors: bob, Dmitry Ilyin, Dominic Cleal, Joris, Joseph Yaworski, Loic Antoine-Gombeaud, Maksym Melnychok, Michiel Brandenburg, Nate Potter, Romain Tartière, Stephen Benjamin, and Steve Moore, as well as anyone contributing in the code review process and by submitting issues.
+
+Special thanks to [Voxpupuli's](https://voxpupuli.org/) Igor Galić for donating the puppet-tea types to kickstart this part of stdlib.
+
+
+#### Deprecations
+* `validate_absolute_path`, `validate_array`, `validate_bool`, `validate_hash`, `validate_integer`, `validate_ip_address`, `validate_ipv4_address`, `validate_ipv6_address`, `validate_numeric`, `validate_re`, `validate_slength`, `validate_string`, and their `is_` counter parts are now deprecated on Puppet 4. See the `validate_legacy()` description in the README for help on migrating away from those functions.
+* The `dig` function is provided by core puppet since 4.5.0 with slightly different calling convention. The stdlib version can still be accessed as `dig44` for now.
+
+
+#### Features
+* Add Puppet 4 data types for Unix, and Windows paths, and URLs.
+* Add `deprecation` function to warn users of functionality that will be removed soon.
+* Add `validate_legacy` function to help with migrating to Puppet 4 data types.
+
+* Add `any2bool` function, a combination of of `string2bool` and `num2bool`.
+* Add `delete_regex` function to delete array elements matching a regular expression.
+* Add `puppet_environmentpath` fact to expose the `environmentpath` setting.
+* Add `regexpescape` function to safely insert arbitrary strings into regular expressions.
+* Add `shell_escape`, `shell_join`, and `shell_split` functions for safer working with shell scripts..
+
+* The `delete` function now also accepts regular expressions as search term.
+* The `loadyaml` function now accepts a default value, which is returned when there is an error loading the file.
+
+#### Bugfixes
+* Fix `file_line.match_for_absence` implementation and description to actually work. (MODULES-3590)
+* Fix `getparam` so that it can now also return `false`. (MODULES-3933)
+* Fix the fixture setup for testing and adjust `load_module_metadata` and `loadjson` tests.
+* Fix `defined_with_params` to handle `undef` correctly on all puppet versions. (PUP-6422, MODULES-3543)
+* Fix `file_line.path` validation to use puppet's built in `absolute_path?` matcher.
+
+#### Minor Improvements
+* README changes: improved descriptions of `deep_merge`, `delete`, `ensure_packages`, `file_line.after`, `range`, and `validate_numeric`.
+* The `getvar` function now returns nil in all situations where the variable is not found.
+* Update the `dig44` function with better `undef`, `nil`, and `false` handling.
+* Better wording on `str2bool` argument validation error message.
+
+
+### Known issues
+* The `validate_legacy` function relies on internal APIs from Puppet 4.4.0 (PE 2016.1) onwards, and doesn't work on earlier versions.
+* Puppet 4.5.0 (PE 2016.2) has a number of improvements around data types - especially error handling - that make working with them much nicer.
+
## Supported Release 4.12.0
###Summary
diff --git a/Gemfile b/Gemfile
index c7da908..c8af871 100644
--- a/Gemfile
+++ b/Gemfile
@@ -2,39 +2,49 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"
-def location_for(place, version = nil)
- if place =~ /^(git[:@][^#]*)#(.*)/
- [version, { :git => $1, :branch => $2, :require => false}].compact
- elsif place =~ /^file:\/\/(.*)/
- ['>= 0', { :path => File.expand_path($1), :require => false}]
+def location_from_env(env, default_location = [])
+ if location = ENV[env]
+ if location =~ /^((?:git|https?)[:@][^#]*)#(.*)/
+ [{ :git => $1, :branch => $2, :require => false }]
+ elsif location =~ /^file:\/\/(.*)/
+ ['>= 0', { :path => File.expand_path($1), :require => false }]
+ else
+ [location, { :require => false }]
+ end
else
- [place, version, { :require => false}].compact
+ default_location
end
end
group :development, :unit_tests do
- gem 'metadata-json-lint', :require => false
- gem 'puppet_facts', :require => false
- gem 'puppet-blacksmith', '>= 3.4.0', :require => false
- gem 'puppetlabs_spec_helper', :require => false
- gem 'rspec-puppet', '>= 2.3.2', :require => false
- gem 'simplecov', :require => false
+ gem 'metadata-json-lint'
+ gem 'puppet_facts'
+ gem 'puppet-blacksmith', '>= 3.4.0'
+ gem 'puppetlabs_spec_helper', '>= 1.2.1'
+ gem 'rspec-puppet', '>= 2.3.2', :git => 'https://github.com/rodjek/rspec-puppet.git', :branch => 'fb27c533e2664057fba4b73d0bd902a946abfce0'
+ # the newly released mocha 1.2.0 causes hangs during spec testing. See MODULES-3958 for a long-term solution
+ gem 'mocha', '< 1.2.0'
+ gem 'rspec-puppet-facts'
+ gem 'simplecov'
+ gem 'parallel_tests', '< 2.10.0' if RUBY_VERSION < '2.0.0'
+ gem 'parallel_tests' if RUBY_VERSION >= '2.0.0'
+ gem 'rubocop', '0.41.2' if RUBY_VERSION < '2.0.0'
+ gem 'rubocop' if RUBY_VERSION >= '2.0.0'
+ gem 'rubocop-rspec', '~> 1.6' if RUBY_VERSION >= '2.3.0'
+ gem 'json_pure', '<= 2.0.1' if RUBY_VERSION < '2.0.0'
end
group :system_tests do
- gem 'beaker-rspec', *location_for(ENV['BEAKER_RSPEC_VERSION'] || '>= 3.4')
- gem 'beaker', *location_for(ENV['BEAKER_VERSION'])
- gem 'serverspec', :require => false
- gem 'beaker-puppet_install_helper', :require => false
- gem 'master_manipulator', :require => false
- gem 'beaker-hostgenerator', *location_for(ENV['BEAKER_HOSTGENERATOR_VERSION'])
+ gem 'beaker', *location_from_env('BEAKER_VERSION', []) if RUBY_VERSION >= '2.3.0'
+ gem 'beaker', *location_from_env('BEAKER_VERSION', ['< 3']) if RUBY_VERSION < '2.3.0'
+ gem 'beaker-rspec', *location_from_env('BEAKER_RSPEC_VERSION', ['>= 3.4'])
+ gem 'serverspec'
+ gem 'beaker-puppet_install_helper'
+ gem 'master_manipulator'
+ gem 'beaker-hostgenerator', *location_from_env('BEAKER_HOSTGENERATOR_VERSION', [])
end
-# json_pure 2.0.2 added a requirement on ruby >= 2. We pin to json_pure 2.0.1
-# if using ruby 1.x
-gem 'json_pure', '<=2.0.1', :require => false if RUBY_VERSION =~ /^1\./
-
-gem 'facter', *location_for(ENV['FACTER_GEM_VERSION'])
-gem 'puppet', *location_for(ENV['PUPPET_GEM_VERSION'])
+gem 'facter', *location_from_env('FACTER_GEM_VERSION')
+gem 'puppet', *location_from_env('PUPPET_GEM_VERSION')
if File.exists? "#{__FILE__}.local"
eval(File.read("#{__FILE__}.local"), binding)
diff --git a/README.markdown b/README.markdown
index 90addee..cc29af9 100644
--- a/README.markdown
+++ b/README.markdown
@@ -1,6 +1,6 @@
-#stdlib
+# stdlib
-####Table of Contents
+#### Table of Contents
1. [Overview](#overview)
2. [Module Description - What the module does and why it is useful](#module-description)
@@ -10,11 +10,11 @@
5. [Limitations - OS compatibility, etc.](#limitations)
6. [Development - Guide for contributing to the module](#development)
-##Overview
+## Overview
Adds a standard library of resources for Puppet modules.
-##Module Description
+## Module Description
This module provides a standard library of resources for the development of Puppet modules. Puppet modules make heavy use of this standard library. The stdlib module adds the following resources to Puppet:
@@ -22,16 +22,16 @@ This module provides a standard library of resources for the development of Pupp
* Facts
* Functions
* Defined resource types
- * Types
+ * Data Types
* Providers
> *Note:* As of version 3.7, Puppet Enterprise no longer includes the stdlib module. If you're running Puppet Enterprise, you should install the most recent release of stdlib for compatibility with Puppet modules.
-##Setup
+## Setup
Installing the stdlib module adds the functions, facts, and resources of this standard library to Puppet.
-##Usage
+## Usage
After you've installed stdlib, all of its functions, facts, and resources are available for module use or development.
@@ -73,7 +73,7 @@ The `stdlib::stages` class declares various run stages for deploying infrastruct
* `stdlib::stages`: Manages a standard set of run stages for Puppet. It is managed by the stdlib class and should not be declared independently.
-### Types
+### Resource Types
#### `file_line`
@@ -124,16 +124,59 @@ error will be raised unless the `multiple => true` parameter is set.
All parameters are optional, unless otherwise noted.
-* `after`: Specifies the line after which Puppet adds any new lines. (Existing lines are added in place.) Valid options: String. Default: Undefined.
+* `after`: Specifies the line after which Puppet adds any new lines using a regular expression. (Existing lines are added in place.) Valid options: String containing a regex. Default: Undefined.
* `ensure`: Ensures whether the resource is present. Valid options: 'present', 'absent'. Default: 'present'.
* `line`: **Required.** Sets the line to be added to the file located by the `path` parameter. Valid options: String. Default: Undefined.
* `match`: Specifies a regular expression to run against existing lines in the file; if a match is found, it is replaced rather than adding a new line. A regex comparison is performed against the line value, and if it does not match, an exception is raised. Valid options: String containing a regex. Default: Undefined.
-* `match_for_absence`: An optional value to determine if match should be applied when `ensure => absent`. If set to true and match is set, the line that matches match will be deleted. If set to false (the default), match is ignored when `ensure => absent` and the value of `line` is used instead. Default: false.
+* `match_for_absence`: An optional value to determine if match should be applied when `ensure => absent`. If set to true and match is set, the line that matches match will be deleted. If set to false (the default), match is ignored when `ensure => absent` and the value of `line` is used instead. Ignored when `ensure => present`. Default: false.
* `multiple`: Determines if `match` and/or `after` can change multiple lines. If set to false, an exception will be raised if more than one line matches. Valid options: 'true', 'false'. Default: Undefined.
* `name`: Sets the name to use as the identity of the resource. This is necessary if you want the resource namevar to differ from the supplied `title` of the resource. Valid options: String. Default: Undefined.
* `path`: **Required.** Defines the file in which Puppet will ensure the line specified by `line`. Must be an absolute path to the file.
* `replace`: Defines whether the resource will overwrite an existing line that matches the `match` parameter. If set to false and a line is found matching the `match` param, the line will not be placed in the file. Valid options: true, false, yes, no. Default: true
+### Data Types
+
+#### `Stdlib::Absolutepath`
+
+A strict absolute path type. Uses a Variant of Unixpath and Windowspath types.
+
+Acceptable input examples: /var/log
+ /usr2/username/bin:/usr/local/bin:/usr/bin:.
+ C:\\WINDOWS\\System32
+Unacceptable input example: ../relative_path
+
+#### `Stdlib::Httpsurl`
+
+Matches https URLs.
+
+Acceptable input example: https://hello.com
+Unacceptable input example: httds://notquiteright.org
+
+#### `Stdlib::Httpurl`
+
+Matches both https and http URLs.
+
+Acceptable input example: https://hello.com
+ http://hello.com
+Unacceptable input example: httds://notquiteright.org
+
+#### `Stdlib::Unixpath`
+
+Matches paths on Unix type Operating Systems.
+
+Acceptable input example: /usr2/username/bin:/usr/local/bin:/usr/bin:.
+ /var/tmp
+Unacceptable input example: C:/whatever
+
+#### `Stdlib::Windowspath`
+
+Matches paths on Windows Operating systems.
+
+Acceptable input example: C:\\WINDOWS\\System32
+ C:\\
+ \\\\host\\windows
+Unacceptable input example: /usr2/username/bin:/usr/local/bin:/usr/bin:.
+
### Functions
#### `abs`
@@ -304,7 +347,20 @@ Deletes all instances of the undef value from an array or hash. For example, `$h
#### `deprecation`
-Function to print deprecation warnings, Logs a warning once for a given key. The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method It is affected by the puppet setting 'strict', which can be set to :error (outputs as an error message), :off (no message / error is displayed) and :warning (default, outputs a warning) *Type*: String, String.
+Prints deprecation warnings and logs a warning once for a given key:
+
+```
+deprecation(key, message)
+```
+
+* key: to keep the number of messages low, during the lifetime of a puppet process, only one message per key is logged.
+* message: the text to be logged.
+
+The Puppet settings '[disable_warnings](https://docs.puppet.com/puppet/latest/reference/configuration.html#disablewarnings)', '[max_deprecations](https://docs.puppet.com/puppet/latest/reference/configuration.html#maxdeprecations)', and '[strict](https://docs.puppet.com/puppet/latest/reference/configuration.html#strict)' affect this function. Set 'strict' to `error` to fail immediately with the deprecation message, `off` to output emit no messages at all, or `warning` (default) to log all warnings.
+
+Additionally you can set the environment variable `STDLIB_LOG_DEPRECATIONS` to decide whether or not to log deprecation warnings: if this environment variable is set to `true`, the functions log a warning, if it is set to `false`, no warnings are logged. If no value is set at all, Puppet 4 will emit warnings, while Puppet 3 will not. Using this setting is especially useful for automated tests to avoid flooding your logs before you are ready to migrate.
+
+*Type*: String, String.
#### `difference`
@@ -1370,9 +1426,85 @@ The following values will fail, causing compilation to abort:
~~~
+#### `validate_legacy`
+
+Validates a value against both a specified type and a deprecated validation function. Silently passes if both pass, errors if only one validation passes, and fails if both validations return false.
+
+Accepts arguments for:
+* the type to check the value against,
+* the full name of the previous validation function,
+* the value to be checked,
+* an unspecified number of arguments needed for the previous validation function.
+
+Example:
+
+```
+validate_legacy("Optional[String]", "validate_re", "Value to be validated", ["."])
+```
+
+This function supports updating modules from Puppet 3 style argument validation (using the stdlib `validate_*` functions) to Puppet 4 data types, without breaking functionality for those depending on Puppet 3 style validation.
+
+> Note: This function relies on internal APIs from Puppet 4.4.0 (PE 2016.1) onwards, and doesn't work on earlier versions.
+
+##### For module users
+
+If you are running Puppet 4 and receiving deprecation warnings about `validate_*` functions, the `validate_legacy` function can help you find and resolve the deprecated code.
+
+In Puppet 3, the `validate_*` functions were the only way to easily check the types of class and defined type arguments. Some of the functions provided additional helpers like [validate_numeric](#validate_numeric), which unintentionally allowed not only numbers, but also arrays of numbers. Puppet 4 allows much better defined type checking using [data types](https://docs.puppet.com/puppet/latest/reference/lang_data.html), without such unintentional effects. The `validate_legacy` function makes these differences visible and makes it easier to move to the clearer Puppet 4 syntax.
+
+Depending on the current state of development of the modules you use and the data you feed those modules, you'll encounter different messages:
+
+* `Notice: Accepting previously invalid value for target type '<type>'`: This message is informational only. You're using values that are allowed by the new type, but would have been invalid by the old validation function.
+* `Warning: This method is deprecated, please use the stdlib validate_legacy function`: The module has not yet upgraded to `validate_legacy`. Use the [deprecation](#deprecation) options to silence warnings for now, or submit a fix with the module's developer. See the information [for module developers](#for-module-developers) below for how to fix the issue.
+* `Warning: validate_legacy(<function>) expected <type> value, got <actual type>_`: Your code passes a value that was accepted by the Puppet 3 style validation, but will not be accepted by the next version of the module. Most often, you can fix this by removing quotes from numbers or booleans.
+* `Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, validate_legacy(<function>) expected <type> value, got <actual type>`: Your code passes a value that is not acceptable to either the new or the old style validation.
+
+##### For module developers
+
+Many `validate_*` functions have surprising holes in their validation. For example, [validate_numeric](#validate_numeric) allows not only numbers, but also arrays of numbers or strings that look like numbers, without giving you any control over the specifics. In contrast, Puppet 4 [data types](https://docs.puppet.com/puppet/latest/reference/lang_data.html) allows you to choose between `Numeric`, `Array[Numeric]`, or `Optional[Numeric]`. The `validate_legacy` function helps you move from Puppet 3 style validation to Puppet 4 validation without breaking functionality your module's users depend on.
+
+For each parameter of your classes and defined types, choose a new Puppet 4 data type to use. In most cases, the new data type allows a different set of values than the original `validate_*` function. The situation then looks like this:
+
+| | `validate_` pass | `validate_` fail |
+| ------------ | ---------------- | ---------------- |
+| matches type | pass | pass, notice |
+| fails type | pass, deprecated | fail |
+
+The code after the validation still has to handle all possible values for now, but users of your code can change their manifests to pass only values that match the new type.
+
+For each `validate_*` function in stdlib, there is a matching `Stdlib::Compat::*` type that allows the appropriate set of values. See the documentation in the `types/` directory in the stdlib source code for caveats.
+
+For example, given a class that should accept only numbers, like this:
+
+~~~
+class example($value) {
+ validate_numeric($value)
+~~~
+
+the resulting validation code looks like this:
+
+~~~
+class example(
+ Variant[Stdlib::Compat::Numeric, Numeric] $value
+) {
+ validate_legacy(Numeric, 'validate_numeric', $value)
+~~~
+
+Here, the type of `$value` is defined as `Variant[Stdlib::Compat::Numeric, Numeric]`, which allows any `Numeric` (the new type), as well as all values previously accepted by `validate_numeric` (through `Stdlib::Compat::Numeric`).
+
+The call to `validate_legacy` takes care of triggering the correct log or fail message for you. It requires the new type, the previous validation function name, and all arguments to that function.
+
+If your module still supported Puppet 3, this is a breaking change. Update your `metadata.json` requirements section to indicate that your module no longer supports Puppet 3, and bump the major version of your module. With this change, all existing tests for your module should still pass. Create additional tests for the new possible values.
+
+As a breaking change, this is also a good time to call [`deprecation`](#deprecation) for any parameters you want to get rid of, or to add additional constraints on your parameters.
+
+After releasing this version, you can release another breaking change release where you remove all compat types and all calls to `validate_legacy`. At that time, you can also go through your code and remove any leftovers dealing with the previously possible values.
+
+Always note such changes in your CHANGELOG and README.
+
#### `validate_numeric`
-Validates that the first argument is a numeric value (or an array of numeric values). Aborts catalog compilation if any of the checks fail.
+Validates that the first argument is a numeric value (or an array or string of numeric values). Aborts catalog compilation if any of the checks fail.
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
@@ -1531,7 +1663,7 @@ Versions | Puppet 2.6 | Puppet 2.7 | Puppet 3.x | Puppet 4.x |
Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad hardware, software, and deployment configurations that Puppet is intended to serve. We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. For more information, see our [module contribution guide](https://docs.puppetlabs.com/forge/contributing.html).
To report or research a bug with any part of this module, please go to
-[http://tickets.puppetlabs.com/browse/PUP](http://tickets.puppetlabs.com/browse/PUP).
+[http://tickets.puppetlabs.com/browse/MODULES](http://tickets.puppetlabs.com/browse/MODULES).
## Contributors
diff --git a/Rakefile b/Rakefile
index 8906d23..3e8d4cb 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,13 +2,9 @@ require 'puppet_blacksmith/rake_tasks'
require 'puppet-lint/tasks/puppet-lint'
require 'puppetlabs_spec_helper/rake_tasks'
-PuppetLint.configuration.fail_on_warnings = true
PuppetLint.configuration.send('relative')
-PuppetLint.configuration.send('disable_140chars')
-PuppetLint.configuration.send('disable_class_inherits_from_params_class')
PuppetLint.configuration.send('disable_documentation')
PuppetLint.configuration.send('disable_single_quote_string_with_variables')
-PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp", "bundle/**/*", "vendor/**/*"]
desc 'Generate pooler nodesets'
task :gen_nodeset do
diff --git a/lib/facter/puppet_settings.rb b/lib/facter/puppet_settings.rb
new file mode 100644
index 0000000..e6a066a
--- /dev/null
+++ b/lib/facter/puppet_settings.rb
@@ -0,0 +1,35 @@
+# These facter facts return the value of the Puppet vardir and environment path
+# settings for the node running puppet or puppet agent. The intent is to
+# enable Puppet modules to automatically have insight into a place where they
+# can place variable data, or for modules running on the puppet master to know
+# where environments are stored.
+#
+# The values should be directly usable in a File resource path attribute.
+#
+begin
+ require 'facter/util/puppet_settings'
+rescue LoadError => e
+ # puppet apply does not add module lib directories to the $LOAD_PATH (See
+ # #4248). It should (in the future) but for the time being we need to be
+ # defensive which is what this rescue block is doing.
+ rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
+ load rb_file if File.exists?(rb_file) or raise e
+end
+
+
+# These will be nil if Puppet is not available.
+Facter.add(:puppet_vardir) do
+ setcode do
+ Facter::Util::PuppetSettings.with_puppet do
+ Puppet[:vardir]
+ end
+ end
+end
+
+Facter.add(:puppet_environmentpath) do
+ setcode do
+ Facter::Util::PuppetSettings.with_puppet do
+ Puppet[:environmentpath]
+ end
+ end
+end
diff --git a/lib/facter/puppet_vardir.rb b/lib/facter/puppet_vardir.rb
deleted file mode 100644
index 0e6af40..0000000
--- a/lib/facter/puppet_vardir.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-# This facter fact returns the value of the Puppet vardir setting for the node
-# running puppet or puppet agent. The intent is to enable Puppet modules to
-# automatically have insight into a place where they can place variable data,
-# regardless of the node's platform.
-#
-# The value should be directly usable in a File resource path attribute.
-
-
-begin
- require 'facter/util/puppet_settings'
-rescue LoadError => e
- # puppet apply does not add module lib directories to the $LOAD_PATH (See
- # #4248). It should (in the future) but for the time being we need to be
- # defensive which is what this rescue block is doing.
- rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb')
- load rb_file if File.exists?(rb_file) or raise e
-end
-
-Facter.add(:puppet_vardir) do
- setcode do
- # This will be nil if Puppet is not available.
- Facter::Util::PuppetSettings.with_puppet do
- Puppet[:vardir]
- end
- end
-end
diff --git a/lib/puppet/functions/deprecation.rb b/lib/puppet/functions/deprecation.rb
index 3b84ae5..a860aa2 100644
--- a/lib/puppet/functions/deprecation.rb
+++ b/lib/puppet/functions/deprecation.rb
@@ -15,7 +15,9 @@ Puppet::Functions.create_function(:deprecation) do
when :error
fail("deprecation. #{key}. #{message}")
else
- Puppet.warn_once('deprecation', key, message)
+ unless ENV['STDLIB_LOG_DEPRECATIONS'] == 'false'
+ Puppet.deprecation_warning(message, key)
+ end
end
end
end
diff --git a/lib/puppet/functions/is_absolute_path.rb b/lib/puppet/functions/is_absolute_path.rb
new file mode 100644
index 0000000..b61064a
--- /dev/null
+++ b/lib/puppet/functions/is_absolute_path.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_absolute_path) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_absolute_path', "This method is deprecated, please use match expressions with Stdlib::Compat::Absolute_Path instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_absolute_path", args)
+ end
+end
diff --git a/lib/puppet/functions/is_array.rb b/lib/puppet/functions/is_array.rb
new file mode 100644
index 0000000..a29fe8a
--- /dev/null
+++ b/lib/puppet/functions/is_array.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_array) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_array', "This method is deprecated, please use match expressions with Stdlib::Compat::Array instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_array", args)
+ end
+end
diff --git a/lib/puppet/functions/is_bool.rb b/lib/puppet/functions/is_bool.rb
new file mode 100644
index 0000000..6e2c22b
--- /dev/null
+++ b/lib/puppet/functions/is_bool.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_bool) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_bool', "This method is deprecated, please use match expressions with Stdlib::Compat::Bool instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_bool", args)
+ end
+end
diff --git a/lib/puppet/functions/is_float.rb b/lib/puppet/functions/is_float.rb
new file mode 100644
index 0000000..c91aa5d
--- /dev/null
+++ b/lib/puppet/functions/is_float.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_float) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_float', "This method is deprecated, please use match expressions with Stdlib::Compat::Float instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_float", args)
+ end
+end
diff --git a/lib/puppet/functions/is_ip_address.rb b/lib/puppet/functions/is_ip_address.rb
new file mode 100644
index 0000000..4c72037
--- /dev/null
+++ b/lib/puppet/functions/is_ip_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_ip_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_ip_address', "This method is deprecated, please use match expressions with Stdlib::Compat::Ip_address instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_ip_address", args)
+ end
+end
diff --git a/lib/puppet/functions/is_ipv4_address.rb b/lib/puppet/functions/is_ipv4_address.rb
new file mode 100644
index 0000000..97b01ae
--- /dev/null
+++ b/lib/puppet/functions/is_ipv4_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_ipv4_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_ipv4_address', "This method is deprecated, please use match expressions with Stdlib::Compat::Ipv4 instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_ipv4_address", args)
+ end
+end
diff --git a/lib/puppet/functions/is_ipv6_address.rb b/lib/puppet/functions/is_ipv6_address.rb
new file mode 100644
index 0000000..be0c98a
--- /dev/null
+++ b/lib/puppet/functions/is_ipv6_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_ipv6_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_ipv4_address', "This method is deprecated, please use match expressions with Stdlib::Compat::Ipv6 instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_ipv6_address", args)
+ end
+end
diff --git a/lib/puppet/functions/is_numeric.rb b/lib/puppet/functions/is_numeric.rb
new file mode 100644
index 0000000..f5e9d41
--- /dev/null
+++ b/lib/puppet/functions/is_numeric.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_numeric) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_numeric', "This method is deprecated, please use match expressions with Stdlib::Compat::Numeric instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_numeric", args)
+ end
+end
diff --git a/lib/puppet/functions/is_string.rb b/lib/puppet/functions/is_string.rb
new file mode 100644
index 0000000..a05a796
--- /dev/null
+++ b/lib/puppet/functions/is_string.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:is_string) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'is_string', "This method is deprecated, please use match expressions with Stdlib::Compat::String instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.")
+ scope.send("function_is_string", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_absolute_path.rb b/lib/puppet/functions/validate_absolute_path.rb
new file mode 100644
index 0000000..a3c696d
--- /dev/null
+++ b/lib/puppet/functions/validate_absolute_path.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_absolute_path) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_absolute_path', "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.")
+ scope.send("function_validate_absolute_path", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_array.rb b/lib/puppet/functions/validate_array.rb
new file mode 100644
index 0000000..f59c6b4
--- /dev/null
+++ b/lib/puppet/functions/validate_array.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_array) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_array', "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.")
+ scope.send("function_validate_array", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_bool.rb b/lib/puppet/functions/validate_bool.rb
new file mode 100644
index 0000000..5cfb2ac
--- /dev/null
+++ b/lib/puppet/functions/validate_bool.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_bool) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_bool', "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.")
+ scope.send("function_validate_bool", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_hash.rb b/lib/puppet/functions/validate_hash.rb
new file mode 100644
index 0000000..89ad9ab
--- /dev/null
+++ b/lib/puppet/functions/validate_hash.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_hash) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_hash', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_hash", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_integer.rb b/lib/puppet/functions/validate_integer.rb
new file mode 100644
index 0000000..475ea0f
--- /dev/null
+++ b/lib/puppet/functions/validate_integer.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_integer) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_integer', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_integer", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_ip_address.rb b/lib/puppet/functions/validate_ip_address.rb
new file mode 100644
index 0000000..1521c08
--- /dev/null
+++ b/lib/puppet/functions/validate_ip_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_ip_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_ip_address', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_Address. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_ip_address", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_ipv4_address.rb b/lib/puppet/functions/validate_ipv4_address.rb
new file mode 100644
index 0000000..fe66ab3
--- /dev/null
+++ b/lib/puppet/functions/validate_ipv4_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_ipv4_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_ipv4_address', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4_Address. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_ipv4_address", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_ipv6_address.rb b/lib/puppet/functions/validate_ipv6_address.rb
new file mode 100644
index 0000000..7cc3cbd
--- /dev/null
+++ b/lib/puppet/functions/validate_ipv6_address.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_ipv6_address) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_ipv6_address', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6_address. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_ipv6_address", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_legacy.rb b/lib/puppet/functions/validate_legacy.rb
new file mode 100644
index 0000000..c9d1f56
--- /dev/null
+++ b/lib/puppet/functions/validate_legacy.rb
@@ -0,0 +1,62 @@
+Puppet::Functions.create_function(:validate_legacy) do
+ # The function checks a value against both the target_type (new) and the previous_validation function (old).
+
+ dispatch :validate_legacy do
+ param 'Any', :scope
+ param 'Type', :target_type
+ param 'String', :function_name
+ param 'Any', :value
+ repeated_param 'Any', :args
+ end
+
+ dispatch :validate_legacy_s do
+ param 'Any', :scope
+ param 'String', :type_string
+ param 'String', :function_name
+ param 'Any', :value
+ repeated_param 'Any', :args
+ end
+
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+
+ def validate_legacy_s(scope, type_string, *args)
+ t = Puppet::Pops::Types::TypeParser.new.parse(type_string, scope)
+ validate_legacy(scope, t, *args)
+ end
+
+ def validate_legacy(scope, target_type, function_name, value, *prev_args)
+ if assert_type(target_type, value)
+ if previous_validation(scope, function_name, value, *prev_args)
+ # Silently passes
+ else
+ Puppet.notice("Accepting previously invalid value for target type '#{target_type}'")
+ end
+ else
+ inferred_type = Puppet::Pops::Types::TypeCalculator.infer_set(value)
+ error_msg = Puppet::Pops::Types::TypeMismatchDescriber.new.describe_mismatch("validate_legacy(#{function_name})", target_type, inferred_type)
+ if previous_validation(scope, function_name, value, *prev_args)
+ call_function('deprecation', 'validate_legacy', error_msg)
+ else
+ call_function('fail', error_msg)
+ end
+ end
+ end
+
+ def previous_validation(scope, function_name, value, *prev_args)
+ # Call the previous validation function and catch any errors. Return true if no errors are thrown.
+ begin
+ scope.send("function_#{function_name}".to_s, [value, *prev_args])
+ true
+ rescue Puppet::ParseError
+ false
+ end
+ end
+
+ def assert_type(type, value)
+ Puppet::Pops::Types::TypeCalculator.instance?(type, value)
+ end
+end
diff --git a/lib/puppet/functions/validate_numeric.rb b/lib/puppet/functions/validate_numeric.rb
new file mode 100644
index 0000000..3052d35
--- /dev/null
+++ b/lib/puppet/functions/validate_numeric.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_numeric) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_numeric', "This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_numeric", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_re.rb b/lib/puppet/functions/validate_re.rb
new file mode 100644
index 0000000..19443a8
--- /dev/null
+++ b/lib/puppet/functions/validate_re.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_re) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_re', "This method is deprecated, please use the stdlib validate_legacy function, with Pattern[]. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_re", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_slength.rb b/lib/puppet/functions/validate_slength.rb
new file mode 100644
index 0000000..584232a
--- /dev/null
+++ b/lib/puppet/functions/validate_slength.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_slength) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_slength', "This method is deprecated, please use the stdlib validate_legacy function, with String[]. There is further documentation for validate_legacy function in the README.")
+ scope.send("function_validate_slength", args)
+ end
+end
diff --git a/lib/puppet/functions/validate_string.rb b/lib/puppet/functions/validate_string.rb
new file mode 100644
index 0000000..91ff004
--- /dev/null
+++ b/lib/puppet/functions/validate_string.rb
@@ -0,0 +1,15 @@
+Puppet::Functions.create_function(:validate_string) do
+ dispatch :deprecation_gen do
+ param 'Any', :scope
+ repeated_param 'Any', :args
+ end
+ # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff-c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1.
+ def call(scope, *args)
+ manipulated_args = [scope] + args
+ self.class.dispatcher.dispatch(self, scope, manipulated_args)
+ end
+ def deprecation_gen(scope, *args)
+ call_function('deprecation', 'validate_string', "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.")
+ scope.send("function_validate_string", args)
+ end
+end
diff --git a/lib/puppet/parser/functions/deprecation.rb b/lib/puppet/parser/functions/deprecation.rb
new file mode 100644
index 0000000..e30f3a0
--- /dev/null
+++ b/lib/puppet/parser/functions/deprecation.rb
@@ -0,0 +1,17 @@
+module Puppet::Parser::Functions
+ newfunction(:deprecation, :type => :rvalue, :doc => <<-EOS
+ Function to print deprecation warnings (this is the 3.X version of it), The uniqueness key - can appear once. The msg is the message text including any positional information that is formatted by the user/caller of the method.).
+EOS
+ ) do |arguments|
+
+ raise(Puppet::ParseError, "deprecation: Wrong number of arguments " +
+ "given (#{arguments.size} for 2)") unless arguments.size == 2
+
+ key = arguments[0]
+ message = arguments[1]
+
+ if ENV['STDLIB_LOG_DEPRECATIONS'] == "true"
+ warning("deprecation. #{key}. #{message}")
+ end
+ end
+end
diff --git a/lib/puppet/parser/functions/dig44.rb b/lib/puppet/parser/functions/dig44.rb
index a7de363..1e7c318 100644
--- a/lib/puppet/parser/functions/dig44.rb
+++ b/lib/puppet/parser/functions/dig44.rb
@@ -3,21 +3,28 @@
#
module Puppet::Parser::Functions
- newfunction(:dig44, :type => :rvalue, :doc => <<-EOS
+ newfunction(
+ :dig44,
+ :type => :rvalue,
+ :arity => -2,
+ :doc => <<-eos
DEPRECATED: This function has been replaced in puppet 4.5.0.
-Looks up into a complex structure of arrays and hashes and returns nil
+Looks up into a complex structure of arrays and hashes and returns a value
or the default value if nothing was found.
-Path is an array of keys to be looked up in data argument. The function
-will go down the structure and try to extract the required value.
+Key can contain slashes to describe path components. The function will go down
+the structure and try to extract the required value.
$data = {
'a' => {
'b' => [
'b1',
'b2',
- 'b3' ]}}
+ 'b3',
+ ]
+ }
+}
$value = dig44($data, ['a', 'b', '2'], 'not_found')
=> $value = 'b3'
@@ -29,18 +36,18 @@ b -> second hash key
not_found -> (optional) will be returned if there is no value or the path
did not match. Defaults to nil.
-In addition to the required "path" argument, "dig44" accepts default
+In addition to the required "key" argument, the function accepts a default
argument. It will be returned if no value was found or a path component is
missing. And the fourth argument can set a variable path separator.
- EOS
- ) do |arguments|
+ eos
+ ) do |arguments|
# Two arguments are required
raise(Puppet::ParseError, "dig44(): Wrong number of arguments " +
"given (#{arguments.size} for at least 2)") if arguments.size < 2
data, path, default = *arguments
- if !(data.is_a?(Hash) || data.is_a?(Array))
+ unless data.is_a?(Hash) or data.is_a?(Array)
raise(Puppet::ParseError, "dig44(): first argument must be a hash or an array, " <<
"given #{data.class.name}")
end
@@ -50,7 +57,17 @@ missing. And the fourth argument can set a variable path separator.
"given #{path.class.name}")
end
- value = path.reduce(data) { |h, k| (h.is_a?(Hash) || h.is_a?(Array)) ? h[k] : break }
+ value = path.reduce(data) do |structure, key|
+ if structure.is_a? Hash or structure.is_a? Array
+ if structure.is_a? Array
+ key = Integer key rescue break
+ end
+ break if structure[key].nil? or structure[key] == :undef
+ structure[key]
+ else
+ break
+ end
+ end
value.nil? ? default : value
end
end
diff --git a/lib/puppet/parser/functions/ensure_resources.rb b/lib/puppet/parser/functions/ensure_resources.rb
index 30d57a8..b3c51e6 100644
--- a/lib/puppet/parser/functions/ensure_resources.rb
+++ b/lib/puppet/parser/functions/ensure_resources.rb
@@ -36,7 +36,7 @@ ENDOFDOC
params ||= {}
if title.is_a?(Hash)
- resource_hash = Hash(title)
+ resource_hash = title.dup
resources = resource_hash.keys
Puppet::Parser::Functions.function(:ensure_resource)
diff --git a/lib/puppet/parser/functions/getparam.rb b/lib/puppet/parser/functions/getparam.rb
index 6d51006..0a5cbe0 100644
--- a/lib/puppet/parser/functions/getparam.rb
+++ b/lib/puppet/parser/functions/getparam.rb
@@ -28,7 +28,7 @@ ENDOFDOC
return '' if param.empty?
if resource = findresource(reference.to_s)
- return resource[param] if resource[param]
+ return resource[param] unless resource[param].nil?
end
return ''
diff --git a/lib/puppet/parser/functions/getvar.rb b/lib/puppet/parser/functions/getvar.rb
index ae9c869..3af8d48 100644
--- a/lib/puppet/parser/functions/getvar.rb
+++ b/lib/puppet/parser/functions/getvar.rb
@@ -20,9 +20,13 @@ module Puppet::Parser::Functions
end
begin
+ result = nil
catch(:undefined_variable) do
- self.lookupvar("#{args[0]}")
+ result = self.lookupvar("#{args[0]}")
end
+
+ # avoid relying on incosistent behaviour around ruby return values from catch
+ result
rescue Puppet::ParseError # Eat the exception if strict_variables = true is set
end
diff --git a/lib/puppet/parser/functions/is_absolute_path.rb b/lib/puppet/parser/functions/is_absolute_path.rb
index 53a5445..e64777f 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([:is_absolute_path, '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..1d2c0fa 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([:is_array, '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..83d2ebe 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([:is_bool, '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_float.rb b/lib/puppet/parser/functions/is_float.rb
index a2da943..1186458 100644
--- a/lib/puppet/parser/functions/is_float.rb
+++ b/lib/puppet/parser/functions/is_float.rb
@@ -8,6 +8,8 @@ Returns true if the variable passed to this function is a float.
EOS
) do |arguments|
+ function_deprecation([:is_float, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Float. There is further documentation for validate_legacy function in the README.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_integer.rb b/lib/puppet/parser/functions/is_integer.rb
index c03d28d..e04fd1f 100644
--- a/lib/puppet/parser/functions/is_integer.rb
+++ b/lib/puppet/parser/functions/is_integer.rb
@@ -13,6 +13,8 @@ If given any other argument `false` is returned.
EOS
) do |arguments|
+ function_deprecation([:is_integer, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_ip_address.rb b/lib/puppet/parser/functions/is_ip_address.rb
index a90adab..5f1d765 100644
--- a/lib/puppet/parser/functions/is_ip_address.rb
+++ b/lib/puppet/parser/functions/is_ip_address.rb
@@ -10,6 +10,8 @@ Returns true if the string passed to this function is a valid IP address.
require 'ipaddr'
+ function_deprecation([:is_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_ipv4_address.rb b/lib/puppet/parser/functions/is_ipv4_address.rb
index b4861d5..1764e61 100644
--- a/lib/puppet/parser/functions/is_ipv4_address.rb
+++ b/lib/puppet/parser/functions/is_ipv4_address.rb
@@ -10,6 +10,8 @@ Returns true if the string passed to this function is a valid IPv4 address.
require 'ipaddr'
+ function_deprecation([:is_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_ipv4_address(): Wrong number of arguments "+
"given #{arguments.size} for 1")
diff --git a/lib/puppet/parser/functions/is_ipv6_address.rb b/lib/puppet/parser/functions/is_ipv6_address.rb
index 475ad50..7ca4997 100644
--- a/lib/puppet/parser/functions/is_ipv6_address.rb
+++ b/lib/puppet/parser/functions/is_ipv6_address.rb
@@ -8,6 +8,8 @@ Returns true if the string passed to this function is a valid IPv6 address.
EOS
) do |arguments|
+ function_deprecation([:is_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
+
require 'ipaddr'
if (arguments.size != 1) then
diff --git a/lib/puppet/parser/functions/is_numeric.rb b/lib/puppet/parser/functions/is_numeric.rb
index e7e1d2a..4a55225 100644
--- a/lib/puppet/parser/functions/is_numeric.rb
+++ b/lib/puppet/parser/functions/is_numeric.rb
@@ -24,6 +24,8 @@ Valid examples:
EOS
) do |arguments|
+ function_deprecation([:is_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.'])
+
if (arguments.size != 1) then
raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+
"given #{arguments.size} for 1")
@@ -71,5 +73,3 @@ Valid examples:
end
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..31ee91e 100644
--- a/lib/puppet/parser/functions/is_string.rb
+++ b/lib/puppet/parser/functions/is_string.rb
@@ -8,12 +8,15 @@ Returns true if the variable passed to this function is a string.
EOS
) do |arguments|
+ function_deprecation([:is_string, '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
type = arguments[0]
- result = type.is_a?(String)
+ # when called through the v4 API shim, undef gets translated to nil
+ result = type.is_a?(String) || type.nil?
if result and (type == type.to_f.to_s or type == type.to_i.to_s) then
return false
diff --git a/lib/puppet/parser/functions/validate_absolute_path.rb b/lib/puppet/parser/functions/validate_absolute_path.rb
index 5f85f72..c73f3df 100644
--- a/lib/puppet/parser/functions/validate_absolute_path.rb
+++ b/lib/puppet/parser/functions/validate_absolute_path.rb
@@ -26,6 +26,9 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ # The deprecation function was being called twice, as validate_absolute_path calls is_absolute_path. I have removed it from here so it only calls deprecation once within is_absolute_path.
+ # function_deprecation([:validate_absolute_path, '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..3bf3983 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([:validate_array, '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..49075b8 100644
--- a/lib/puppet/parser/functions/validate_bool.rb
+++ b/lib/puppet/parser/functions/validate_bool.rb
@@ -19,6 +19,9 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ # The deprecation function was being called twice, as validate_bool calls is_bool. I have removed it from here so it only calls deprecation once within is_bool.
+ # function_deprecation([:validate_bool, '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_hash.rb b/lib/puppet/parser/functions/validate_hash.rb
index 9bdd543..fcdc7e1 100644
--- a/lib/puppet/parser/functions/validate_hash.rb
+++ b/lib/puppet/parser/functions/validate_hash.rb
@@ -18,6 +18,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_hash, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Hash. There is further documentation for validate_legacy function in the README.'])
+
unless args.length > 0 then
raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)")
end
diff --git a/lib/puppet/parser/functions/validate_integer.rb b/lib/puppet/parser/functions/validate_integer.rb
index a950916..2ae0293 100644
--- a/lib/puppet/parser/functions/validate_integer.rb
+++ b/lib/puppet/parser/functions/validate_integer.rb
@@ -2,7 +2,7 @@ module Puppet::Parser::Functions
newfunction(:validate_integer, :doc => <<-'ENDHEREDOC') do |args|
Validate that the first argument is an integer (or an array of integers). Abort catalog compilation if any of the checks fail.
-
+
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min.
@@ -53,6 +53,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_integer, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Integer. There is further documentation for validate_legacy function in the README.'])
+
# tell the user we need at least one, and optionally up to two other parameters
raise Puppet::ParseError, "validate_integer(): Wrong number of arguments; must be 1, 2 or 3, got #{args.length}" unless args.length > 0 and args.length < 4
diff --git a/lib/puppet/parser/functions/validate_ip_address.rb b/lib/puppet/parser/functions/validate_ip_address.rb
index 64fbd75..5d80cfb 100644
--- a/lib/puppet/parser/functions/validate_ip_address.rb
+++ b/lib/puppet/parser/functions/validate_ip_address.rb
@@ -8,12 +8,12 @@ module Puppet::Parser::Functions
$my_ip = "1.2.3.4"
validate_ip_address($my_ip)
validate_ip_address("8.8.8.8", "172.16.0.1", $my_ip)
-
+
$my_ip = "3ffe:505:2"
validate_ip_address(1)
validate_ip_address($my_ip)
validate_ip_address("fe80::baf6:b1ff:fe19:7507", $my_ip)
-
+
The following values will fail, causing compilation to abort:
$some_array = [ 1, true, false, "garbage string", "3ffe:505:2" ]
validate_ip_address($some_array)
@@ -23,6 +23,8 @@ module Puppet::Parser::Functions
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
+ function_deprecation([:validate_ip_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ip_address. There is further documentation for validate_legacy function in the README.'])
+
if defined?(IPAddr::InvalidAddressError)
rescuable_exceptions << IPAddr::InvalidAddressError
end
diff --git a/lib/puppet/parser/functions/validate_ipv4_address.rb b/lib/puppet/parser/functions/validate_ipv4_address.rb
index 97faa57..0660abd 100644
--- a/lib/puppet/parser/functions/validate_ipv4_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv4_address.rb
@@ -18,6 +18,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
) do |args|
+ function_deprecation([:validate_ipv4_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv4. There is further documentation for validate_legacy function in the README.'])
+
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
diff --git a/lib/puppet/parser/functions/validate_ipv6_address.rb b/lib/puppet/parser/functions/validate_ipv6_address.rb
index b0f2558..f5dd9e5 100644
--- a/lib/puppet/parser/functions/validate_ipv6_address.rb
+++ b/lib/puppet/parser/functions/validate_ipv6_address.rb
@@ -19,6 +19,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
) do |args|
+ function_deprecation([:validate_ipv6_address, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Ipv6. There is further documentation for validate_legacy function in the README.'])
+
require "ipaddr"
rescuable_exceptions = [ ArgumentError ]
diff --git a/lib/puppet/parser/functions/validate_numeric.rb b/lib/puppet/parser/functions/validate_numeric.rb
index 3a14443..4205b30 100644
--- a/lib/puppet/parser/functions/validate_numeric.rb
+++ b/lib/puppet/parser/functions/validate_numeric.rb
@@ -2,7 +2,7 @@ module Puppet::Parser::Functions
newfunction(:validate_numeric, :doc => <<-'ENDHEREDOC') do |args|
Validate that the first argument is a numeric value (or an array of numeric values). Abort catalog compilation if any of the checks fail.
-
+
The second argument is optional and passes a maximum. (All elements of) the first argument has to be less or equal to this max.
The third argument is optional and passes a minimum. (All elements of) the first argument has to be greater or equal to this min.
@@ -15,6 +15,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_numeric, 'This method is deprecated, please use the stdlib validate_legacy function, with Stdlib::Compat::Numeric. There is further documentation for validate_legacy function in the README.'])
+
# tell the user we need at least one, and optionally up to two other parameters
raise Puppet::ParseError, "validate_numeric(): Wrong number of arguments; must be 1, 2 or 3, got #{args.length}" unless args.length > 0 and args.length < 4
diff --git a/lib/puppet/parser/functions/validate_re.rb b/lib/puppet/parser/functions/validate_re.rb
index efee7f8..0ac83dd 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([:validate_re, '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_slength.rb b/lib/puppet/parser/functions/validate_slength.rb
index 47c7d4a..383855c 100644
--- a/lib/puppet/parser/functions/validate_slength.rb
+++ b/lib/puppet/parser/functions/validate_slength.rb
@@ -21,6 +21,8 @@ module Puppet::Parser::Functions
ENDHEREDOC
+ function_deprecation([:validate_slength, 'This method is deprecated, please use the stdlib validate_legacy function, with String[]. There is further documentation for validate_legacy function in the README.'])
+
raise Puppet::ParseError, "validate_slength(): Wrong number of arguments (#{args.length}; must be 2 or 3)" unless args.length == 2 or args.length == 3
input, max_length, min_length = *args
diff --git a/lib/puppet/parser/functions/validate_string.rb b/lib/puppet/parser/functions/validate_string.rb
index c841f6a..6675d86 100644
--- a/lib/puppet/parser/functions/validate_string.rb
+++ b/lib/puppet/parser/functions/validate_string.rb
@@ -13,22 +13,25 @@ module Puppet::Parser::Functions
validate_string(true)
validate_string([ 'some', 'array' ])
-
+
Note: validate_string(undef) will not fail in this version of the
functions API (incl. current and future parser). Instead, use:
-
+
if $var == undef {
fail('...')
}
-
+
ENDHEREDOC
+ function_deprecation([:validate_string, '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
args.each do |arg|
- unless arg.is_a?(String)
+ # when called through the v4 API shim, undef gets translated to nil
+ unless arg.is_a?(String) || arg.nil?
raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}")
end
end
diff --git a/lib/puppet/provider/file_line/ruby.rb b/lib/puppet/provider/file_line/ruby.rb
index aab6fe2..beeb430 100644
--- a/lib/puppet/provider/file_line/ruby.rb
+++ b/lib/puppet/provider/file_line/ruby.rb
@@ -4,7 +4,11 @@ Puppet::Type.type(:file_line).provide(:ruby) do
true
else
lines.find do |line|
- line.chomp == resource[:line].chomp
+ if resource[:ensure].to_s == 'absent' and resource[:match_for_absence].to_s == 'true'
+ line.chomp =~ Regexp.new(resource[:match])
+ else
+ line.chomp == resource[:line].chomp
+ end
end
end
end
diff --git a/lib/puppet/type/file_line.rb b/lib/puppet/type/file_line.rb
index 6f5c188..7b7d44e 100644
--- a/lib/puppet/type/file_line.rb
+++ b/lib/puppet/type/file_line.rb
@@ -71,7 +71,8 @@ Puppet::Type.newtype(:file_line) do
newparam(:match_for_absence) do
desc 'An optional value to determine if match should be applied when ensure => absent.' +
' If set to true and match is set, the line that matches match will be deleted.' +
- ' If set to false (the default), match is ignored when ensure => absent.'
+ ' If set to false (the default), match is ignored when ensure => absent.' +
+ ' When `ensure => present`, match_for_absence is ignored.'
newvalues(true, false)
defaultto false
end
diff --git a/metadata.json b/metadata.json
index 514023e..8ad4eec 100644
--- a/metadata.json
+++ b/metadata.json
@@ -1,6 +1,6 @@
{
"name": "puppetlabs-stdlib",
- "version": "4.12.0",
+ "version": "4.13.1",
"author": "puppetlabs",
"summary": "Standard library of resources for Puppet modules.",
"license": "Apache-2.0",
@@ -100,16 +100,12 @@
],
"requirements": [
{
- "name": "pe",
- "version_requirement": ">= 3.0.0 < 2015.4.0"
- },
- {
"name": "puppet",
"version_requirement": ">=2.7.20 <5.0.0"
}
],
"description": "Standard Library for Puppet Modules",
"dependencies": [
-
+
]
}
diff --git a/spec/acceptance/deprecation_spec.rb b/spec/acceptance/deprecation_spec.rb
index d0d7fed..ea13700 100644
--- a/spec/acceptance/deprecation_spec.rb
+++ b/spec/acceptance/deprecation_spec.rb
@@ -1,19 +1,29 @@
#! /usr/bin/env ruby -S rspec
require 'spec_helper_acceptance'
-require 'shellwords'
describe 'deprecation function' do
- before :each do
- FileUtils.rm_rf '/tmp/deprecation'
+
+ if fact('operatingsystem') == 'windows'
+ test_file = 'C:/deprecation'
+ else
+ test_file = "/tmp/deprecation"
+ end
+
+ # It seems that Windows needs everything to be on one line when using puppet apply -e, otherwise the manifests would be in an easier format
+ add_file_manifest = "\"deprecation('key', 'message') file { '#{test_file}': ensure => present, content => 'test', }\""
+ remove_file_manifest = "file { '#{test_file}': ensure => absent }"
+
+ before :all do
+ apply_manifest(remove_file_manifest)
end
context 'with --strict=error', if: get_puppet_version =~ /^4/ do
before :all do
- pp = <<-EOS
- deprecation('key', 'message')
- file { '/tmp/deprecation': ensure => present }
- EOS
- @result = on(default, puppet('apply', '--strict=error', '-e', Shellwords.shellescape(pp)), acceptable_exit_codes: (0...256))
+ @result = on(default, puppet('apply', '--strict=error', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
+ end
+
+ after :all do
+ apply_manifest(remove_file_manifest)
end
it "should return an error" do
@@ -24,18 +34,18 @@ describe 'deprecation function' do
expect(@result.stderr).to match(/deprecation. key. message/)
end
- describe file('/tmp/deprecation') do
- it { is_expected.not_to exist }
+ describe file("#{test_file}") do
+ it { is_expected.not_to be_file }
end
end
context 'with --strict=warning', if: get_puppet_version =~ /^4/ do
before :all do
- pp = <<-EOS
- deprecation('key', 'message')
- file { '/tmp/deprecation': ensure => present }
- EOS
- @result = on(default, puppet('apply', '--strict=warning', '-e', Shellwords.shellescape(pp)), acceptable_exit_codes: (0...256))
+ @result = on(default, puppet('apply', '--strict=warning', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
+ end
+
+ after :all do
+ apply_manifest(remove_file_manifest)
end
it "should not return an error" do
@@ -46,18 +56,18 @@ describe 'deprecation function' do
expect(@result.stderr).to match(/Warning: message/)
end
- describe file('/tmp/deprecation') do
- it { is_expected.to exist }
+ describe file("#{test_file}") do
+ it { is_expected.to be_file }
end
end
context 'with --strict=off', if: get_puppet_version =~ /^4/ do
before :all do
- pp = <<-EOS
- deprecation('key', 'message')
- file { '/tmp/deprecation': ensure => present }
- EOS
- @result = on(default, puppet('apply', '--strict=off', '-e', Shellwords.shellescape(pp)), acceptable_exit_codes: (0...256))
+ @result = on(default, puppet('apply', '--strict=off', '-e', add_file_manifest), acceptable_exit_codes: (0...256))
+ end
+
+ after :all do
+ apply_manifest(remove_file_manifest)
end
it "should not return an error" do
@@ -68,8 +78,8 @@ describe 'deprecation function' do
expect(@result.stderr).not_to match(/Warning: message/)
end
- describe file('/tmp/deprecation') do
- it { is_expected.to exist }
+ describe file("#{test_file}") do
+ it { is_expected.to be_file }
end
end
end
diff --git a/spec/acceptance/is_string_spec.rb b/spec/acceptance/is_string_spec.rb
index 94d8e96..f526888 100755
--- a/spec/acceptance/is_string_spec.rb
+++ b/spec/acceptance/is_string_spec.rb
@@ -95,6 +95,17 @@ describe 'is_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('o
expect(r.stdout).to match(/Notice: output correct/)
end
end
+ it 'is_strings undef' do
+ pp = <<-EOS
+ $a = undef
+ $o = is_string($a)
+ notice(inline_template('is_string is <%= @o.inspect %>'))
+ EOS
+
+ apply_manifest(pp, :catch_failures => true) do |r|
+ expect(r.stdout).to match(/is_string is true/)
+ end
+ end
end
describe 'failure' do
it 'handles improper argument counts'
diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml
index 1a40c89..5eebdef 100644
--- a/spec/acceptance/nodesets/centos-7-x64.yml
+++ b/spec/acceptance/nodesets/centos-7-x64.yml
@@ -3,7 +3,7 @@ HOSTS:
roles:
- agent
- default
- platform: redhat-7-x86_64
+ platform: el-7-x86_64
hypervisor: vagrant
box: puppetlabs/centos-7.2-64-nocm
CONFIG:
diff --git a/spec/acceptance/validate_array_spec.rb b/spec/acceptance/validate_array_spec.rb
index b53e98c..2f549d5 100755
--- a/spec/acceptance/validate_array_spec.rb
+++ b/spec/acceptance/validate_array_spec.rb
@@ -20,14 +20,14 @@ describe 'validate_array function', :unless => UNSUPPORTED_PLATFORMS.include?(fa
apply_manifest(pp, :catch_failures => true)
end
- it 'validates a non-array' do
- {
- %{validate_array({'a' => 'hash' })} => "Hash",
- %{validate_array('string')} => "String",
- %{validate_array(false)} => "FalseClass",
- %{validate_array(undef)} => "String"
- }.each do |pp,type|
- expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
+ [
+ %{validate_array({'a' => 'hash' })},
+ %{validate_array('string')},
+ %{validate_array(false)},
+ %{validate_array(undef)}
+ ].each do |pp|
+ it "rejects #{pp.inspect}" do
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/is not an Array\. It looks to be a/)
end
end
end
diff --git a/spec/acceptance/validate_bool_spec.rb b/spec/acceptance/validate_bool_spec.rb
index c837f08..5c52d0f 100755
--- a/spec/acceptance/validate_bool_spec.rb
+++ b/spec/acceptance/validate_bool_spec.rb
@@ -20,14 +20,14 @@ describe 'validate_bool function', :unless => UNSUPPORTED_PLATFORMS.include?(fac
apply_manifest(pp, :catch_failures => true)
end
- it 'validates a non-bool' do
- {
- %{validate_bool('true')} => "String",
- %{validate_bool('false')} => "String",
- %{validate_bool([true])} => "Array",
- %{validate_bool(undef)} => "String",
- }.each do |pp,type|
- expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
+ [
+ %{validate_bool('true')},
+ %{validate_bool('false')},
+ %{validate_bool([true])},
+ %{validate_bool(undef)}
+ ].each do |pp|
+ it "rejects #{pp.inspect}" do
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/is not a boolean\. It looks to be a/)
end
end
end
diff --git a/spec/acceptance/validate_hash_spec.rb b/spec/acceptance/validate_hash_spec.rb
index 52fb615..637df0a 100755
--- a/spec/acceptance/validate_hash_spec.rb
+++ b/spec/acceptance/validate_hash_spec.rb
@@ -20,14 +20,14 @@ describe 'validate_hash function', :unless => UNSUPPORTED_PLATFORMS.include?(fac
apply_manifest(pp, :catch_failures => true)
end
- it 'validates a non-hash' do
- {
- %{validate_hash('{ "not" => "hash" }')} => "String",
- %{validate_hash('string')} => "String",
- %{validate_hash(["array"])} => "Array",
- %{validate_hash(undef)} => "String",
- }.each do |pp,type|
- expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/a #{type}/)
+ [
+ %{validate_hash('{ "not" => "hash" }')},
+ %{validate_hash('string')},
+ %{validate_hash(["array"])},
+ %{validate_hash(undef)}
+ ].each do |pp|
+ it "rejects #{pp.inspect}" do
+ expect(apply_manifest(pp, :expect_failures => true).stderr).to match(//)
end
end
end
diff --git a/spec/acceptance/validate_string_spec.rb b/spec/acceptance/validate_string_spec.rb
index 8956f48..ae3468f 100755
--- a/spec/acceptance/validate_string_spec.rb
+++ b/spec/acceptance/validate_string_spec.rb
@@ -20,6 +20,13 @@ describe 'validate_string function', :unless => UNSUPPORTED_PLATFORMS.include?(f
apply_manifest(pp, :catch_failures => true)
end
+ it 'validates undef' do
+ pp = <<-EOS
+ validate_string(undef)
+ EOS
+
+ apply_manifest(pp, :catch_failures => true)
+ end
it 'validates a non-string' do
{
%{validate_string({ 'a' => 'hash' })} => "Hash",
diff --git a/spec/aliases/absolute_path_spec.rb b/spec/aliases/absolute_path_spec.rb
new file mode 100644
index 0000000..3fb9d12
--- /dev/null
+++ b/spec/aliases/absolute_path_spec.rb
@@ -0,0 +1,62 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ 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/absolutepath_spec.rb b/spec/aliases/absolutepath_spec.rb
new file mode 100644
index 0000000..aa435d7
--- /dev/null
+++ b/spec/aliases/absolutepath_spec.rb
@@ -0,0 +1,49 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::absolutepath', type: :class do
+ describe 'valid handling' do
+ %w{
+ /usr2/username/bin:/usr/local/bin:/usr/bin:.
+ 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' },
+ { },
+ '',
+ "*/Users//nope",
+ "\\Users/hc/wksp/stdlib",
+ "C:noslashes",
+ "\\var\\tmp"
+ ].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 Variant/) }
+ 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..d0f9877
--- /dev/null
+++ b/spec/aliases/array_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ 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..78c57fc
--- /dev/null
+++ b/spec/aliases/bool_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ 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/float_spec.rb b/spec/aliases/float_spec.rb
new file mode 100644
index 0000000..cc20758
--- /dev/null
+++ b/spec/aliases/float_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::float', type: :class do
+ describe 'accepts floats' do
+ [
+ 3.7,
+ '3.7',
+ -3.7,
+ '-342.2315e-12',
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [ true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x', 3, '3', -3, '-3'].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a value of type Float or Pattern(\[.*\]+)?/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/httpsurl_spec.rb b/spec/aliases/httpsurl_spec.rb
new file mode 100644
index 0000000..97ae006
--- /dev/null
+++ b/spec/aliases/httpsurl_spec.rb
@@ -0,0 +1,40 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::httpsurl', type: :class do
+ describe 'valid handling' do
+ %w{
+ https://hello.com
+ https://notcreative.org
+ https://notexciting.co.uk
+ }.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' },
+ { },
+ '',
+ "httds://notquiteright.org",
+ "hptts:/nah",
+ "https;//notrightbutclose.org"
+ ].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::HTTPSUrl/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/aliases/httpurl_spec.rb b/spec/aliases/httpurl_spec.rb
new file mode 100644
index 0000000..8bd57ca
--- /dev/null
+++ b/spec/aliases/httpurl_spec.rb
@@ -0,0 +1,43 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::httpurl', type: :class do
+ describe 'valid handling' do
+ %w{
+ https://hello.com
+ https://notcreative.org
+ https://canstillaccepthttps.co.uk
+ http://anhttp.com
+ http://runningoutofideas.gov
+ http://
+ }.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' },
+ { },
+ '',
+ "httds://notquiteright.org",
+ "hptts:/nah",
+ "https;//notrightbutclose.org"
+ ].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::HTTPUrl/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/aliases/integer_spec.rb b/spec/aliases/integer_spec.rb
new file mode 100644
index 0000000..260090a
--- /dev/null
+++ b/spec/aliases/integer_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::integer', type: :class do
+ describe 'accepts integers' do
+ [
+ 3,
+ '3',
+ -3,
+ '-3',
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [ true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x', 3.7, '3.7',-3.7, '-342.2315e-12' ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a value of type Integer, Pattern(\[.*\]+)?, or Array/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/ip_address.rb b/spec/aliases/ip_address.rb
new file mode 100644
index 0000000..664bf24
--- /dev/null
+++ b/spec/aliases/ip_address.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::ip_address', type: :class do
+ describe 'accepts ipv4 and ipv6 addresses' do
+ [
+ '224.0.0.0',
+ '255.255.255.255',
+ '0.0.0.0',
+ '192.88.99.0',
+ '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ 'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ [
+ 'nope',
+ '77',
+ '4.4.4',
+ '2001:0db8:85a3:000000:0000:8a2e:0370:7334'
+ ].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/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/ipv4_spec.rb b/spec/aliases/ipv4_spec.rb
new file mode 100644
index 0000000..210b4b1
--- /dev/null
+++ b/spec/aliases/ipv4_spec.rb
@@ -0,0 +1,22 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::ipv4', type: :class do
+ describe 'accepts ipv4 addresses' do
+ SharedData::IPV4_PATTERNS.each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ SharedData::IPV4_NEGATIVE_PATTERNS.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::Ipv4/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/ipv6_spec.rb b/spec/aliases/ipv6_spec.rb
new file mode 100644
index 0000000..13d7c3e
--- /dev/null
+++ b/spec/aliases/ipv6_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::ipv6', type: :class do
+ describe 'accepts ipv6 addresses' do
+ [
+ '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ 'fa76:8765:34ac:0823:ab76:eee9:0987:1111'
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+ describe 'rejects other values' do
+ [
+ 'nope',
+ '77',
+ '4.4.4',
+ '2000:7334'
+ ].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::Ipv6/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/numeric_spec.rb b/spec/aliases/numeric_spec.rb
new file mode 100644
index 0000000..0e98bee
--- /dev/null
+++ b/spec/aliases/numeric_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::numeric', type: :class do
+ describe 'accepts numerics' do
+ [
+ 3,
+ '3',
+ -3,
+ '-3',
+ 3.7,
+ '3.7',
+ -3.7,
+ '-342.2315e-12',
+ ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile }
+ end
+ end
+ end
+
+ describe 'rejects other values' do
+ [ true, 'true', false, 'false', 'iAmAString', '1test', '1 test', 'test 1', 'test 1 test', {}, { 'key' => 'value' }, { 1=> 2 }, '', :undef , 'x' ].each do |value|
+ describe value.inspect do
+ let(:params) {{ value: value }}
+ it { is_expected.to compile.and_raise_error(/parameter 'value' expects a value of type Numeric, Pattern(\[.*\]+)?, or Array/) }
+ 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..8a93585
--- /dev/null
+++ b/spec/aliases/string_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::string', type: :class do
+ describe 'accepts strings' do
+ [
+ '',
+ 'one',
+ nil,
+ ].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 String/) }
+ end
+ end
+ end
+ end
+end
diff --git a/spec/aliases/unixpath_spec.rb b/spec/aliases/unixpath_spec.rb
new file mode 100644
index 0000000..aee161d
--- /dev/null
+++ b/spec/aliases/unixpath_spec.rb
@@ -0,0 +1,41 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::unixpath', type: :class do
+ describe 'valid handling' do
+ %w{
+ /usr2/username/bin:/usr/local/bin:/usr/bin:.
+ /var/tmp
+ /Users/helencampbell/workspace/puppetlabs-stdlib
+ }.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' },
+ { },
+ '',
+ "C:/whatever",
+ "\\var\\tmp",
+ "\\Users/hc/wksp/stdlib",
+ "*/Users//nope"
+ ].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::Unixpath/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/aliases/windowspath_spec.rb b/spec/aliases/windowspath_spec.rb
new file mode 100644
index 0000000..c13794e
--- /dev/null
+++ b/spec/aliases/windowspath_spec.rb
@@ -0,0 +1,44 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.5
+ describe 'test::windowspath', type: :class do
+ describe 'valid handling' do
+ %w{
+ C:\\
+ C:\\WINDOWS\\System32
+ C:/windows/system32
+ X:/foo/bar
+ X:\\foo\\bar
+ \\\\host\\windows
+ }.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' },
+ { },
+ '',
+ "httds://notquiteright.org",
+ "/usr2/username/bin:/usr/local/bin:/usr/bin:.",
+ "C;//notright/here",
+ "C:noslashes"
+ ].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::Windowspath/) }
+ end
+ end
+ end
+
+ end
+ end
+end
diff --git a/spec/fixtures/test/manifests/absolute_path.pp b/spec/fixtures/test/manifests/absolute_path.pp
new file mode 100644
index 0000000..d77f6bd
--- /dev/null
+++ b/spec/fixtures/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/test/manifests/absolutepath.pp b/spec/fixtures/test/manifests/absolutepath.pp
new file mode 100644
index 0000000..8321471
--- /dev/null
+++ b/spec/fixtures/test/manifests/absolutepath.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Absolutepath type. Not to be confused with Stdlib::Compat::Absolute_path.
+class test::absolutepath(
+ Stdlib::Absolutepath $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/array.pp b/spec/fixtures/test/manifests/array.pp
new file mode 100644
index 0000000..84b6a5b
--- /dev/null
+++ b/spec/fixtures/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/test/manifests/bool.pp b/spec/fixtures/test/manifests/bool.pp
new file mode 100644
index 0000000..ab5b5ea
--- /dev/null
+++ b/spec/fixtures/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/test/manifests/float.pp b/spec/fixtures/test/manifests/float.pp
new file mode 100644
index 0000000..03a603d
--- /dev/null
+++ b/spec/fixtures/test/manifests/float.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::Float type alias
+class test::float(
+ Stdlib::Compat::Float $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/fixtures/test/manifests/httpsurl.pp b/spec/fixtures/test/manifests/httpsurl.pp
new file mode 100644
index 0000000..9d6b92d
--- /dev/null
+++ b/spec/fixtures/test/manifests/httpsurl.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::HTTPSUrl type alias
+class test::httpsurl(
+ Stdlib::HTTPSUrl $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/httpurl.pp b/spec/fixtures/test/manifests/httpurl.pp
new file mode 100644
index 0000000..abf869e
--- /dev/null
+++ b/spec/fixtures/test/manifests/httpurl.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::HTTPUrl type alias
+class test::httpurl(
+ Stdlib::HTTPUrl $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/integer.pp b/spec/fixtures/test/manifests/integer.pp
new file mode 100644
index 0000000..a4f26df
--- /dev/null
+++ b/spec/fixtures/test/manifests/integer.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::Integer type alias
+class test::integer(
+ Stdlib::Compat::Integer $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/fixtures/test/manifests/ip_address.pp b/spec/fixtures/test/manifests/ip_address.pp
new file mode 100644
index 0000000..bbbd804
--- /dev/null
+++ b/spec/fixtures/test/manifests/ip_address.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ip_address type alias
+class test::ip_address(
+ Stdlib::Compat::Ip_address $value,
+ ) {
+ notice("Success")
+ }
diff --git a/spec/fixtures/test/manifests/ipv4.pp b/spec/fixtures/test/manifests/ipv4.pp
new file mode 100644
index 0000000..2e8022d
--- /dev/null
+++ b/spec/fixtures/test/manifests/ipv4.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ipv4 type alias
+class test::ipv4(
+ Stdlib::Compat::Ipv4 $value,
+ ) {
+ notice("Success")
+ }
diff --git a/spec/fixtures/test/manifests/ipv6.pp b/spec/fixtures/test/manifests/ipv6.pp
new file mode 100644
index 0000000..7912fd6
--- /dev/null
+++ b/spec/fixtures/test/manifests/ipv6.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Compat::Ipv6 type alias
+class test::ipv6(
+ Stdlib::Compat::Ipv6 $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/numeric.pp b/spec/fixtures/test/manifests/numeric.pp
new file mode 100644
index 0000000..2657ebc
--- /dev/null
+++ b/spec/fixtures/test/manifests/numeric.pp
@@ -0,0 +1,8 @@
+# Class to test the Stdlib::Compat::Numeric type alias
+class test::numeric(
+ Stdlib::Compat::Numeric $value,
+ ) {
+
+ notice("Success")
+
+}
diff --git a/spec/fixtures/test/manifests/string.pp b/spec/fixtures/test/manifests/string.pp
new file mode 100644
index 0000000..6508c70
--- /dev/null
+++ b/spec/fixtures/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/fixtures/test/manifests/unixpath.pp b/spec/fixtures/test/manifests/unixpath.pp
new file mode 100644
index 0000000..9311109
--- /dev/null
+++ b/spec/fixtures/test/manifests/unixpath.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Unixpath type alias
+class test::unixpath(
+ Stdlib::Unixpath $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/fixtures/test/manifests/windowspath.pp b/spec/fixtures/test/manifests/windowspath.pp
new file mode 100644
index 0000000..af93ed3
--- /dev/null
+++ b/spec/fixtures/test/manifests/windowspath.pp
@@ -0,0 +1,6 @@
+# Class to test the Stdlib::Windowspath type alias
+class test::windowspath(
+ Stdlib::Windowspath $value,
+ ) {
+ notice("Success")
+}
diff --git a/spec/functions/assert_private_spec.rb b/spec/functions/assert_private_spec.rb
index 98f2598..355e0dd 100755
--- a/spec/functions/assert_private_spec.rb
+++ b/spec/functions/assert_private_spec.rb
@@ -5,31 +5,26 @@ describe 'assert_private' do
it "should not fail" do
scope.expects(:lookupvar).with('module_name').returns('foo')
scope.expects(:lookupvar).with('caller_module_name').returns('foo')
- expect {
- subject.call []
- }.not_to raise_error
+
+ is_expected.to run.with_params()
end
end
- context "with an explicit failure message" do
- it "prints the failure message on error" do
+ context "when called from private class" do
+ before :each do
scope.expects(:lookupvar).with('module_name').returns('foo')
scope.expects(:lookupvar).with('caller_module_name').returns('bar')
- expect {
- subject.call ['failure message!']
- }.to raise_error Puppet::ParseError, /failure message!/
end
- end
- context "when called from private class" do
it "should fail with a class error message" do
- scope.expects(:lookupvar).with('module_name').returns('foo')
- scope.expects(:lookupvar).with('caller_module_name').returns('bar')
scope.source.expects(:name).returns('foo::baz')
scope.source.expects(:type).returns('hostclass')
- expect {
- subject.call []
- }.to raise_error Puppet::ParseError, /Class foo::baz is private/
+
+ is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Class foo::baz is private/)
+ end
+
+ context "with an explicit failure message" do
+ it { is_expected.to run.with_params('failure message!').and_raise_error(Puppet::ParseError, /failure message!/) }
end
end
@@ -39,9 +34,8 @@ describe 'assert_private' do
scope.expects(:lookupvar).with('caller_module_name').returns('bar')
scope.source.expects(:name).returns('foo::baz')
scope.source.expects(:type).returns('definition')
- expect {
- subject.call []
- }.to raise_error Puppet::ParseError, /Definition foo::baz is private/
+
+ is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /Definition foo::baz is private/)
end
end
end
diff --git a/spec/functions/deprecation_spec.rb b/spec/functions/deprecation_spec.rb
index bbabe48..9859833 100644
--- a/spec/functions/deprecation_spec.rb
+++ b/spec/functions/deprecation_spec.rb
@@ -1,13 +1,5 @@
require 'spec_helper'
-if ENV["FUTURE_PARSER"] == 'yes'
- describe 'deprecation' do
- pending 'teach rspec-puppet to load future-only functions under 3.7.5' do
- it { is_expected.not_to eq(nil) }
- end
- end
-end
-
if Puppet.version.to_f >= 4.0
describe 'deprecation' do
before(:each) {
@@ -48,4 +40,18 @@ if Puppet.version.to_f >= 4.0
Puppet.settings[:strict] = :warning
}
end
+else
+ describe 'deprecation' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+
+ it 'should display a single warning' do
+ scope.expects(:warning).with(includes('heelo'))
+ is_expected.to run.with_params('key', 'heelo')
+ end
+ end
end
diff --git a/spec/functions/dig44_spec.rb b/spec/functions/dig44_spec.rb
index fd451ff..4f7408d 100644
--- a/spec/functions/dig44_spec.rb
+++ b/spec/functions/dig44_spec.rb
@@ -1,44 +1,105 @@
require 'spec_helper'
describe 'dig44' do
- it "should exist" do
- expect(Puppet::Parser::Functions.function("dig44")).to eq("function_dig44")
+
+ let(:data) do
+ {
+ 'a' => {
+ 'g' => '2',
+ 'e' => [
+ 'f0',
+ 'f1',
+ {
+ 'x' => {
+ 'y' => 'z'
+ }
+ },
+ 'f3',
+ ]
+ },
+ 'b' => true,
+ 'c' => false,
+ 'd' => '1',
+ 'e' => :undef,
+ 'f' => nil,
+ }
end
- it "should raise a ParseError if there are less than 2 arguments" do
- expect { scope.function_dig44([]) }.to raise_error(Puppet::ParseError)
- end
+ context 'single values' do
+ it 'should exist' do
+ is_expected.not_to be_nil
+ end
- it "should raise a ParseError if the first argument isn't a hash or array" do
- expect { scope.function_dig44(['bad', []]) }.to raise_error(Puppet::ParseError)
- end
+ it 'should require two arguments' do
+ is_expected.to run.with_params().and_raise_error(ArgumentError)
+ end
- it "should raise a ParseError if the second argument isn't an array" do
- expect { scope.function_dig44([{}, 'bad']) }.to raise_error(Puppet::ParseError)
- end
+ it 'should fail if the data is not a structure' do
+ is_expected.to run.with_params('test', []).and_raise_error(Puppet::Error)
+ end
- it "should return an empty hash when given empty parameters" do
- result = scope.function_dig44([{}, []])
- expect(result).to(eq({}))
- end
+ it 'should fail if the path is not an array' do
+ is_expected.to run.with_params({}, '').and_raise_error(Puppet::Error)
+ end
- it "should return value when given simple hash" do
- result = scope.function_dig44([{"a" => "b"}, ["a"]])
- expect(result).to(eq("b"))
- end
+ it 'should return the value if the value is string' do
+ is_expected.to run.with_params(data, ['d'], 'default').and_return('1')
+ end
- it "should find hash values two levels deep" do
- result = scope.function_dig44([{"a" => {"b" => "c"}}, ["a", "b"]])
- expect(result).to(eq("c"))
- end
+ it 'should return true if the value is true' do
+ is_expected.to run.with_params(data, ['b'], 'default').and_return(true)
+ end
- it "should return default value if nothing was found" do
- result = scope.function_dig44([{}, ["a", "b"], "d"])
- expect(result).to(eq("d"))
+ it 'should return false if the value is false' do
+ is_expected.to run.with_params(data, ['c'], 'default').and_return(false)
+ end
+
+ it 'should return the default if the value is nil' do
+ is_expected.to run.with_params(data, ['f'], 'default').and_return('default')
+ end
+
+ it 'should return the default if the value is :undef (same as nil)' do
+ is_expected.to run.with_params(data, ['e'], 'default').and_return('default')
+ end
+
+ it 'should return the default if the path is not found' do
+ is_expected.to run.with_params(data, ['missing'], 'default').and_return('default')
+ end
end
- it "should work on booleans as well as strings" do
- result = scope.function_dig44([{"a" => false}, ["a"]])
- expect(result).to(eq(false))
+ context 'structure values' do
+
+ it 'should be able to extract a deeply nested hash value' do
+ is_expected.to run.with_params(data, %w(a g), 'default').and_return('2')
+ end
+
+ it 'should return the default value if the path is too long' do
+ is_expected.to run.with_params(data, %w(a g c d), 'default').and_return('default')
+ end
+
+ it 'should support an array index (number) in the path' do
+ is_expected.to run.with_params(data, ['a', 'e', 1], 'default').and_return('f1')
+ end
+
+ it 'should support an array index (string) in the path' do
+ is_expected.to run.with_params(data, %w(a e 1), 'default').and_return('f1')
+ end
+
+ it 'should return the default value if an array index is not a number' do
+ is_expected.to run.with_params(data, %w(a b c), 'default').and_return('default')
+ end
+
+ it 'should return the default value if and index is out of array length' do
+ is_expected.to run.with_params(data, %w(a e 5), 'default').and_return('default')
+ end
+
+ it 'should be able to path though both arrays and hashes' do
+ is_expected.to run.with_params(data, %w(a e 2 x y), 'default').and_return('z')
+ end
+
+ it 'should return "nil" if value is not found and no default value is provided' do
+ is_expected.to run.with_params(data, %w(a 1)).and_return(nil)
+ end
+
end
end
diff --git a/spec/functions/ensure_resource_spec.rb b/spec/functions/ensure_resource_spec.rb
index 9a17f5b..d552f4e 100755
--- a/spec/functions/ensure_resource_spec.rb
+++ b/spec/functions/ensure_resource_spec.rb
@@ -4,7 +4,12 @@ describe 'ensure_resource' do
it { is_expected.not_to eq(nil) }
it { is_expected.to run.with_params().and_raise_error(ArgumentError, /Must specify a type/) }
it { is_expected.to run.with_params('type').and_raise_error(ArgumentError, /Must specify a title/) }
- it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) }
+ if Puppet.version.to_f >= 4.6
+ it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(ArgumentError) }
+ else
+ it { is_expected.to run.with_params('type', 'title', {}, 'extras').and_raise_error(Puppet::ParseError) }
+ end
+
it {
pending("should not accept numbers as arguments")
is_expected.to run.with_params(1,2,3).and_raise_error(Puppet::ParseError)
diff --git a/spec/functions/getparam_spec.rb b/spec/functions/getparam_spec.rb
index 9e3d9e4..e4ef9e6 100755
--- a/spec/functions/getparam_spec.rb
+++ b/spec/functions/getparam_spec.rb
@@ -22,9 +22,6 @@ describe 'getparam' do
it { is_expected.to run.with_params('User[one]', 'ensure').and_return('present') }
it { is_expected.to run.with_params('User[two]', 'ensure').and_return('') }
it { is_expected.to run.with_params('User[one]', 'shell').and_return('/bin/sh') }
- it {
- pending("both rspec-puppet as well as the function do the wrong thing here.")
- is_expected.to run.with_params('User[one]', 'managehome').and_return(false)
- }
+ it { is_expected.to run.with_params('User[one]', 'managehome').and_return(false) }
end
end
diff --git a/spec/functions/getvar_spec.rb b/spec/functions/getvar_spec.rb
index 6ab137e..54f1842 100755
--- a/spec/functions/getvar_spec.rb
+++ b/spec/functions/getvar_spec.rb
@@ -6,6 +6,8 @@ describe 'getvar' do
it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
it { is_expected.to run.with_params().and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
+ it { is_expected.to run.with_params('$::foo').and_return(nil) }
+
context 'given variables in namespaces' do
let(:pre_condition) {
<<-'ENDofPUPPETcode'
diff --git a/spec/functions/is_array_spec.rb b/spec/functions/is_array_spec.rb
index 7dd21c2..e89f54b 100755
--- a/spec/functions/is_array_spec.rb
+++ b/spec/functions/is_array_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe 'is_array' 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) }
it {
@@ -16,4 +17,20 @@ describe 'is_array' do
it { is_expected.to run.with_params('one').and_return(false) }
it { is_expected.to run.with_params(1).and_return(false) }
it { is_expected.to run.with_params({}).and_return(false) }
+ context 'Checking for deprecation warning' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(['1.2.3.4']).and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(['1.2.3.4']).and_return(true)
+ end
+ end
end
diff --git a/spec/functions/is_bool_spec.rb b/spec/functions/is_bool_spec.rb
index 76d619b..d21345c 100755
--- a/spec/functions/is_bool_spec.rb
+++ b/spec/functions/is_bool_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe 'is_bool' 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) }
it { is_expected.to run.with_params(true, false).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
@@ -12,4 +13,21 @@ describe 'is_bool' do
it { is_expected.to run.with_params([true]).and_return(false) }
it { is_expected.to run.with_params('true').and_return(false) }
it { is_expected.to run.with_params('false').and_return(false) }
+ context 'Checking for deprecation warning' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(true).and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(false).and_return(true)
+ end
+ end
end
+
diff --git a/spec/functions/is_float_spec.rb b/spec/functions/is_float_spec.rb
index ffff971..af3322e 100755
--- a/spec/functions/is_float_spec.rb
+++ b/spec/functions/is_float_spec.rb
@@ -1,7 +1,9 @@
require 'spec_helper'
describe 'is_float' 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) }
it { is_expected.to run.with_params(0.1, 0.2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
@@ -19,4 +21,22 @@ describe 'is_float' do
it { is_expected.to run.with_params(1.0).and_return(true) }
it { is_expected.to run.with_params(1).and_return(false) }
end
+
+ context 'Checking for deprecation warning' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(2.2).and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(1.0).and_return(true)
+ end
+ end
+
end
diff --git a/spec/functions/is_integer_spec.rb b/spec/functions/is_integer_spec.rb
index 67263c1..b296830 100755
--- a/spec/functions/is_integer_spec.rb
+++ b/spec/functions/is_integer_spec.rb
@@ -1,7 +1,9 @@
require 'spec_helper'
describe 'is_integer' 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) }
it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
@@ -9,7 +11,7 @@ describe 'is_integer' do
it { is_expected.to run.with_params('3').and_return(true) }
it { is_expected.to run.with_params(-3).and_return(true) }
it { is_expected.to run.with_params('-3').and_return(true) }
-
+
it { is_expected.to run.with_params(3.7).and_return(false) }
it { is_expected.to run.with_params('3.7').and_return(false) }
it { is_expected.to run.with_params(-3.7).and_return(false) }
@@ -22,4 +24,22 @@ describe 'is_integer' do
it { is_expected.to run.with_params(true).and_return(false) }
it { is_expected.to run.with_params(false).and_return(false) }
it { is_expected.to run.with_params('0001234').and_return(false) }
+
+ context 'Checking for deprecation warning' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(50).and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(50).and_return(true)
+ end
+ end
+
end
diff --git a/spec/functions/is_ip_address_spec.rb b/spec/functions/is_ip_address_spec.rb
index a7a383a..39525d7 100755
--- a/spec/functions/is_ip_address_spec.rb
+++ b/spec/functions/is_ip_address_spec.rb
@@ -20,4 +20,21 @@ describe 'is_ip_address' do
it { is_expected.to run.with_params(1).and_return(false) }
it { is_expected.to run.with_params({}).and_return(false) }
it { is_expected.to run.with_params([]).and_return(false) }
+
+ context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.2.3.4').and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('1.2.3.4').and_return(true)
+ end
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ end
end
diff --git a/spec/functions/is_ipv4_address_spec.rb b/spec/functions/is_ipv4_address_spec.rb
new file mode 100644
index 0000000..985260c
--- /dev/null
+++ b/spec/functions/is_ipv4_address_spec.rb
@@ -0,0 +1,32 @@
+require 'spec_helper'
+
+describe 'is_ipv4_address' 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) }
+
+ SharedData::IPV4_PATTERNS.each do |value|
+ it { is_expected.to run.with_params(value).and_return(true) }
+ end
+
+ SharedData::IPV4_NEGATIVE_PATTERNS.each do |value|
+ it { is_expected.to run.with_params(value).and_return(false) }
+ end
+
+ context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first).and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first).and_return(true)
+ end
+ end
+end
diff --git a/spec/functions/is_ipv6_address_spec.rb b/spec/functions/is_ipv6_address_spec.rb
new file mode 100644
index 0000000..acd6a87
--- /dev/null
+++ b/spec/functions/is_ipv6_address_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe 'is_ipv6_address' 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) }
+ it { is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true) }
+ it { is_expected.to run.with_params('85a3:0000:0000:8a2e:0370:7334:100.100.100.100').and_return(true) }
+ it { is_expected.to run.with_params('1.2.3').and_return(false) }
+ it { is_expected.to run.with_params('1.2.3.4.5').and_return(false) }
+ it { is_expected.to run.with_params('').and_return(false) }
+ it { is_expected.to run.with_params('one').and_return(false) }
+
+ context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('2001:0db8:85a3:0000:0000:8a2e:0370:7334').and_return(true)
+ end
+ end
+end
diff --git a/spec/functions/is_numeric_spec.rb b/spec/functions/is_numeric_spec.rb
index d0f5a6e..5962d8a 100755
--- a/spec/functions/is_numeric_spec.rb
+++ b/spec/functions/is_numeric_spec.rb
@@ -1,7 +1,9 @@
require 'spec_helper'
describe 'is_numeric' 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) }
it { is_expected.to run.with_params(1, 2).and_raise_error(Puppet::ParseError, /wrong number of arguments/i) }
@@ -25,4 +27,22 @@ describe 'is_numeric' do
it { is_expected.to run.with_params(false).and_return(false) }
it { is_expected.to run.with_params('0001234').and_return(false) }
it { is_expected.to run.with_params(' - 1234').and_return(false) }
+
+ context 'Checking for deprecation warning' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(7).and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(7).and_return(true)
+ end
+ end
+
end
diff --git a/spec/functions/is_string_spec.rb b/spec/functions/is_string_spec.rb
index 8e459cc..e92f85c 100755
--- a/spec/functions/is_string_spec.rb
+++ b/spec/functions/is_string_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe 'is_string' 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) }
it {
@@ -25,4 +26,22 @@ describe 'is_string' do
it { is_expected.to run.with_params(false).and_return(false) }
it { is_expected.to run.with_params('one').and_return(true) }
it { is_expected.to run.with_params('0001234').and_return(true) }
+
+ context 'Checking for deprecation warning' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('sponge').and_return(true)
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('bob').and_return(true)
+ end
+ end
+
end
diff --git a/spec/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb
index 4a8404d..9397da5 100755
--- a/spec/functions/validate_absolute_path_spec.rb
+++ b/spec/functions/validate_absolute_path_spec.rb
@@ -1,6 +1,17 @@
require 'spec_helper'
describe 'validate_absolute_path' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ 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..409b3dc 100755
--- a/spec/functions/validate_array_spec.rb
+++ b/spec/functions/validate_array_spec.rb
@@ -1,8 +1,18 @@
require 'spec_helper'
describe 'validate_array' do
+
describe 'signature validation' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
it { is_expected.not_to eq(nil) }
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).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..3074d88 100755
--- a/spec/functions/validate_bool_spec.rb
+++ b/spec/functions/validate_bool_spec.rb
@@ -1,6 +1,17 @@
require 'spec_helper'
describe 'validate_bool' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ 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_hash_spec.rb b/spec/functions/validate_hash_spec.rb
index 2e8e59f..7533abe 100755
--- a/spec/functions/validate_hash_spec.rb
+++ b/spec/functions/validate_hash_spec.rb
@@ -5,6 +5,18 @@ describe 'validate_hash' 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) }
+ describe 'check for deprecation warning' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params({'key' => 'value'})
+ end
+ end
+
describe 'valid inputs' do
it { is_expected.to run.with_params({}) }
it { is_expected.to run.with_params({'key' => 'value'}) }
diff --git a/spec/functions/validate_integer_spec.rb b/spec/functions/validate_integer_spec.rb
index 4c0a9d7..6558d00 100755
--- a/spec/functions/validate_integer_spec.rb
+++ b/spec/functions/validate_integer_spec.rb
@@ -1,6 +1,17 @@
require 'spec_helper'
describe 'validate_integer' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(3)
+ 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_ip_address_spec.rb b/spec/functions/validate_ip_address_spec.rb
index b56ce51..0414f5e 100644
--- a/spec/functions/validate_ip_address_spec.rb
+++ b/spec/functions/validate_ip_address_spec.rb
@@ -1,6 +1,7 @@
require 'spec_helper'
describe 'validate_ip_address' do
+
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) }
@@ -19,6 +20,24 @@ describe 'validate_ip_address' do
it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
it { is_expected.to run.with_params('::1/64') }
it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+
+ context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1.2.3.4')
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('1.2.3.4')
+ end
+ end
+
context 'with netmasks' do
it { is_expected.to run.with_params('8.8.8.8/0') }
it { is_expected.to run.with_params('8.8.8.8/16') }
diff --git a/spec/functions/validate_ipv4_address_spec.rb b/spec/functions/validate_ipv4_address_spec.rb
index b6170d4..6e4ca05 100755
--- a/spec/functions/validate_ipv4_address_spec.rb
+++ b/spec/functions/validate_ipv4_address_spec.rb
@@ -1,40 +1,41 @@
require 'spec_helper'
describe 'validate_ipv4_address' do
+
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) }
+ end
- describe 'valid inputs' do
- it { is_expected.to run.with_params('0.0.0.0') }
- it { is_expected.to run.with_params('8.8.8.8') }
- it { is_expected.to run.with_params('127.0.0.1') }
- it { is_expected.to run.with_params('10.10.10.10') }
- it { is_expected.to run.with_params('194.232.104.150') }
- it { is_expected.to run.with_params('244.24.24.24') }
- it { is_expected.to run.with_params('255.255.255.255') }
- it { is_expected.to run.with_params('1.2.3.4', '5.6.7.8') }
- context 'with netmasks' do
- it { is_expected.to run.with_params('8.8.8.8/0') }
- it { is_expected.to run.with_params('8.8.8.8/16') }
- it { is_expected.to run.with_params('8.8.8.8/32') }
- it { is_expected.to run.with_params('8.8.8.8/255.255.0.0') }
- end
+ context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first)
end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first)
+ end
+ end
+
+ SharedData::IPV4_PATTERNS.each do |value|
+ it { is_expected.to run.with_params(value) }
+ end
+
+ SharedData::IPV4_NEGATIVE_PATTERNS.each do |value|
+ it { is_expected.to run.with_params(value).and_raise_error(Puppet::ParseError, /is not a valid IPv4/) }
+ end
- describe 'invalid inputs' do
- it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) }
- it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) }
- it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) }
- it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) }
- it { is_expected.to run.with_params('affe::beef').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) }
- it { is_expected.to run.with_params('1.2.3.4', {}).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params('1.2.3.4', 1).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params('1.2.3.4', true).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params('1.2.3.4', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv4/) }
+ describe 'invalid inputs' do
+ [ {}, [], 1, true ].each do |invalid|
+ it { is_expected.to run.with_params(invalid).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params(SharedData::IPV4_PATTERNS.first, invalid).and_raise_error(Puppet::ParseError, /is not a string/) }
end
end
end
diff --git a/spec/functions/validate_ipv6_address_spec.rb b/spec/functions/validate_ipv6_address_spec.rb
index 7aaf006..78810d4 100755
--- a/spec/functions/validate_ipv6_address_spec.rb
+++ b/spec/functions/validate_ipv6_address_spec.rb
@@ -1,32 +1,50 @@
require 'spec_helper'
describe 'validate_ipv6_address' do
+
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) }
+ end
- describe 'valid inputs' do
- it { is_expected.to run.with_params('3ffe:0505:0002::') }
- it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
- it { is_expected.to run.with_params('::1/64') }
- it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ context 'Checking for deprecation warning', if: Puppet.version.to_f < 4.0 do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+ # Checking for deprecation warning, which should only be provoked when the env variable for it is set.
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('3ffe:0505:0002::')
+ end
+ it 'should display no warning for deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "false"
+ scope.expects(:warning).with(includes('This method is deprecated')).never
+ is_expected.to run.with_params('3ffe:0505:0002::')
end
+ end
+
+ describe 'valid inputs' do
+ it { is_expected.to run.with_params('3ffe:0505:0002::') }
+ it { is_expected.to run.with_params('3ffe:0505:0002::', '3ffe:0505:0002::2') }
+ it { is_expected.to run.with_params('::1/64') }
+ it { is_expected.to run.with_params('fe80::a00:27ff:fe94:44d6/64') }
+ end
- describe 'invalid inputs' do
- it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
- it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
- it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
- it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
- it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
- it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
- context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do
- it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) }
- it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, /is not a string/) }
- end
+ describe 'invalid inputs' do
+ it { is_expected.to run.with_params({}).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params(true).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params('one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('0.0.0.256').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('0.0.0.0.0').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('affe:beef').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ it { is_expected.to run.with_params('::1', {}).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params('::1', true).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params('::1', 'one').and_raise_error(Puppet::ParseError, /is not a valid IPv6/) }
+ context 'unless running on ruby 1.8.7', :if => RUBY_VERSION != '1.8.7' do
+ it { is_expected.to run.with_params(1).and_raise_error(Puppet::ParseError, /is not a string/) }
+ it { is_expected.to run.with_params('::1', 1).and_raise_error(Puppet::ParseError, /is not a string/) }
end
end
end
diff --git a/spec/functions/validate_legacy_spec.rb b/spec/functions/validate_legacy_spec.rb
new file mode 100644
index 0000000..50cb317
--- /dev/null
+++ b/spec/functions/validate_legacy_spec.rb
@@ -0,0 +1,68 @@
+require 'spec_helper'
+
+if Puppet.version.to_f >= 4.0
+ describe 'validate_legacy' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params.and_raise_error(ArgumentError) }
+
+ describe 'when passing the type assertion and passing the previous validation' do
+ before do
+ scope.expects(:function_validate_foo).with([5]).once
+ Puppet.expects(:notice).never
+ end
+ it 'passes without notice' do
+ is_expected.to run.with_params('Integer', 'validate_foo', 5)
+ end
+ end
+
+ describe 'when passing the type assertion and failing the previous validation' do
+ before do
+ scope.expects(:function_validate_foo).with([5]).raises(Puppet::ParseError, 'foo').once
+ Puppet.expects(:notice).with(includes('Accepting previously invalid value for target type'))
+ end
+ it 'passes with a notice about newly accepted value' do
+ is_expected.to run.with_params('Integer', 'validate_foo', 5)
+ end
+ end
+
+ describe 'when failing the type assertion and passing the previous validation' do
+ before do
+ scope.expects(:function_validate_foo).with(['5']).once
+ subject.func.expects(:call_function).with('deprecation', 'validate_legacy', includes('Integer')).once
+ end
+ it 'passes with a deprecation message' do
+ is_expected.to run.with_params('Integer', 'validate_foo', '5')
+ end
+ end
+
+ describe 'when failing the type assertion and failing the previous validation' do
+ before do
+ scope.expects(:function_validate_foo).with(['5']).raises(Puppet::ParseError, 'foo').once
+ subject.func.expects(:call_function).with('fail', includes('Integer')).once
+ end
+ it 'fails with a helpful message' do
+ is_expected.to run.with_params('Integer', 'validate_foo', '5')
+ end
+ end
+
+ describe 'when passing in undef' do
+ before do
+ scope.expects(:function_validate_foo).with([:undef]).once
+ Puppet.expects(:notice).never
+ end
+ it 'works' do
+ is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef)
+ end
+ end
+
+ describe 'when passing in multiple arguments' do
+ before do
+ scope.expects(:function_validate_foo).with([:undef, 1, 'foo']).once
+ Puppet.expects(:notice).never
+ end
+ it 'passes with a deprecation message' do
+ is_expected.to run.with_params('Optional[Integer]', 'validate_foo', :undef, 1, 'foo')
+ end
+ end
+ end
+end
diff --git a/spec/functions/validate_numeric_spec.rb b/spec/functions/validate_numeric_spec.rb
index 9b8eb0e..4c0e24d 100755
--- a/spec/functions/validate_numeric_spec.rb
+++ b/spec/functions/validate_numeric_spec.rb
@@ -1,6 +1,17 @@
require 'spec_helper'
describe 'validate_numeric' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params(3)
+ 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..3531182 100755
--- a/spec/functions/validate_re_spec.rb
+++ b/spec/functions/validate_re_spec.rb
@@ -1,6 +1,17 @@
require 'spec_helper'
describe 'validate_re' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).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) }
@@ -17,22 +28,6 @@ describe 'validate_re' do
end
describe 'invalid inputs' do
- it {
- pending('should implement stricter type checking')
- is_expected.to run.with_params([], '').and_raise_error(Puppet::ParseError, /is not a String/)
- }
- it {
- pending('should implement stricter type checking')
- is_expected.to run.with_params('', {}).and_raise_error(Puppet::ParseError, /is not an Array/)
- }
- it {
- pending('should implement stricter type checking')
- is_expected.to run.with_params('', '', []).and_raise_error(Puppet::ParseError, /is not a String/)
- }
- it {
- pending('should implement stricter type checking')
- is_expected.to run.with_params(nil, nil).and_raise_error(Puppet::ParseError, /is not a String/)
- }
it { is_expected.to run.with_params('', []).and_raise_error(Puppet::ParseError, /does not match/) }
it { is_expected.to run.with_params('one', 'two').and_raise_error(Puppet::ParseError, /does not match/) }
it { is_expected.to run.with_params('', 'two').and_raise_error(Puppet::ParseError, /does not match/) }
diff --git a/spec/functions/validate_slength_spec.rb b/spec/functions/validate_slength_spec.rb
index 5a8fa6a..e4162de 100755
--- a/spec/functions/validate_slength_spec.rb
+++ b/spec/functions/validate_slength_spec.rb
@@ -1,6 +1,17 @@
require 'spec_helper'
describe 'validate_slength' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).with(includes('This method is deprecated'))
+ is_expected.to run.with_params('1234567890', 10)
+ 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..0907ede 100755
--- a/spec/functions/validate_string_spec.rb
+++ b/spec/functions/validate_string_spec.rb
@@ -1,12 +1,24 @@
require 'spec_helper'
describe 'validate_string' do
+ after(:all) do
+ ENV.delete('STDLIB_LOG_DEPRECATIONS')
+ end
+
+ # Checking for deprecation warning
+ it 'should display a single deprecation' do
+ ENV['STDLIB_LOG_DEPRECATIONS'] = "true"
+ scope.expects(:warning).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) }
describe 'valid inputs' do
it { is_expected.to run.with_params('') }
+ it { is_expected.to run.with_params(nil) }
it { is_expected.to run.with_params('one') }
it { is_expected.to run.with_params('one', 'two') }
end
diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb
index 023a862..616490c 100644
--- a/spec/spec_helper_local.rb
+++ b/spec/spec_helper_local.rb
@@ -1,3 +1,5 @@
+# automatically load any shared examples or contexts
+Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
# hack to enable all the expect syntax (like allow_any_instance_of) in rspec-puppet examples
RSpec::Mocks::Syntax.enable_expect(RSpec::Puppet::ManifestMatchers)
diff --git a/spec/support/shared_data.rb b/spec/support/shared_data.rb
new file mode 100644
index 0000000..ea9b7a0
--- /dev/null
+++ b/spec/support/shared_data.rb
@@ -0,0 +1,38 @@
+module SharedData
+ IPV4_PATTERNS = [
+ '0.0.0.0',
+ '1.2.3.4',
+ '10.10.10.10',
+ '127.0.0.1',
+ '192.88.99.0',
+ '194.232.104.150',
+ '224.0.0.0',
+ '244.24.24.24',
+ '255.255.255.255',
+ '8.8.8.8',
+ '8.8.8.8/0',
+ '8.8.8.8/16',
+ '8.8.8.8/255.255.0.0',
+ '8.8.8.8/32',
+ ]
+ IPV4_NEGATIVE_PATTERNS = [
+ '',
+ '0000',
+ '0.0.0.0.',
+ '0.0.0.0./0.0.0.0.',
+ '0.0.0.0./1',
+ '0.0.0.0.0',
+ '0.0.0.0/0.0.0.0.',
+ '0.0.0.256',
+ '0.0.0',
+ '1.2.3.4.5',
+ '1.2.3',
+ '10.010.10.10',
+ '2001:0db8:85a3:0000:0000:8a2e:0370:73342001:0db8:85a3:0000:0000:8a2e:0370:7334',
+ '4.4.4',
+ '77',
+ '9999.9999.9999.9999',
+ 'affe::beef',
+ 'nope',
+ ]
+end
diff --git a/spec/unit/puppet/provider/file_line/ruby_spec.rb b/spec/unit/puppet/provider/file_line/ruby_spec.rb
index fdeaf1a..1f41f62 100755
--- a/spec/unit/puppet/provider/file_line/ruby_spec.rb
+++ b/spec/unit/puppet/provider/file_line/ruby_spec.rb
@@ -363,6 +363,13 @@ describe provider_class do
@provider = provider_class.new(@resource)
end
+ it 'should find a line to match' do
+ File.open(@tmpfile, 'w') do |fh|
+ fh.write("foo1\nfoo\nfoo2")
+ end
+ expect(@provider.exists?).to be_truthy
+ end
+
it 'should remove one line if it matches' do
File.open(@tmpfile, 'w') do |fh|
fh.write("foo1\nfoo\nfoo2")
diff --git a/types/absolutepath.pp b/types/absolutepath.pp
new file mode 100644
index 0000000..70ec916
--- /dev/null
+++ b/types/absolutepath.pp
@@ -0,0 +1,2 @@
+# A strict absolutepath type
+type Stdlib::Absolutepath = Variant[Stdlib::Windowspath, Stdlib::Unixpath]
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..5d8e27e
--- /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/float.pp b/types/compat/float.pp
new file mode 100644
index 0000000..7f98bd2
--- /dev/null
+++ b/types/compat/float.pp
@@ -0,0 +1,19 @@
+# Emulate the is_float function
+# The regex is what's currently used in is_float
+# To keep your development moving forward, you can also add a deprecation warning using the Integer type:
+#
+# ```class example($value) { validate_float($value,) }```
+#
+# would turn into
+#
+# ```
+# class example(Stdlib::Compat::Float $value) {
+# validate_float($value, 10, 0)
+# assert_type(Integer[0, 10], $value) |$expected, $actual| {
+# warning("The 'value' parameter for the 'ntp' class has type ${actual}, but should be ${expected}.")
+# }
+# }
+# ```
+#
+# This allows you to find all places where a consumers of your code call it with unexpected values.
+type Stdlib::Compat::Float = Variant[Float, Pattern[/^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)(?:[eE]-?\d+)?$/]]
diff --git a/types/compat/integer.pp b/types/compat/integer.pp
new file mode 100644
index 0000000..e5cadb6
--- /dev/null
+++ b/types/compat/integer.pp
@@ -0,0 +1,23 @@
+# Emulate the is_integer and validate_integer functions
+# The regex is what's currently used in is_integer
+# validate_numeric also allows range checking, which cannot be mapped to the string parsing inside the function.
+# For full backwards compatibility, you will need to keep the validate_numeric call around to catch everything.
+# To keep your development moving forward, you can also add a deprecation warning using the Integer type:
+#
+# ```class example($value) { validate_integer($value, 10, 0) }```
+#
+# would turn into
+#
+# ```
+# class example(Stdlib::Compat::Integer $value) {
+# validate_numeric($value, 10, 0)
+# assert_type(Integer[0, 10], $value) |$expected, $actual| {
+# warning("The 'value' parameter for the 'ntp' class has type ${actual}, but should be ${expected}.")
+# }
+# }
+# ```
+#
+# > Note that you need to use Variant[Integer[0, 10], Float[0, 10]] if you want to match both integers and floating point numbers.
+#
+# This allows you to find all places where a consumers of your code call it with unexpected values.
+type Stdlib::Compat::Integer = Variant[Integer, Pattern[/^-?(?:(?:[1-9]\d*)|0)$/], Array[Variant[Integer, Pattern[/^-?(?:(?:[1-9]\d*)|0)$/]]]]
diff --git a/types/compat/ip_address.pp b/types/compat/ip_address.pp
new file mode 100644
index 0000000..bf4c4b4
--- /dev/null
+++ b/types/compat/ip_address.pp
@@ -0,0 +1 @@
+type Stdlib::Compat::Ip_address = Variant[Stdlib::Compat::Ipv4, Stdlib::Compat::Ipv6]
diff --git a/types/compat/ipv4.pp b/types/compat/ipv4.pp
new file mode 100644
index 0000000..a0ba0d6
--- /dev/null
+++ b/types/compat/ipv4.pp
@@ -0,0 +1,2 @@
+# Emulate the validate_ipv4_address and is_ipv4_address functions
+type Stdlib::Compat::Ipv4 = Pattern[/^((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d)))(\/((([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))[.]){3}([0-9](?!\d)|[1-9][0-9](?!\d)|1[0-9]{2}(?!\d)|2[0-4][0-9](?!\d)|25[0-5](?!\d))|[0-9]+))?$/]
diff --git a/types/compat/ipv6.pp b/types/compat/ipv6.pp
new file mode 100644
index 0000000..18b148d
--- /dev/null
+++ b/types/compat/ipv6.pp
@@ -0,0 +1 @@
+type Stdlib::Compat::Ipv6 = Pattern[/^(?:(?:[\da-f]{1,4}:){7}[\da-f]{1,4}|((?:[\da-f]{1,4}:){6})(\d+)\.(\d+)\.(\d+)\.(\d+))$/]
diff --git a/types/compat/numeric.pp b/types/compat/numeric.pp
new file mode 100644
index 0000000..5bfc3d3
--- /dev/null
+++ b/types/compat/numeric.pp
@@ -0,0 +1,23 @@
+# Emulate the is_numeric and validate_numeric functions
+# The regex is what's currently used in is_numeric
+# validate_numeric also allows range checking, which cannot be mapped to the string parsing inside the function.
+# For full backwards compatibility, you will need to keep the validate_numeric call around to catch everything.
+# To keep your development moving forward, you can also add a deprecation warning using the Integer type:
+#
+# ```class example($value) { validate_numeric($value, 10, 0) }```
+#
+# would turn into
+#
+# ```
+# class example(Stdlib::Compat::Numeric $value) {
+# validate_numeric($value, 10, 0)
+# assert_type(Integer[0, 10], $value) |$expected, $actual| {
+# warning("The 'value' parameter for the 'ntp' class has type ${actual}, but should be ${expected}.")
+# }
+# }
+# ```
+#
+# > Note that you need to use Variant[Integer[0, 10], Float[0, 10]] if you want to match both integers and floating point numbers.
+#
+# This allows you to find all places where a consumers of your code call it with unexpected values.
+type Stdlib::Compat::Numeric = Variant[Numeric, Pattern[/^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$/], Array[Variant[Numeric, Pattern[/^-?(?:(?:[1-9]\d*)|0)(?:\.\d+)?(?:[eE]-?\d+)?$/]]]]
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..b06255d
--- /dev/null
+++ b/types/compat/string.pp
@@ -0,0 +1,2 @@
+# Emulate the is_string and validate_string functions
+type Stdlib::Compat::String = Optional[String]
diff --git a/types/httpsurl.pp b/types/httpsurl.pp
new file mode 100644
index 0000000..36fd30f
--- /dev/null
+++ b/types/httpsurl.pp
@@ -0,0 +1 @@
+type Stdlib::HTTPSUrl = Pattern[/^https:\/\//]
diff --git a/types/httpurl.pp b/types/httpurl.pp
new file mode 100644
index 0000000..0d93a95
--- /dev/null
+++ b/types/httpurl.pp
@@ -0,0 +1 @@
+type Stdlib::HTTPUrl = Pattern[/^https?:\/\//]
diff --git a/types/unixpath.pp b/types/unixpath.pp
new file mode 100644
index 0000000..76f2c17
--- /dev/null
+++ b/types/unixpath.pp
@@ -0,0 +1,2 @@
+# this regex rejects any path component that is a / or a NUL
+type Stdlib::Unixpath = Pattern[/^\/([^\/\0]+(\/)?)+$/]
diff --git a/types/windowspath.pp b/types/windowspath.pp
new file mode 100644
index 0000000..bc1ee9c
--- /dev/null
+++ b/types/windowspath.pp
@@ -0,0 +1 @@
+type Stdlib::Windowspath = Pattern[/^(([a-zA-Z]:[\\\/])|([\\\/][\\\/][^\\\/]+[\\\/][^\\\/]+)|([\\\/][\\\/]\?[\\\/][^\\\/]+))/]