puppet 3.7.4 → 3.7.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of puppet might be problematic. Click here for more details.

Files changed (115) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.md +11 -6
  3. data/ext/build_defaults.yaml +2 -2
  4. data/ext/systemd/puppet.service +1 -0
  5. data/lib/hiera/puppet_function.rb +71 -0
  6. data/lib/puppet.rb +12 -0
  7. data/lib/puppet/application/device.rb +22 -5
  8. data/lib/puppet/daemon.rb +13 -4
  9. data/lib/puppet/defaults.rb +27 -4
  10. data/lib/puppet/environments.rb +1 -1
  11. data/lib/puppet/error.rb +4 -0
  12. data/lib/puppet/functions.rb +118 -65
  13. data/lib/puppet/functions/assert_type.rb +5 -5
  14. data/lib/puppet/functions/each.rb +12 -12
  15. data/lib/puppet/functions/epp.rb +3 -4
  16. data/lib/puppet/functions/filter.rb +12 -12
  17. data/lib/puppet/functions/hiera.rb +29 -0
  18. data/lib/puppet/functions/hiera_array.rb +34 -0
  19. data/lib/puppet/functions/hiera_hash.rb +36 -0
  20. data/lib/puppet/functions/hiera_include.rb +50 -0
  21. data/lib/puppet/functions/inline_epp.rb +2 -3
  22. data/lib/puppet/functions/map.rb +12 -12
  23. data/lib/puppet/functions/reduce.rb +6 -6
  24. data/lib/puppet/functions/scanf.rb +3 -3
  25. data/lib/puppet/functions/slice.rb +10 -9
  26. data/lib/puppet/functions/with.rb +3 -4
  27. data/lib/puppet/graph/simple_graph.rb +5 -5
  28. data/lib/puppet/metatype/manager.rb +1 -1
  29. data/lib/puppet/node/environment.rb +1 -1
  30. data/lib/puppet/parser/ast/arithmetic_operator.rb +1 -1
  31. data/lib/puppet/parser/ast/collexpr.rb +1 -1
  32. data/lib/puppet/parser/compiler.rb +3 -3
  33. data/lib/puppet/parser/functions/create_resources.rb +1 -9
  34. data/lib/puppet/parser/functions/defined.rb +1 -1
  35. data/lib/puppet/parser/functions/hiera.rb +20 -11
  36. data/lib/puppet/parser/functions/hiera_array.rb +23 -13
  37. data/lib/puppet/parser/functions/hiera_hash.rb +25 -15
  38. data/lib/puppet/parser/functions/hiera_include.rb +20 -9
  39. data/lib/puppet/parser/functions/lookup.rb +1 -1
  40. data/lib/puppet/parser/functions/realize.rb +1 -1
  41. data/lib/puppet/parser/functions/scanf.rb +21 -12
  42. data/lib/puppet/parser/parser_factory.rb +2 -2
  43. data/lib/puppet/parser/relationship.rb +1 -1
  44. data/lib/puppet/parser/scope.rb +34 -7
  45. data/lib/puppet/pops.rb +2 -0
  46. data/lib/puppet/pops/binder/lookup.rb +24 -7
  47. data/lib/puppet/pops/binder/producers.rb +2 -2
  48. data/lib/puppet/pops/evaluator/closure.rb +1 -1
  49. data/lib/puppet/pops/evaluator/evaluator_impl.rb +109 -17
  50. data/lib/puppet/pops/evaluator/puppet_proc.rb +69 -0
  51. data/lib/puppet/pops/evaluator/runtime3_converter.rb +175 -0
  52. data/lib/puppet/pops/evaluator/runtime3_support.rb +15 -128
  53. data/lib/puppet/pops/functions/dispatch.rb +21 -17
  54. data/lib/puppet/pops/functions/dispatcher.rb +3 -3
  55. data/lib/puppet/pops/functions/function.rb +46 -14
  56. data/lib/puppet/pops/issues.rb +2 -2
  57. data/lib/puppet/pops/model/model_label_provider.rb +1 -1
  58. data/lib/puppet/pops/parser/egrammar.ra +2 -0
  59. data/lib/puppet/pops/parser/eparser.rb +732 -724
  60. data/lib/puppet/pops/parser/heredoc_support.rb +1 -1
  61. data/lib/puppet/pops/parser/lexer2.rb +20 -22
  62. data/lib/puppet/pops/types/class_loader.rb +1 -1
  63. data/lib/puppet/pops/types/type_calculator.rb +104 -37
  64. data/lib/puppet/pops/types/type_factory.rb +1 -1
  65. data/lib/puppet/pops/types/types.rb +4 -1
  66. data/lib/puppet/pops/types/types_meta.rb +2 -2
  67. data/lib/puppet/pops/validation/checker4_0.rb +5 -3
  68. data/lib/puppet/provider/service/systemd.rb +1 -0
  69. data/lib/puppet/provider/yumrepo/inifile.rb +4 -1
  70. data/lib/puppet/resource.rb +3 -2
  71. data/lib/puppet/resource/catalog.rb +3 -2
  72. data/lib/puppet/resource/type.rb +1 -1
  73. data/lib/puppet/settings/environment_conf.rb +12 -4
  74. data/lib/puppet/type/package.rb +23 -13
  75. data/lib/puppet/util/autoload.rb +7 -7
  76. data/lib/puppet/util/errors.rb +4 -2
  77. data/lib/puppet/util/network_device/config.rb +5 -0
  78. data/lib/puppet/version.rb +1 -1
  79. data/lib/puppetx.rb +2 -2
  80. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/usee/lib/puppet/parser/functions/callee.rb +8 -0
  81. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/usee/lib/puppet/parser/functions/callee_ws.rb +8 -0
  82. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/usee/metadata.json +9 -0
  83. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/user/lib/puppet/functions/user/caller.rb +5 -0
  84. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/user/lib/puppet/functions/user/caller_ws.rb +12 -0
  85. data/spec/fixtures/unit/pops/loaders/loaders/mix_4x_and_3x_functions/user/metadata.json +9 -0
  86. data/spec/integration/parser/environment_spec.rb +47 -0
  87. data/spec/integration/parser/future_compiler_spec.rb +11 -6
  88. data/spec/unit/application/device_spec.rb +52 -14
  89. data/spec/unit/daemon_spec.rb +0 -2
  90. data/spec/unit/environments_spec.rb +2 -2
  91. data/spec/unit/functions/assert_type_spec.rb +4 -25
  92. data/spec/unit/functions/hiera_spec.rb +127 -0
  93. data/spec/unit/functions/with_spec.rb +9 -4
  94. data/spec/unit/functions4_spec.rb +98 -35
  95. data/spec/unit/hiera/backend/puppet_backend_spec.rb +1 -1
  96. data/spec/unit/parser/functions/create_resources_spec.rb +2 -2
  97. data/spec/unit/parser/functions/defined_spec.rb +5 -0
  98. data/spec/unit/parser/functions/lookup_spec.rb +5 -1
  99. data/spec/unit/parser/functions/scanf_spec.rb +30 -0
  100. data/spec/unit/parser/scope_spec.rb +5 -0
  101. data/spec/unit/pops/binder/injector_spec.rb +1 -1
  102. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +33 -5
  103. data/spec/unit/pops/loaders/loaders_spec.rb +22 -1
  104. data/spec/unit/pops/parser/lexer2_spec.rb +28 -16
  105. data/spec/unit/pops/parser/parse_heredoc_spec.rb +21 -0
  106. data/spec/unit/pops/types/type_calculator_spec.rb +141 -19
  107. data/spec/unit/pops/types/type_factory_spec.rb +2 -2
  108. data/spec/unit/pops/validator/validator_spec.rb +25 -3
  109. data/spec/unit/provider/service/systemd_spec.rb +20 -4
  110. data/spec/unit/provider/user/hpux_spec.rb +1 -1
  111. data/spec/unit/provider/yumrepo/inifile_spec.rb +1 -0
  112. data/spec/unit/settings/environment_conf_spec.rb +12 -1
  113. data/spec/unit/type/package_spec.rb +0 -20
  114. data/spec/unit/util/network_device/config_spec.rb +6 -0
  115. metadata +3422 -3405
