Skip to content

Commit b46508d

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

File tree

8 files changed

+45
-4
lines changed

8 files changed

+45
-4
lines changed

Diff for: lib/puppet/info_service.rb

+1
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

Diff for: lib/puppet/info_service/class_information_service.rb

+4
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)

Diff for: lib/puppet/pops/evaluator/literal_evaluator.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module Evaluator
1313
# Regular Expression (produces ruby regular expression)
1414
#
1515
# Not considered literal
16-
# QualifiedReference # i.e. File, FooBar
16+
# QualifiedReference # i.e. File, FooBar # REMOVE THIS?
1717
#
1818
class LiteralEvaluator
1919

@@ -28,6 +28,7 @@ def literal(ast)
2828
end
2929

3030
def literal_Object(o)
31+
#require 'byebug'; byebug
3132
throw :not_literal
3233
end
3334

@@ -40,6 +41,7 @@ def literal_Program(o)
4041
end
4142

4243
def literal_LiteralString(o)
44+
#require 'byebug'; byebug if $DEBUG
4345
o.value
4446
end
4547

@@ -48,6 +50,7 @@ def literal_QualifiedName(o)
4850
end
4951

5052
def literal_LiteralNumber(o)
53+
#require 'byebug'; byebug
5154
o.value
5255
end
5356

@@ -67,6 +70,17 @@ def literal_LiteralRegularExpression(o)
6770
o.value
6871
end
6972

73+
def literal_QualifiedReference(o)
74+
#require 'pry-byebug'; binding.pry
75+
o.value
76+
end
77+
78+
def literal_AccessExpression(o)
79+
#require 'byebug'; byebug
80+
throw :not_literal if o.keys.size == 1 && o.keys[0].is_a?(Model::LiteralList)
81+
o.keys.map {|v| literal(v) }
82+
end
83+
7084
def literal_ConcatenatedString(o)
7185
# use double quoted string value if there is no interpolation
7286
throw :not_literal unless o.segments.size == 1 && o.segments[0].is_a?(Model::LiteralString)

Diff for: lib/puppet/pops/issues.rb

+4
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.

Diff for: lib/puppet/pops/validation/checker4_0.rb

+14
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,19 @@ def check_ResourceTypeDefinition(o)
481482
internal_check_no_idem_last(o)
482483
end
483484

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

Diff for: lib/puppet/pops/visitor.rb

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def visit_this_class(receiver, clazz, args)
7979
# (This is ~30% faster than calling the general method)
8080
#
8181
def visit_this_0(receiver, thing)
82+
#require 'byebug'; byebug
8283
method_name = @cache[thing.class]
8384
if method_name
8485
return receiver.send(method_name, thing)

Diff for: spec/unit/info_service_spec.rb

+2-1
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({

Diff for: spec/unit/pops/evaluator/literal_evaluator_spec.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
'"a"' => 'a',
1717
'a' => 'a',
1818
'a::b' => 'a::b',
19+
'Integer[1]' => [1],
20+
'File' => "file",
1921

2022
# special values
2123
'default' => :default,
@@ -35,9 +37,9 @@
3537
expect(leval.literal(parser.parse_string('undef'))).to be_nil
3638
end
3739

38-
['1+1', 'File', '[1,2, 1+2]', '{a=>1+1}', 'Integer[1]', '"x$y"', '"x${y}z"'].each do |source|
40+
['1+1', '[1,2, 1+2]', '{a=>1+1}', '"x$y"', '"x${y}z"', 'Integer[1-3]', 'Optional[[String]]'].each do |source|
3941
it "throws :not_literal for non literal expression '#{source}'" do
40-
expect{leval.literal(parser.parse_string('1+1'))}.to throw_symbol(:not_literal)
42+
expect{leval.literal(parser.parse_string(source))}.to throw_symbol(:not_literal)
4143
end
4244
end
4345
end

0 commit comments

Comments
 (0)