Skip to content

Commit c3054b4

Browse files
committed
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.
1 parent d34b227 commit c3054b4

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

lib/puppet/pops/validation/validator_factory_4_0.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ def severity_producer
3636
p[Issues::NAME_WITH_HYPHEN] = :error
3737
p[Issues::EMPTY_RESOURCE_SPECIALIZATION] = :ignore
3838
p[Issues::CLASS_NOT_VIRTUALIZABLE] = :error
39+
40+
p[Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE] = Puppet[:strict] == :off ? :ignore : Puppet[:strict]
3941
p
4042
end
4143
end

spec/unit/pops/validator/validator_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ def with_environment(environment, env_params = {})
211211
expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_TOP_CONSTRUCT_LOCATION)
212212
end
213213
end
214+
215+
it 'produces a warning for non-literal class parameters' do
216+
acceptor = validate(parse('class test(Integer[2-1] $port) {}'))
217+
expect(acceptor.warning_count).to eql(1)
218+
expect(acceptor.error_count).to eql(0)
219+
expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE)
220+
end
214221
end
215222

216223
context 'with --strict set to error' do
@@ -262,6 +269,13 @@ def with_environment(environment, env_params = {})
262269
expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_TOP_CONSTRUCT_LOCATION)
263270
end
264271
end
272+
273+
it 'produces an error for non-literal class parameters' do
274+
acceptor = validate(parse('class test(Integer[2-1] $port) {}'))
275+
expect(acceptor.warning_count).to eql(0)
276+
expect(acceptor.error_count).to eql(1)
277+
expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE)
278+
end
265279
end
266280

267281
context 'with --strict set to off' do
@@ -292,6 +306,13 @@ def with_environment(environment, env_params = {})
292306
expect(acceptor).to have_issue(Puppet::Pops::Issues::ILLEGAL_TOP_CONSTRUCT_LOCATION)
293307
end
294308
end
309+
310+
it 'does not produce an error or warning for non-literal class parameters' do
311+
acceptor = validate(parse('class test(Integer[2-1] $port) {}'))
312+
expect(acceptor.warning_count).to eql(0)
313+
expect(acceptor.error_count).to eql(0)
314+
expect(acceptor).to_not have_issue(Puppet::Pops::Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE)
315+
end
295316
end
296317

297318
context 'irrespective of --strict' do

0 commit comments

Comments
 (0)