@@ -55,8 +55,6 @@ describe Puppet::Daemon, :unless => Puppet.features.microsoft_windows? do
55
55
 
56
56
  Puppet.expects(:notice)
57
57
 
58
- daemon.expects(method)
59
-
60
58
  daemon.set_signal_traps
61
59
  end
62
60
  end
@@ -489,7 +489,7 @@ config_version=$vardir/random/scripts
489
489
  env = Puppet::Node::Environment.create(:cached, [])
490
490
  mocked_loader = mock('loader')
491
491
  mocked_loader.expects(:get).with(:cached).returns(env).once
492
- mocked_loader.expects(:get_conf).with(:cached).returns(Puppet::Settings::EnvironmentConf.static_for(env, 20)).once
492
+ mocked_loader.expects(:get_conf).with(:cached).returns(Puppet::Settings::EnvironmentConf.static_for(env,'current', 20)).once
493
493
 
494
494
  cached = Puppet::Environments::Cached.new(mocked_loader)
495
495
 
@@ -515,7 +515,7 @@ config_version=$vardir/random/scripts
515
515
  env = Puppet::Node::Environment.create(:cached, [])
516
516
  mocked_loader = mock('loader')
517
517
  mocked_loader.expects(:get).with(:cached).returns(env).once
518
- mocked_loader.expects(:get_conf).with(:cached).returns(Puppet::Settings::EnvironmentConf.static_for(env, 20)).once
518
+ mocked_loader.expects(:get_conf).with(:cached).returns(Puppet::Settings::EnvironmentConf.static_for(env,'current', 20)).once
519
519
 
