Skip to content

Commit

Permalink
(PUP-514) Check for slurp arguments in EPP
Browse files Browse the repository at this point in the history
EPP, because it uses named parameters, does not support using slurped
(captures rest) parameters. This adds a static check to catch that being
done.
  • Loading branch information
zaphod42 committed Jun 12, 2014
1 parent ff0e7c1 commit 4fc507d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/puppet/pops/validation/checker4_0.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ def check_CallNamedFunctionExpression(o)
end
end

def check_EppExpression(o)
if o.eContainer.is_a?(Puppet::Pops::Model::LambdaExpression)
internal_check_no_capture(o.eContainer, o)
end
end

def check_MethodCallExpression(o)
unless o.functor_expr.is_a? Model::QualifiedName
acceptor.accept(Issues::ILLEGAL_EXPRESSION, o.functor_expr, :feature => 'function name', :container => o)
Expand Down Expand Up @@ -269,10 +275,10 @@ def internal_check_capture_last(o)
end
end

def internal_check_no_capture(o)
def internal_check_no_capture(o, container = o)
o.parameters.each_with_index do |p, index|
if p.captures_rest
acceptor.accept(Issues::CAPTURES_REST_NOT_SUPPORTED, p, {:container => o, :param_name => p.name})
acceptor.accept(Issues::CAPTURES_REST_NOT_SUPPORTED, p, {:container => container, :param_name => p.name})
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions spec/unit/parser/functions/epp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
expect(eval_template_with_args("<%-|String $x|-%><%= $x == correct %>", 'x' => 'correct')).to eq("true")
end

it "does not allow slurped parameters" do
expect do
eval_template_with_args("<%-|*$x|-%><%= $x %>", 'x' => 'incorrect')
end.to raise_error(/'captures rest' - not supported in an Epp Template/)
end

it "raises an error when the passed value does not match the parameter's type" do
expect do
eval_template_with_args("<%-|Integer $x|-%><%= $x %>", 'x' => 'incorrect')
Expand Down

0 comments on commit 4fc507d

Please sign in to comment.