Skip to content

Commit 8992763

Browse files
committed
(PUP-11981) Add test for non-literal class params in ClassInfoService spec
1 parent 838a496 commit 8992763

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/puppet/pops/evaluator/literal_evaluator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def literal_QualifiedReference(o)
7373
def literal_AccessExpression(o)
7474
# to prevent parameters with [[]] like Optional[[String]]
7575
throw :not_literal if o.keys.size == 1 && o.keys[0].is_a?(Model::LiteralList)
76-
o.keys.map {|v| literal(v) }
76+
o.keys.map { |v| literal(v) }
7777
end
7878

7979
def literal_ConcatenatedString(o)

lib/puppet/pops/validation/checker4_0.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ def internal_check_parameter_type_literal(o)
491491
catch :not_literal do
492492
type = literal(p.type_expr)
493493
end
494-
acceptor.accept(Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE, p, {name: p.name, type_class: p.type_expr.class}) if type.nil?
494+
acceptor.accept(Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE, p, { name: p.name, type_class: p.type_expr.class }) if type.nil?
495495
end
496496
end
497497

spec/unit/info_service_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,12 @@ class Borked($Herp+$Derp) {}
313313
CODE
314314
'json_unsafe.pp' => <<-CODE,
315315
class json_unsafe($arg1 = /.*/, $arg2 = default, $arg3 = {1 => 1}) {}
316+
CODE
317+
'non_literal.pp' => <<-CODE,
318+
class oops(Integer[1-3] $bad_int) { }
319+
CODE
320+
'non_literal_2.pp' => <<-CODE,
321+
class oops_2(Optional[[String]] $double_brackets) { }
316322
CODE
317323
})
318324
end
@@ -509,6 +515,19 @@ class json_unsafe($arg1 = /.*/, $arg2 = default, $arg3 = {1 => 1}) {}
509515
})
510516
end
511517

518+
it "errors 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+
result = Puppet::InfoService.classes_per_environment({'production' => files })
521+
expect(result).to eq({
522+
"production"=>{
523+
"#{code_dir}/non_literal.pp" =>
524+
{:error=> "The parameter '$bad_int' must be a literal type, not a Puppet::Pops::Model::AccessExpression (file: #{code_dir}/non_literal.pp, line: 1, column: 37)"},
525+
"#{code_dir}/non_literal_2.pp" =>
526+
{:error=> "The parameter '$double_brackets' must be a literal type, not a Puppet::Pops::Model::AccessExpression (file: #{code_dir}/non_literal_2.pp, line: 1, column: 44)"}
527+
} # end production env
528+
})
529+
end
530+
512531
it "produces no type entry if type is not given" do
513532
files = ['fum.pp'].map {|f| File.join(code_dir, f) }
514533
result = Puppet::InfoService.classes_per_environment({'production' => files })

0 commit comments

Comments
 (0)