520
520
  cached = Puppet::Environments::Cached.new(mocked_loader)
521
521
 
@@ -3,19 +3,10 @@ require 'puppet/pops'
3
3
  require 'puppet/loaders'
4
4
 
5
5
  describe 'the assert_type function' do
6
-
7
6
  after(:all) { Puppet::Pops::Loaders.clear }
8
7
 
9
- around(:each) do |example|
10
- loaders = Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, []))
11
- Puppet.override({:loaders => loaders}, "test-example") do
12
- example.run
13
- end
14
- end
15
-
16
- let(:func) do
17
- Puppet.lookup(:loaders).puppet_system_loader.load(:function, 'assert_type')
18
- end
8
+ let(:loaders) { Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, [])) }
9
+ let(:func) { loaders.puppet_system_loader.load(:function, 'assert_type') }
19
10
 
20
11
  it 'asserts compliant type by returning the value' do
21
12
  expect(func.call({}, type(String), 'hello world')).to eql('hello world')
@@ -50,9 +41,10 @@ actual:
50
41
  end
51
42
 
52
43
  it 'can be called with a callable that receives a specific type' do
53
- expected, actual = func.call({}, optional(String), 1, create_callable_2_args_unit)
44
+ expected, actual, actual2 = func.call({}, 'Optional[String]', 1) { |expected, actual| [expected, actual, actual] }
54
45
  expect(expected.to_s).to eql('Optional[String]')
55
46
  expect(actual.to_s).to eql('Integer[1, 1]')
47
+ expect(actual2.to_s).to eql('Integer[1, 1]')
56
48
  end
57
49
 
58
50
  def optional(type_ref)
@@ -62,17 +54,4 @@ actual:
62
54
  def type(type_ref)
63
55
  Puppet::Pops::Types::TypeFactory.type_of(type_ref)
64
56
  end
65
-
66
- def create_callable_2_args_unit()
67
- Puppet::Functions.create_function(:func) do
68
- dispatch :func do
69
- param 'Type', 'expected'
70
- param 'Type', 'actual'
71
- end
72
-
73
- def func(expected, actual)
74
- [expected, actual]
75
- end
76
- end.new({}, nil)
77
- end
78
57
  end
