Skip to content

Commit 5f804e2

Browse files
committed
(PUP-11981) WIP
1 parent 775592c commit 5f804e2

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

lib/puppet/info_service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module Puppet::InfoService
66
require_relative 'info_service/plan_information_service'
77

88
def self.classes_per_environment(env_file_hash)
9+
#require 'pry-byebug'; binding.pry
910
Puppet::InfoService::ClassInformationService.new.classes_per_environment(env_file_hash)
1011
end
1112

lib/puppet/info_service/class_information_service.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def classes_per_environment(env_file_hash)
2626
# if file already processed, use last result or error
2727
#
2828
env_file_hash.each do |env, files|
29+
#require 'pry-byebug'; binding.pry
2930
env_result = result[env] = {}
3031
files.each do |f|
3132
env_result[f] = result_of(f)
@@ -56,6 +57,7 @@ def parse_file(f)
5657
return {:error => _("The file %{f} does not exist") % { f: f }} unless Puppet::FileSystem.exist?(f)
5758

5859
begin
60+
#require 'pry-byebug'; binding.pry
5961
parse_result = @parser.parse_file(f)
6062
{:classes =>
6163
parse_result.definitions.select {|d| d.is_a?(Puppet::Pops::Model::HostClassDefinition)}.map do |d|
@@ -77,9 +79,11 @@ def extract_type(structure, p)
7779
return structure if p.type_expr.nil?
7880
structure[:type] = typeexpr_to_string(p.type_expr)
7981
structure
82+
# require 'pry-byebug'; binding.pry
8083
end
8184

8285
def extract_default(structure, p)
86+
# require 'pry-byebug'; binding.pry
8387
value_expr = p.value
8488
return structure if value_expr.nil?
8589
default_value = value_as_literal(value_expr)

lib/puppet/pops/evaluator/literal_evaluator.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def literal_Program(o)
4040
end
4141

4242
def literal_LiteralString(o)
43+
#require 'pry-byebug'; binding.pry
4344
o.value
4445
end
4546

@@ -67,6 +68,11 @@ def literal_LiteralRegularExpression(o)
6768
o.value
6869
end
6970

71+
def literal_QualifiedReference(o)
72+
#require 'pry-byebug'; binding.pry
73+
o.value
74+
end
75+
7076
def literal_ConcatenatedString(o)
7177
# use double quoted string value if there is no interpolation
7278
throw :not_literal unless o.segments.size == 1 && o.segments[0].is_a?(Model::LiteralString)

lib/puppet/pops/issues.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,10 @@ def self.hard_issue(issue_code, *args, &block)
207207
_("The numeric parameter name '$%{name}' cannot be used (clashes with numeric match result variables)") % { name: name }
208208
end
209209

210+
ILLEGAL_NONLITERAL_PARAMETER_TYPE = issue :ILLEGAL_NONLITERAL_PARAMETER_TYPE, :name, :type_class do
211+
_("The parameter '$%{name}' must be a literal type, not %{type_class}") % { name: name, type_class: label.a_an(type_class) }
212+
end
213+
210214
# In certain versions of Puppet it may be allowed to assign to a not already assigned key
211215
# in an array or a hash. This is an optional validation that may be turned on to prevent accidental
212216
# mutation.

lib/puppet/pops/validation/checker4_0.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ def check_HostClassDefinition(o)
471471
internal_check_parameter_name_uniqueness(o)
472472
internal_check_reserved_params(o)
473473
internal_check_no_idem_last(o)
474+
internal_check_parameter_type_literal(o)
474475
end
475476

476477
def check_ResourceTypeDefinition(o)
@@ -481,6 +482,18 @@ def check_ResourceTypeDefinition(o)
481482
internal_check_no_idem_last(o)
482483
end
483484

485+
def internal_check_parameter_type_literal(o)
486+
o.parameters.each do |p|
487+
next unless p.type_expr
488+
catch :not_literal do
489+
#require 'pry-byebug'; binding.pry
490+
literal(p.type_expr)
491+
next
492+
end
493+
acceptor.accept(Issues::ILLEGAL_NONLITERAL_PARAMETER_TYPE, p, {name: p.name, type_class: p.type_expr.class})
494+
end
495+
end
496+
484497
def internal_check_return_type(o)
485498
r = o.return_type
486499
internal_check_type_ref(o, r) unless r.nil?

spec/unit/info_service_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class Borked($Herp+$Derp) {}
313313
CODE
314314
'json_unsafe.pp' => <<-CODE,
315315
class json_unsafe($arg1 = /.*/, $arg2 = default, $arg3 = {1 => 1}) {}
316-
CODE
316+
CODE
317317
})
318318
end
319319

@@ -326,6 +326,7 @@ class json_unsafe($arg1 = /.*/, $arg2 = default, $arg3 = {1 => 1}) {}
326326
end
327327

328328
it "produces classes and parameters from a given file" do
329+
#require 'pry-byebug'; binding.pry
329330
files = ['foo.pp'].map {|f| File.join(code_dir, f) }
330331
result = Puppet::InfoService.classes_per_environment({'production' => files })
331332
expect(result).to eq({

0 commit comments

Comments
 (0)