Skip to content

Commit 8cb167d

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 6c85333 commit 8cb167d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
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/info_service_spec.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,15 @@ class oops_2(Optional[[String]] $double_brackets) { }
515515
})
516516
end
517517

518-
it "errors with a descriptive message if non-literal class parameter is given" do
518+
it "warns with a descriptive message if non-literal class parameter is given" do
519+
files = ['non_literal.pp', 'non_literal_2.pp'].map {|f| File.join(code_dir, f) }
520+
Puppet::InfoService.classes_per_environment({'production' => files })
521+
expect(@logs).to include(an_object_having_attributes(message: "The parameter '$bad_int' must be a literal type, not a Puppet::Pops::Model::AccessExpression"))
522+
expect(@logs).to include(an_object_having_attributes(message: "The parameter '$double_brackets' must be a literal type, not a Puppet::Pops::Model::AccessExpression"))
523+
end
524+
525+
it "errors in strict mode if non-literal class parameter is given" do
526+
Puppet[:strict] = "error"
519527
files = ['non_literal.pp', 'non_literal_2.pp'].map {|f| File.join(code_dir, f) }
520528
result = Puppet::InfoService.classes_per_environment({'production' => files })
521529
expect(result).to eq({

spec/unit/pops/validator/validator_spec.rb

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

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

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

298319
context 'irrespective of --strict' do

0 commit comments

Comments
 (0)