@@ -0,0 +1,127 @@
1
+ require 'spec_helper'
2
+ require 'puppet_spec/scope'
3
+ require 'puppet/pops'
4
+ require 'puppet/loaders'
5
+
6
+ describe 'when calling' do
7
+ include PuppetSpec::Scope
8
+
9
+ let(:scope) { create_test_scope_for_node('foo') }
10
+ let(:loaders) { Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, [])) }
11
+ let(:loader) { loaders.puppet_system_loader }
12
+
13
+ context 'hiera' do
14
+ let(:hiera) { loader.load(:function, 'hiera') }
15
+
16
+ it 'should require a key argument' do
17
+ expect { hiera.call(scope, []) }.to raise_error(ArgumentError)
18
+ end
19
+
20
+ it 'should raise a useful error when nil is returned' do
21
+ expect { hiera.call(scope, 'badkey') }.to raise_error(Puppet::ParseError, /Could not find data item badkey/)
22
+ end
23
+
24
+ it 'should use the priority resolution_type' do
25
+ Hiera.any_instance.expects(:lookup).with { |*args| args[4].should be(:priority) }.returns('foo_result')
26
+ expect(hiera.call(scope, 'key')).to eql('foo_result')
27
+ end
28
+
29
+ it 'should propagate optional default' do
30
+ dflt = 'the_default'
31
+ Hiera.any_instance.expects(:lookup).with { |*args| args[1].should be(dflt) }.returns('foo_result')
32
+ expect(hiera.call(scope, 'key', dflt)).to eql('foo_result')
33
+ end
34
+
35
+ it 'should propagate optional override' do
36
+ ovr = 'the_override'
37
+ Hiera.any_instance.expects(:lookup).with { |*args| args[3].should be(ovr) }.returns('foo_result')
38
+ expect(hiera.call(scope, 'key', nil, ovr)).to eql('foo_result')
39
+ end
40
+
41
+ it 'should use default block' do
42
+ #expect(hiera.call(scope, 'foo', lambda_1(scope, loader) { |k| "default for key '#{k}'" })).to eql("default for key 'foo'")
43
+ expect(hiera.call(scope, 'foo') { |k| "default for key '#{k}'" }).to eql("default for key 'foo'")
44
+ end
45
+
46
+ # Test disabled since it assumes that Yaml_backend returns nil when a key is not found and that this
47
+ # triggers use of default. This changes in Hiera 2.0 so that the backend throws a :no_such_key exception.
48
+ # Changing that here will invalidate tests using hiera stable.
49
+ #
50
+ # it 'should propagate optional override when combined with default block' do
51
+ # ovr = 'the_override'
52
+ # Hiera::Backend::Yaml_backend.any_instance.expects(:lookup).with { |*args| args[2].should be(ovr) }
53
+ # expect(hiera.call(scope, 'foo', ovr) { |k| "default for key '#{k}'" }).to eql("default for key 'foo'")
54
+ # end
55
+ end
56
+
57
+ context 'hiera_array' do
58
+ # noinspection RubyResolve
59
+ let(:hiera_array) { loader.load(:function, 'hiera_array') }
60
+
61
+ it 'should require a key argument' do
62
+ expect { hiera_array.call(scope, []) }.to raise_error(ArgumentError)
63
+ end
64
+
65
+ it 'should raise a useful error when nil is returned' do
66
+ expect { hiera_array.call(scope, 'badkey') }.to raise_error(Puppet::ParseError, /Could not find data item badkey/)
67
+ end
68
+
69
+ it 'should use the array resolution_type' do
70
+ Hiera.any_instance.expects(:lookup).with { |*args| args[4].should be(:array) }.returns(%w[foo bar baz])
71
+ expect(hiera_array.call(scope, 'key', {'key' => 'foo_result'})).to eql(%w[foo bar baz])
72
+ end
73
+
74
+ it 'should use default block' do
75
+ expect(hiera_array.call(scope, 'foo') { |k| ['key', k] }).to eql(%w[key foo])
76
+ end
77
+ end
78
+
79
+ context 'hiera_hash' do
80
+ let(:hiera_hash) { loader.load(:function, 'hiera_hash') }
81
+
82
+ it 'should require a key argument' do
83
+ expect { hiera_hash.call(scope, []) }.to raise_error(ArgumentError)
84
+ end
85
+
86
+ it 'should raise a useful error when nil is returned' do
87
+ expect { hiera_hash.call(scope, 'badkey') }.to raise_error(Puppet::ParseError, /Could not find data item badkey/)
88
+ end
89
+
90
+ it 'should use the hash resolution_type' do
91
+ Hiera.any_instance.expects(:lookup).with { |*args| args[4].should be(:hash) }.returns({'foo' => 'result'})
92
+ expect(hiera_hash.call(scope, 'key', {'key' => 'foo_result'})).to eql({'foo' => 'result'})
93
+ end
94
+
95
+ it 'should use default block' do
96
+ expect(hiera_hash.call(scope, 'foo') { |k| {'key' => k} }).to eql({'key' => 'foo'})
97
+ end
98
+ end
99
+
100
+ context 'hiera_include' do
101
+ let(:hiera_include) { loader.load(:function, 'hiera_include') }
102
+
103
+ it 'should require a key argument' do
104
+ expect { hiera_include.call(scope, []) }.to raise_error(ArgumentError)
105
+ end
106
+
107
+ it 'should raise a useful error when nil is returned' do
108
+ expect { hiera_include.call(scope, 'badkey') }.to raise_error(Puppet::ParseError, /Could not find data item badkey/)
109
+ end
110
+
111
+ it 'should use the array resolution_type' do
112
+ Hiera.any_instance.expects(:lookup).with { |*args| args[4].should be(:array) }.returns(%w[foo bar baz])
113
+ hiera_include.expects(:call_function).with('include', %w[foo bar baz])
114
+ hiera_include.call(scope, 'key', {'key' => 'foo_result'})
115
+ end
116
+
117
+ it 'should not raise an error if the resulting hiera lookup returns an empty array' do
118
+ Hiera.any_instance.expects(:lookup).returns []
119
+ expect { hiera_include.call(scope, 'key') }.to_not raise_error
120
+ end
121
+
122
+ it 'should use default block' do
123
+ hiera_include.expects(:call_function).with('include', %w[key foo])
124
+ hiera_include.call(scope, 'foo') { |k| ['key', k] }
125
+ end
126
+ end
127
+ end
@@ -27,9 +27,14 @@ describe 'the with function' do
27
27
  expect(compile_to_catalog('notify { test: message => "data" } with(Notify[test]) |$x| { notify { "${x[message]}": } }')).to have_resource('Notify[data]')
