From 83ed38b9c379bab4351bf8339e443ad92a4c3ccd Mon Sep 17 00:00:00 2001 From: Josh Cooper Date: Tue, 27 Feb 2024 16:41:36 -0800 Subject: [PATCH] Allow non-literal parameter type issue to be controlled by strict If strict is off, the issue will be ignored. If strict is warning, then a warning will be reported, but compilation will continue: Warning: The parameter '$i' must be a literal type, not a Puppet::Pops::Model::AccessExpression If strict is error, then compilation will fail. --- .../pops/validation/validator_factory_4_0.rb | 2 ++ spec/unit/pops/validator/validator_spec.rb | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/lib/puppet/pops/validation/validator_factory_4_0.rb b/lib/puppet/pops/validation/validator_factory_4_0.rb index d103c94b74d..7cab8348abc 100644 --- a/lib/puppet/pops/validation/validator_factory_4_0.rb +++ b/lib/puppet/pops/validation/validator_factory_4_0.rb @@ -36,6 +36,8 @@ def severity_producer p[Issues::NAME_WITH_HYPHEN] = :error p[Issues::EMPTY_RESOURCE_SPECIALIZATION] = :ignore p[Issues::CLASS_NOT_VIRTUALIZABLE] = :error + + p[Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE] = Puppet[:strict] == :off ? :ignore : Puppet[:strict] p end end diff --git a/spec/unit/pops/validator/validator_spec.rb b/spec/unit/pops/validator/validator_spec.rb index 5e54702a6db..037804ff7a7 100644 --- a/spec/unit/pops/validator/validator_spec.rb +++ b/spec/unit/pops/validator/validator_spec.rb @@ -211,6 +211,13 @@ def with_environment(environment, env_params = {}) expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_TOP_CONSTRUCT_LOCATION) end end + + it 'produces a warning for non-literal class parameters' do + acceptor = validate(parse('class test(Integer[2-1] $port) {}')) + expect(acceptor.warning_count).to eql(1) + expect(acceptor.error_count).to eql(0) + expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE) + end end context 'with --strict set to error' do @@ -262,6 +269,13 @@ def with_environment(environment, env_params = {}) expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_TOP_CONSTRUCT_LOCATION) end end + + it 'produces an error for non-literal class parameters' do + acceptor = validate(parse('class test(Integer[2-1] $port) {}')) + expect(acceptor.warning_count).to eql(0) + expect(acceptor.error_count).to eql(1) + expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE) + end end context 'with --strict set to off' do @@ -292,6 +306,13 @@ def with_environment(environment, env_params = {}) expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_TOP_CONSTRUCT_LOCATION) end end + + it 'does not produce an error or warning for non-literal class parameters' do + acceptor = validate(parse('class test(Integer[2-1] $port) {}')) + expect(acceptor.warning_count).to eql(0) + expect(acceptor.error_count).to eql(0) + expect(acceptor).to_not have_issue(Puppet::Pops::Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE) + end end context 'irrespective of --strict' do