28
28
  end
29
29
 
30
- it 'errors when not given enough arguments for the lambda' do
31
- expect do
32
- compile_to_catalog('with(1) |$x, $y| { }')
33
- end.to raise_error(/Parameter \$y is required but no value was given/m)
30
+ # Conditinoally left out for Ruby 1.8.x since the Proc created for the expected number of arguments will accept
31
+ # a call with fewer arguments and then pass all arguments to the closure. The closure then receives an argument
32
+ # array of correct size with nil values instead of an array with too few arguments
33
+ unless RUBY_VERSION[0,3] == '1.8'
34
+ it 'errors when not given enough arguments for the lambda' do
35
+ expect do
36
+ compile_to_catalog('with(1) |$x, $y| { }')
37
+ end.to raise_error(/Parameter \$y is required but no value was given/m)
38
+ end
34
39
  end
35
40
  end
@@ -191,6 +191,13 @@ actual:
191
191
  min(Integer) - arg count {1}")
192
192
  end
193
193
 
194
+ it 'a function can use inexact argument mapping' do
195
+ f = create_function_with_inexact_dispatch
196
+ func = f.new(:closure_scope, :loader)
197
+ expect(func.call({}, 3,4,5)).to eql([Fixnum, Fixnum, Fixnum])
198
+ expect(func.call({}, 'Apple', 'Banana')).to eql([String, String])
199
+ end
200
+
194
201
  it 'a function can be created using dispatch and called' do
195
202
  f = create_min_function_class_disptaching_to_two_methods()
196
203
  func = f.new(:closure_scope, :loader)
@@ -198,6 +205,14 @@ actual:
198
205
  expect(func.call({}, 'Apple', 'Banana')).to eql('Apple')
199
206
  end
200
207
 
208
+ it 'a function can not be created with parameters declared after a repeated parameter' do
209
+ expect { create_function_with_param_after_repeated }.to raise_error(ArgumentError, 'Parameters cannot be added after a repeated parameter')
210
+ end
211
+
212
+ it 'a function can not be created with required parameters declared after optional ones' do
213
+ expect { create_function_with_rq_after_opt }.to raise_error(ArgumentError, 'A required parameter cannot be added after an optional parameter')
214
+ end
215
+
201
216
  it 'an error is raised with reference to multiple methods when called with mis-matched arguments' do
202
217
  f = create_min_function_class_disptaching_to_two_methods()
203
218
  # TODO: Bogus parameters, not yet used
@@ -273,15 +288,12 @@ actual:
273
288
 
274
289
  context 'supports lambdas' do
275
290
  it 'such that, a required block can be defined and given as an argument' do
276
- # use a Function as callable
277
- the_callable = create_min_function_class().new(:closure_scope, :loader)
278
291
  the_function = create_function_with_required_block_all_defaults().new(:closure_scope, :loader)
279
- result = the_function.call({}, 10, the_callable)
280
- expect(result).to be(the_callable)
292
+ result = the_function.call({}, 7) { |a,b| a < b ? a : b }
293
+ expect(result).to eq(7)
281
294
  end
282
295
 
283
296
  it 'such that, a missing required block when called raises an error' do
284
- # use a Function as callable
285
297
  the_function = create_function_with_required_block_all_defaults().new(:closure_scope, :loader)
286
298
  expect do
287
299
  the_function.call({}, 10)
@@ -294,17 +306,19 @@ actual:
294
306
  end
295
307
 
296
308
  it 'such that, an optional block can be defined and given as an argument' do
297
- # use a Function as callable
298
- the_callable = create_min_function_class().new(:closure_scope, :loader)
299
309
  the_function = create_function_with_optional_block_all_defaults().new(:closure_scope, :loader)
300
- result = the_function.call({}, 10, the_callable)
301
- expect(result).to be(the_callable)
310
+ result = the_function.call({}, 4) { |a,b| a < b ? a : b }
311
+ expect(result).to eql(4)
302
312
  end
303
313
 
304
314
  it 'such that, an optional block can be omitted when called and gets the value nil' do
305
- # use a Function as callable
306
315
  the_function = create_function_with_optional_block_all_defaults().new(:closure_scope, :loader)
307
- expect(the_function.call({}, 10)).to be_nil
316
+ expect(the_function.call({}, 2)).to be_nil
317
+ end
318
+
319
+ it 'such that, a scope can be injected and a block can be used' do
320
+ the_function = create_function_with_scope_required_block_all_defaults().new(:closure_scope, :loader)
321
+ expect(the_function.call({}, 1) { |a,b| a < b ? a : b }).to eql(1)
308
322
  end
309
323
  end
310
324
 
@@ -455,9 +469,9 @@ actual:
455
469
  # block called 'the_block', and using "all_callables"
456
470
  required_block_param #(all_callables(), 'the_block')
457
471
  end
458
- def test(x, block)
472
+ def test(x)
459
473
  # call the block with x
460
- block.call(closure_scope, x)
474
+ yield(x)
461
475
  end
462
476
  end
463
477
  # add the function to the loader (as if it had been loaded from somewhere)
@@ -552,12 +566,11 @@ actual:
552
566
  def create_function_with_optionals_and_varargs_via_dispatch
553
567
  f = Puppet::Functions.create_function('min') do
554
568
  dispatch :min do
555
- param 'Numeric', 'x'
556
- param 'Numeric', 'y'
557
- param 'Numeric', 'a'
558
- param 'Numeric', 'b'
559
- param 'Numeric', 'c'
560
- arg_count 2, :default
569
+ param 'Numeric', :x
570
+ param 'Numeric', :y
571
+ optional_param 'Numeric', :a
572
+ optional_param 'Numeric', :b
573
+ repeated_param 'Numeric', :c
561
574
  end
562
575
  def min(x,y,a=1, b=1, *c)
563
576
  x <= y ? x : y
@@ -565,6 +578,48 @@ actual:
565
578
  end
566
579
  end
567
580
 
581
+ def create_function_with_inexact_dispatch
582
+ f = Puppet::Functions.create_function('t1') do
583
+ dispatch :t1 do
584
+ param 'Numeric', :x
585
+ param 'Numeric', :y
586
+ repeated_param 'Numeric', :z
587
+ end
588
+ dispatch :t1 do
589
+ param 'String', :x
590
+ param 'String', :y
591
+ repeated_param 'String', :z
592
+ end
593
+ def t1(first, *x)
594
+ [first.class, *x.map {|e|e.class}]
595
+ end
596
+ end
597
+ end
598
+
599
+ def create_function_with_rq_after_opt
600
+ f = Puppet::Functions.create_function('t1') do
601
+ dispatch :t1 do
602
+ optional_param 'Numeric', :x
603
+ param 'Numeric', :y
604
+ end
605
+ def t1(*x)
606
+ x
607
+ end
608
+ end
609
+ end
610
+
611
+ def create_function_with_param_after_repeated
612
+ f = Puppet::Functions.create_function('t1') do
613
+ dispatch :t1 do
614
+ repeated_param 'Numeric', :x
615
+ param 'Numeric', :y
616
+ end
617
+ def t1(*x)
618
+ x
619
+ end
620
+ end
621
+ end
622
+
568
623
  def create_function_with_class_injection
569
624
  f = Puppet::Functions.create_function('test', Puppet::Functions::InternalFunction) do
570
625
  attr_injected Puppet::Pops::Types::TypeFactory.type_of(FunctionAPISpecModule::TestDuck), :test_attr
@@ -600,13 +655,26 @@ actual:
600
655
  def create_function_with_required_block_all_defaults
601
656
  f = Puppet::Functions.create_function('test') do
602
657
  dispatch :test do
658
+ param 'Integer', 'x'
659
+ # use defaults, any callable, name is 'block'
660
+ block_param
661
+ end
662
+ def test(x)
663
+ yield(8,x)
664
+ end
665
+ end
666
+ end
667
+
668
+ def create_function_with_scope_required_block_all_defaults
669
+ f = Puppet::Functions.create_function('test', Puppet::Functions::InternalFunction) do
670
+ dispatch :test do
671
+ scope_param
603
672
  param 'Integer', 'x'
604
673
  # use defaults, any callable, name is 'block'
605
674
  required_block_param
606
675
  end
607
- def test(x, block)
608
- # returns the block to make it easy to test what it got when called
609
- block
676
+ def test(scope, x)
677
+ yield(3,x)
610
678
  end
611
679
  end
612
680
  end
@@ -618,9 +686,8 @@ actual:
618
686
  # use defaults, any callable, name is 'block'
619
687
  required_block_param 'the_block'
620
688
  end
621
- def test(x, block)
622
- # returns the block to make it easy to test what it got when called
623
- block
689
+ def test(x)
690
+ yield
624
691
  end
625
692
  end
626
693
  end
@@ -631,9 +698,8 @@ actual:
631
698
  param 'Integer', 'x'
632
699
  required_block_param
633
700
  end
634
- def test(x, block)
635
- # returns the block to make it easy to test what it got when called
636
- block
701
+ def test(x)
702
+ yield
637
703
  end
638
704
  end
639
705
  end
@@ -645,9 +711,8 @@ actual:
645
711
  # use defaults, any callable, name is 'block'
646
712
  required_block_param('Callable', 'the_block')
647
713
  end
648
- def test(x, block)
649
- # returns the block to make it easy to test what it got when called
650
- block
714
+ def test(x)
715
+ yield
651
716
  end
652
717
  end
653
718
  end
@@ -659,10 +724,8 @@ actual:
659
724
  # use defaults, any callable, name is 'block'
660
725
  optional_block_param
661
726
  end
662
- def test(x, block=nil)
663
- # returns the block to make it easy to test what it got when called
664
- # a default of nil must be used or the call will fail with a missing parameter
665
- block
727
+ def test(x)
728
+ yield(5,x) if block_given?
666
729
  end
667
730
  end
668
731
  end