puppet 3.5.1-x86-mingw32 → 3.6.0.rc1-x86-mingw32

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 (342) hide show
  1. data/CONTRIBUTING.md +5 -0
  2. data/Gemfile +17 -9
  3. data/README.md +1 -0
  4. data/conf/fileserver.conf +4 -3
  5. data/ext/README.environment +8 -0
  6. data/ext/build_defaults.yaml +1 -1
  7. data/ext/debian/control +2 -2
  8. data/ext/debian/puppet-common.dirs +4 -0
  9. data/ext/debian/rules +4 -0
  10. data/ext/emacs/puppet-mode-init.el +1 -1
  11. data/ext/emacs/puppet-mode.el +36 -17
  12. data/ext/redhat/client.init +3 -3
  13. data/ext/redhat/puppet.spec.erb +9 -0
  14. data/ext/systemd/puppet.service +3 -4
  15. data/ext/systemd/puppetmaster.service +1 -3
  16. data/install.rb +1 -1
  17. data/lib/puppet.rb +2 -1
  18. data/lib/puppet/agent.rb +1 -1
  19. data/lib/puppet/application.rb +17 -17
  20. data/lib/puppet/application/doc.rb +1 -1
  21. data/lib/puppet/configurer.rb +4 -1
  22. data/lib/puppet/configurer/downloader.rb +13 -12
  23. data/lib/puppet/configurer/plugin_handler.rb +3 -3
  24. data/lib/puppet/context.rb +6 -1
  25. data/lib/puppet/defaults.rb +82 -12
  26. data/lib/puppet/environments.rb +169 -13
  27. data/lib/puppet/external/nagios/grammar.ry +2 -0
  28. data/lib/puppet/external/nagios/parser.rb +28 -19
  29. data/lib/puppet/face/config.rb +19 -6
  30. data/lib/puppet/face/module/generate.rb +209 -7
  31. data/lib/puppet/face/module/install.rb +17 -16
  32. data/lib/puppet/face/module/list.rb +83 -82
  33. data/lib/puppet/face/module/search.rb +1 -1
  34. data/lib/puppet/face/module/upgrade.rb +10 -9
  35. data/lib/puppet/face/parser.rb +3 -2
  36. data/lib/puppet/face/plugin.rb +8 -4
  37. data/lib/puppet/file_bucket/dipper.rb +6 -3
  38. data/lib/puppet/file_bucket/file.rb +4 -2
  39. data/lib/puppet/file_serving/metadata.rb +1 -1
  40. data/lib/puppet/file_system/memory_file.rb +27 -1
  41. data/lib/puppet/file_system/memory_impl.rb +15 -1
  42. data/lib/puppet/forge.rb +148 -52
  43. data/lib/puppet/forge/cache.rb +5 -1
  44. data/lib/puppet/forge/errors.rb +10 -0
  45. data/lib/puppet/forge/repository.rb +61 -26
  46. data/lib/puppet/functions.rb +548 -0
  47. data/lib/puppet/functions/assert_type.rb +42 -0
  48. data/lib/puppet/functions/import.rb +7 -0
  49. data/lib/puppet/indirector/facts/facter.rb +1 -1
  50. data/lib/puppet/indirector/file_bucket_file/file.rb +3 -2
  51. data/lib/puppet/indirector/rest.rb +18 -0
  52. data/lib/puppet/loaders.rb +20 -0
  53. data/lib/puppet/module.rb +2 -2
  54. data/lib/puppet/module_tool.rb +40 -14
  55. data/lib/puppet/module_tool/applications.rb +0 -1
  56. data/lib/puppet/module_tool/applications/application.rb +35 -26
  57. data/lib/puppet/module_tool/applications/builder.rb +16 -6
  58. data/lib/puppet/module_tool/applications/checksummer.rb +25 -19
  59. data/lib/puppet/module_tool/applications/installer.rb +196 -35
  60. data/lib/puppet/module_tool/applications/searcher.rb +1 -0
  61. data/lib/puppet/module_tool/applications/uninstaller.rb +7 -1
  62. data/lib/puppet/module_tool/applications/unpacker.rb +57 -31
  63. data/lib/puppet/module_tool/applications/upgrader.rb +221 -65
  64. data/lib/puppet/module_tool/checksums.rb +5 -8
  65. data/lib/puppet/module_tool/errors/installer.rb +12 -44
  66. data/lib/puppet/module_tool/errors/shared.rb +84 -11
  67. data/lib/puppet/module_tool/errors/upgrader.rb +16 -45
  68. data/lib/puppet/module_tool/install_directory.rb +7 -6
  69. data/lib/puppet/module_tool/installed_modules.rb +92 -0
  70. data/lib/puppet/module_tool/local_tarball.rb +91 -0
  71. data/lib/puppet/module_tool/metadata.rb +119 -115
  72. data/lib/puppet/module_tool/modulefile.rb +9 -9
  73. data/lib/puppet/module_tool/shared_behaviors.rb +19 -7
  74. data/lib/puppet/module_tool/skeleton/templates/generator/README.md.erb +79 -0
  75. data/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +18 -0
  76. data/lib/puppet/module_tool/skeleton/templates/generator/metadata.json.erb +1 -0
  77. data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +7 -0
  78. data/lib/puppet/module_tool/tar.rb +3 -7
  79. data/lib/puppet/module_tool/tar/gnu.rb +21 -9
  80. data/lib/puppet/module_tool/tar/mini.rb +2 -8
  81. data/lib/puppet/network/http/api/v1.rb +1 -1
  82. data/lib/puppet/network/http/api/v2/authorization.rb +4 -2
  83. data/lib/puppet/network/http/issues.rb +1 -0
  84. data/lib/puppet/network/http_pool.rb +15 -6
  85. data/lib/puppet/node/environment.rb +91 -20
  86. data/lib/puppet/parser/ast/pops_bridge.rb +44 -3
  87. data/lib/puppet/parser/collector.rb +1 -1
  88. data/lib/puppet/parser/compiler.rb +50 -7
  89. data/lib/puppet/parser/functions.rb +6 -0
  90. data/lib/puppet/parser/functions/generate.rb +1 -1
  91. data/lib/puppet/parser/resource.rb +1 -1
  92. data/lib/puppet/pops.rb +22 -1
  93. data/lib/puppet/pops/adapters.rb +8 -1
  94. data/lib/puppet/pops/binder/bindings_composer.rb +1 -1
  95. data/lib/puppet/pops/binder/bindings_factory.rb +1 -1
  96. data/lib/puppet/pops/binder/config/binder_config_checker.rb +1 -1
  97. data/lib/puppet/pops/binder/producers.rb +2 -2
  98. data/lib/puppet/pops/evaluator/access_operator.rb +65 -25
  99. data/lib/puppet/pops/evaluator/callable_signature.rb +101 -0
  100. data/lib/puppet/pops/evaluator/closure.rb +57 -2
  101. data/lib/puppet/pops/evaluator/compare_operator.rb +1 -1
  102. data/lib/puppet/pops/evaluator/evaluator_impl.rb +9 -11
  103. data/lib/puppet/pops/evaluator/runtime3_support.rb +72 -21
  104. data/lib/puppet/pops/functions/dispatch.rb +71 -0
  105. data/lib/puppet/pops/functions/dispatcher.rb +237 -0
  106. data/lib/puppet/pops/functions/function.rb +77 -0
  107. data/lib/puppet/pops/issues.rb +12 -0
  108. data/lib/puppet/pops/loader/base_loader.rb +102 -0
  109. data/lib/puppet/pops/loader/dependency_loader.rb +60 -0
  110. data/lib/puppet/pops/loader/gem_support.rb +49 -0
  111. data/lib/puppet/pops/loader/loader.rb +180 -0
  112. data/lib/puppet/pops/loader/loader_paths.rb +137 -0
  113. data/lib/puppet/pops/loader/module_loaders.rb +242 -0
  114. data/lib/puppet/pops/loader/null_loader.rb +44 -0
  115. data/lib/puppet/pops/loader/ruby_function_instantiator.rb +34 -0
  116. data/lib/puppet/pops/loader/ruby_legacy_function_instantiator.rb +109 -0
  117. data/lib/puppet/pops/loader/simple_environment_loader.rb +20 -0
  118. data/lib/puppet/pops/loader/static_loader.rb +69 -0
  119. data/lib/puppet/pops/loader/uri_helper.rb +22 -0
  120. data/lib/puppet/pops/loaders.rb +240 -0
  121. data/lib/puppet/pops/model/factory.rb +13 -5
  122. data/lib/puppet/pops/model/model_tree_dumper.rb +12 -4
  123. data/lib/puppet/pops/parser/egrammar.ra +31 -18
  124. data/lib/puppet/pops/parser/eparser.rb +1137 -1106
  125. data/lib/puppet/pops/parser/lexer2.rb +17 -16
  126. data/lib/puppet/pops/semantic_error.rb +17 -0
  127. data/lib/puppet/pops/types/type_calculator.rb +150 -15
  128. data/lib/puppet/pops/types/type_factory.rb +69 -0
  129. data/lib/puppet/pops/types/type_parser.rb +9 -0
  130. data/lib/puppet/pops/types/types.rb +65 -4
  131. data/lib/puppet/pops/validation/checker4_0.rb +1 -1
  132. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -1
  133. data/lib/puppet/property/list.rb +1 -1
  134. data/lib/puppet/provider/augeas/augeas.rb +2 -2
  135. data/lib/puppet/provider/cron/crontab.rb +13 -2
  136. data/lib/puppet/provider/package.rb +24 -0
  137. data/lib/puppet/provider/package/apt.rb +6 -1
  138. data/lib/puppet/provider/package/gem.rb +8 -2
  139. data/lib/puppet/provider/package/msi.rb +0 -15
  140. data/lib/puppet/provider/package/openbsd.rb +0 -24
  141. data/lib/puppet/provider/package/rpm.rb +3 -29
  142. data/lib/puppet/provider/package/windows.rb +0 -15
  143. data/lib/puppet/provider/package/yum.rb +101 -24
  144. data/lib/puppet/provider/package/yumhelper.py +31 -1
  145. data/lib/puppet/provider/package/zypper.rb +10 -28
  146. data/lib/puppet/provider/service/debian.rb +1 -1
  147. data/lib/puppet/provider/service/init.rb +3 -0
  148. data/lib/puppet/provider/service/openbsd.rb +318 -0
  149. data/lib/puppet/provider/service/redhat.rb +6 -3
  150. data/lib/puppet/provider/service/systemd.rb +2 -2
  151. data/lib/puppet/provider/yumrepo/inifile.rb +115 -42
  152. data/lib/puppet/resource.rb +13 -9
  153. data/lib/puppet/resource/catalog.rb +12 -6
  154. data/lib/puppet/resource/type_collection.rb +3 -3
  155. data/lib/puppet/settings.rb +57 -36
  156. data/lib/puppet/settings/config_file.rb +5 -0
  157. data/lib/puppet/settings/environment_conf.rb +147 -0
  158. data/lib/puppet/settings/ttl_setting.rb +48 -0
  159. data/lib/puppet/ssl/certificate_authority.rb +2 -3
  160. data/lib/puppet/ssl/certificate_authority/autosign_command.rb +1 -1
  161. data/lib/puppet/ssl/certificate_request.rb +4 -4
  162. data/lib/puppet/ssl/validator/default_validator.rb +2 -2
  163. data/lib/puppet/status.rb +1 -1
  164. data/lib/puppet/test/test_helper.rb +1 -0
  165. data/lib/puppet/type/augeas.rb +13 -1
  166. data/lib/puppet/type/cron.rb +32 -18
  167. data/lib/puppet/type/file.rb +4 -2
  168. data/lib/puppet/type/file/checksum.rb +15 -5
  169. data/lib/puppet/type/file/content.rb +3 -1
  170. data/lib/puppet/type/file/source.rb +5 -5
  171. data/lib/puppet/type/package.rb +12 -17
  172. data/lib/puppet/type/resources.rb +3 -1
  173. data/lib/puppet/type/scheduled_task.rb +4 -5
  174. data/lib/puppet/type/service.rb +12 -2
  175. data/lib/puppet/type/user.rb +106 -0
  176. data/lib/puppet/type/yumrepo.rb +9 -1
  177. data/lib/puppet/util/checksums.rb +60 -1
  178. data/lib/puppet/util/diff.rb +3 -1
  179. data/lib/puppet/util/execution.rb +20 -16
  180. data/lib/puppet/util/feature.rb +3 -0
  181. data/lib/puppet/util/logging.rb +19 -12
  182. data/lib/puppet/util/rubygems.rb +10 -0
  183. data/lib/puppet/util/watched_file.rb +1 -1
  184. data/lib/puppet/util/windows/security.rb +5 -3
  185. data/lib/puppet/vendor/load_semantic.rb +1 -0
  186. data/lib/puppet/vendor/require_vendored.rb +2 -0
  187. data/lib/puppet/vendor/semantic/Gemfile +20 -0
  188. data/lib/puppet/vendor/semantic/Rakefile +69 -0
  189. data/lib/puppet/vendor/semantic/lib/semantic.rb +7 -0
  190. data/lib/puppet/vendor/semantic/lib/semantic/dependency.rb +181 -0
  191. data/lib/puppet/vendor/semantic/lib/semantic/dependency/graph.rb +60 -0
  192. data/lib/puppet/vendor/semantic/lib/semantic/dependency/graph_node.rb +117 -0
  193. data/lib/puppet/vendor/semantic/lib/semantic/dependency/module_release.rb +46 -0
  194. data/lib/puppet/vendor/semantic/lib/semantic/dependency/source.rb +25 -0
  195. data/lib/puppet/vendor/semantic/lib/semantic/dependency/unsatisfiable_graph.rb +31 -0
  196. data/lib/puppet/vendor/semantic/lib/semantic/version.rb +168 -0
  197. data/lib/puppet/vendor/semantic/lib/semantic/version_range.rb +424 -0
  198. data/lib/puppet/vendor/semantic/spec/spec_helper.rb +24 -0
  199. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/graph_node_spec.rb +141 -0
  200. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/graph_spec.rb +162 -0
  201. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/module_release_spec.rb +143 -0
  202. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/source_spec.rb +5 -0
  203. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency/unsatisfiable_graph_spec.rb +44 -0
  204. data/lib/puppet/vendor/semantic/spec/unit/semantic/dependency_spec.rb +383 -0
  205. data/lib/puppet/vendor/semantic/spec/unit/semantic/version_range_spec.rb +307 -0
  206. data/lib/puppet/vendor/semantic/spec/unit/semantic/version_spec.rb +608 -0
  207. data/lib/puppet/version.rb +1 -1
  208. data/spec/fixtures/java.tgz +0 -0
  209. data/spec/fixtures/stdlib.tgz +0 -0
  210. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/usee/lib/puppet/functions/usee/callee.rb +5 -0
  211. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/user/lib/puppet/functions/user/caller.rb +5 -0
  212. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/user/metadata.json +9 -0
  213. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/lib/puppet/functions/modulea/rb_func_a.rb +5 -0
  214. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/lib/puppet/functions/rb_func_a.rb +5 -0
  215. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/manifests/init.pp +3 -0
  216. data/spec/fixtures/unit/pops/loaders/loaders/single_module/modules/modulea/metadata.json +19 -0
  217. data/spec/fixtures/unit/pops/loaders/loaders/wo_metadata_module/modules/moduleb/lib/puppet/functions/moduleb/rb_func_b.rb +6 -0
  218. data/spec/fixtures/unit/pops/loaders/loaders/wo_metadata_module/modules/moduleb/manifests/init.pp +3 -0
  219. data/spec/fixtures/unit/provider/naginator/define_empty_param +6 -0
  220. data/spec/fixtures/unit/provider/service/systemd/list_unit_files_services +7 -0
  221. data/spec/fixtures/unit/type/user/authorized_keys +5 -0
  222. data/spec/integration/application/apply_spec.rb +1 -2
  223. data/spec/integration/configurer_spec.rb +2 -2
  224. data/spec/integration/faces/plugin_spec.rb +62 -0
  225. data/spec/integration/indirector/catalog/compiler_spec.rb +1 -1
  226. data/spec/integration/indirector/catalog/queue_spec.rb +1 -1
  227. data/spec/integration/node/environment_spec.rb +2 -2
  228. data/spec/integration/parser/future_compiler_spec.rb +96 -142
  229. data/spec/integration/parser/ruby_manifest_spec.rb +0 -5
  230. data/spec/integration/provider/cron/crontab_spec.rb +35 -0
  231. data/spec/integration/type/file_spec.rb +74 -72
  232. data/spec/integration/util/windows/security_spec.rb +17 -0
  233. data/spec/lib/matchers/resource.rb +45 -13
  234. data/spec/lib/puppet_spec/files.rb +18 -0
  235. data/spec/lib/puppet_spec/module_tool/shared_functions.rb +56 -0
  236. data/spec/lib/puppet_spec/module_tool/stub_source.rb +133 -0
  237. data/spec/shared_contexts/checksums.rb +55 -0
  238. data/spec/unit/application/apply_spec.rb +10 -7
  239. data/spec/unit/application/doc_spec.rb +17 -10
  240. data/spec/unit/application/indirection_base_spec.rb +18 -10
  241. data/spec/unit/application/inspect_spec.rb +22 -20
  242. data/spec/unit/configurer/downloader_spec.rb +7 -6
  243. data/spec/unit/configurer/plugin_handler_spec.rb +5 -8
  244. data/spec/unit/configurer_spec.rb +1 -1
  245. data/spec/unit/context_spec.rb +23 -0
  246. data/spec/unit/environments_spec.rb +274 -16
  247. data/spec/unit/face/config_spec.rb +111 -11
  248. data/spec/unit/face/module/install_spec.rb +14 -85
  249. data/spec/unit/face/module/list_spec.rb +108 -62
  250. data/spec/unit/face/module/search_spec.rb +1 -1
  251. data/spec/unit/face/module/uninstall_spec.rb +21 -42
  252. data/spec/unit/face/parser_spec.rb +5 -2
  253. data/spec/unit/file_bucket/dipper_spec.rb +92 -86
  254. data/spec/unit/file_bucket/file_spec.rb +23 -75
  255. data/spec/unit/file_serving/metadata_spec.rb +74 -74
  256. data/spec/unit/forge/module_release_spec.rb +131 -0
  257. data/spec/unit/forge/repository_spec.rb +21 -20
  258. data/spec/unit/forge_spec.rb +99 -23
  259. data/spec/unit/functions/assert_type_spec.rb +59 -0
  260. data/spec/unit/functions4_spec.rb +671 -0
  261. data/spec/unit/indirector/catalog/static_compiler_spec.rb +2 -2
  262. data/spec/unit/indirector/facts/facter_spec.rb +9 -3
  263. data/spec/unit/indirector/file_bucket_file/file_spec.rb +156 -155
  264. data/spec/unit/indirector/rest_spec.rb +8 -0
  265. data/spec/unit/interface/face_collection_spec.rb +35 -23
  266. data/spec/unit/module_spec.rb +20 -8
  267. data/spec/unit/module_tool/applications/builder_spec.rb +40 -12
  268. data/spec/unit/module_tool/applications/checksummer_spec.rb +86 -105
  269. data/spec/unit/module_tool/applications/installer_spec.rb +293 -261
  270. data/spec/unit/module_tool/applications/searcher_spec.rb +1 -1
  271. data/spec/unit/module_tool/applications/uninstaller_spec.rb +90 -154
  272. data/spec/unit/module_tool/applications/unpacker_spec.rb +12 -12
  273. data/spec/unit/module_tool/applications/upgrader_spec.rb +286 -18
  274. data/spec/unit/module_tool/metadata_spec.rb +223 -14
  275. data/spec/unit/module_tool/tar/gnu_spec.rb +12 -9
  276. data/spec/unit/module_tool/tar/mini_spec.rb +1 -1
  277. data/spec/unit/module_tool/tar_spec.rb +4 -18
  278. data/spec/unit/module_tool_spec.rb +123 -27
  279. data/spec/unit/network/formats_spec.rb +2 -2
  280. data/spec/unit/network/http_pool_spec.rb +21 -0
  281. data/spec/unit/network/rights_spec.rb +10 -8
  282. data/spec/unit/node/environment_spec.rb +27 -2
  283. data/spec/unit/parser/collector_spec.rb +1 -1
  284. data/spec/unit/parser/compiler_spec.rb +1 -1
  285. data/spec/unit/parser/functions/generate_spec.rb +4 -0
  286. data/spec/unit/pops/evaluator/access_ops_spec.rb +50 -11
  287. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +25 -0
  288. data/spec/unit/pops/loaders/dependency_loader_spec.rb +44 -0
  289. data/spec/unit/pops/loaders/loader_paths_spec.rb +66 -0
  290. data/spec/unit/pops/loaders/loaders_spec.rb +105 -0
  291. data/spec/unit/pops/loaders/module_loaders_spec.rb +119 -0
  292. data/spec/unit/pops/loaders/static_loader_spec.rb +46 -0
  293. data/spec/unit/pops/types/type_calculator_spec.rb +145 -10
  294. data/spec/unit/pops/types/type_factory_spec.rb +101 -0
  295. data/spec/unit/pops/types/type_parser_spec.rb +22 -0
  296. data/spec/unit/property/list_spec.rb +9 -1
  297. data/spec/unit/provider/augeas/augeas_spec.rb +58 -11
  298. data/spec/unit/provider/cron/crontab_spec.rb +1 -0
  299. data/spec/unit/provider/cron/parsed_spec.rb +15 -0
  300. data/spec/unit/provider/naginator_spec.rb +14 -0
  301. data/spec/unit/provider/package/apt_spec.rb +78 -64
  302. data/spec/unit/provider/package/gem_spec.rb +15 -0
  303. data/spec/unit/provider/package/rpm_spec.rb +6 -6
  304. data/spec/unit/provider/package/windows_spec.rb +1 -1
  305. data/spec/unit/provider/package/yum_spec.rb +199 -104
  306. data/spec/unit/provider/package/zypper_spec.rb +41 -15
  307. data/spec/unit/provider/service/openbsd_spec.rb +129 -22
  308. data/spec/unit/provider/service/redhat_spec.rb +18 -4
  309. data/spec/unit/provider/service/systemd_spec.rb +5 -9
  310. data/spec/unit/provider/service/upstart_spec.rb +1 -1
  311. data/spec/unit/provider/user/directoryservice_spec.rb +10 -0
  312. data/spec/unit/provider/yumrepo/inifile_spec.rb +171 -15
  313. data/spec/unit/resource/catalog_spec.rb +20 -104
  314. data/spec/unit/resource/type_collection_spec.rb +10 -9
  315. data/spec/unit/settings/config_file_spec.rb +29 -6
  316. data/spec/unit/settings/environment_conf_spec.rb +51 -0
  317. data/spec/unit/settings_spec.rb +97 -12
  318. data/spec/unit/ssl/certificate_authority_spec.rb +2 -0
  319. data/spec/unit/type/augeas_spec.rb +1 -1
  320. data/spec/unit/type/cron_spec.rb +6 -7
  321. data/spec/unit/type/file/checksum_spec.rb +6 -0
  322. data/spec/unit/type/file/content_spec.rb +277 -207
  323. data/spec/unit/type/file_spec.rb +9 -7
  324. data/spec/unit/type/user_spec.rb +106 -18
  325. data/spec/unit/type/yumrepo_spec.rb +8 -0
  326. data/spec/unit/util/checksums_spec.rb +12 -5
  327. data/spec/unit/util/diff_spec.rb +8 -0
  328. data/spec/unit/util/execution_spec.rb +4 -4
  329. data/spec/unit/util/feature_spec.rb +2 -0
  330. data/spec/unit/util/logging_spec.rb +14 -4
  331. data/spec/unit/util/rdoc/parser_spec.rb +5 -4
  332. data/spec/unit/util/rubygems_spec.rb +14 -0
  333. data/tasks/parallel.rake +2 -2
  334. metadata +154 -21
  335. checksums.yaml +0 -7
  336. data/lib/puppet/module_tool/applications/generator.rb +0 -142
  337. data/lib/puppet/module_tool/skeleton.rb +0 -37
  338. data/lib/puppet/module_tool/skeleton/templates/generator/Modulefile.erb +0 -11
  339. data/lib/puppet/module_tool/skeleton/templates/generator/README.erb +0 -16
  340. data/lib/puppet/module_tool/tar/solaris.rb +0 -5
  341. data/spec/fixtures/unit/provider/service/systemd/list_units_services +0 -17
  342. data/spec/unit/module_tool/tar/solaris_spec.rb +0 -22
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+ require 'puppet/pops'
3
+ require 'puppet/loaders'
4
+
5
+ describe 'the assert_type function' do
6
+
7
+ after(:all) { Puppet::Pops::Loaders.clear }
8
+
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
19
+
20
+ it 'asserts compliant type by returning the value' do
21
+ expect(func.call({}, type(String), 'hello world')).to eql('hello world')
22
+ end
23
+
24
+ it 'accepts type given as a String' do
25
+ expect(func.call({}, 'String', 'hello world')).to eql('hello world')
26
+ end
27
+
28
+ it 'asserts non compliant type by raising an error' do
29
+ expect do
30
+ func.call({}, type(Integer), 'hello world')
31
+ end.to raise_error(Puppet::ParseError, /does not match actual/)
32
+ end
33
+
34
+ it 'checks that first argument is a type' do
35
+ expect do
36
+ func.call({}, 10, 10)
37
+ end.to raise_error(ArgumentError, Regexp.new(Regexp.escape(
38
+ "function 'assert_type' called with mis-matched arguments
39
+ expected one of:
40
+ assert_type(Type type, Optional[Object] value) - arg count {2}
41
+ assert_type(String type_string, Optional[Object] value) - arg count {2}
42
+ actual:
43
+ assert_type(Integer, Integer) - arg count {2}")))
44
+ end
45
+
46
+ it 'allows the second arg to be undef/nil)' do
47
+ expect do
48
+ func.call({}, optional(String), nil)
49
+ end.to_not raise_error(ArgumentError)
50
+ end
51
+
52
+ def optional(type_ref)
53
+ Puppet::Pops::Types::TypeFactory.optional(type(type_ref))
54
+ end
55
+
56
+ def type(type_ref)
57
+ Puppet::Pops::Types::TypeFactory.type_of(type_ref)
58
+ end
59
+ end
@@ -0,0 +1,671 @@
1
+ require 'spec_helper'
2
+ require 'puppet/pops'
3
+ require 'puppet/loaders'
4
+ require 'puppet_spec/pops'
5
+ require 'puppet_spec/scope'
6
+
7
+ module FunctionAPISpecModule
8
+ class TestDuck
9
+ end
10
+
11
+ class TestFunctionLoader < Puppet::Pops::Loader::StaticLoader
12
+ def initialize
13
+ @functions = {}
14
+ end
15
+
16
+ def add_function(name, function)
17
+ typed_name = Puppet::Pops::Loader::Loader::TypedName.new(:function, name)
18
+ entry = Puppet::Pops::Loader::Loader::NamedEntry.new(typed_name, function, __FILE__)
19
+ @functions[typed_name] = entry
20
+ end
21
+
22
+ # override StaticLoader
23
+ def load_constant(typed_name)
24
+ @functions[typed_name]
25
+ end
26
+ end
27
+ end
28
+
29
+ describe 'the 4x function api' do
30
+ include FunctionAPISpecModule
31
+ include PuppetSpec::Pops
32
+ include PuppetSpec::Scope
33
+
34
+ let(:loader) { FunctionAPISpecModule::TestFunctionLoader.new }
35
+
36
+ it 'allows a simple function to be created without dispatch declaration' do
37
+ f = Puppet::Functions.create_function('min') do
38
+ def min(x,y)
39
+ x <= y ? x : y
40
+ end
41
+ end
42
+
43
+ # the produced result is a Class inheriting from Function
44
+ expect(f.class).to be(Class)
45
+ expect(f.superclass).to be(Puppet::Functions::Function)
46
+ # and this class had the given name (not a real Ruby class name)
47
+ expect(f.name).to eql('min')
48
+ end
49
+
50
+ it 'refuses to create functions that are not based on the Function class' do
51
+ expect do
52
+ Puppet::Functions.create_function('testing', Object) {}
53
+ end.to raise_error(ArgumentError, 'Functions must be based on Puppet::Pops::Functions::Function. Got Object')
54
+ end
55
+
56
+ it 'a function without arguments can be defined and called without dispatch declaration' do
57
+ f = create_noargs_function_class()
58
+ func = f.new(:closure_scope, :loader)
59
+ expect(func.call({})).to eql(10)
60
+ end
61
+
62
+ it 'an error is raised when calling a no arguments function with arguments' do
63
+ f = create_noargs_function_class()
64
+ func = f.new(:closure_scope, :loader)
65
+ expect{func.call({}, 'surprise')}.to raise_error(ArgumentError, "function 'test' called with mis-matched arguments
66
+ expected:
67
+ test() - arg count {0}
68
+ actual:
69
+ test(String) - arg count {1}")
70
+ end
71
+
72
+ it 'a simple function can be called' do
73
+ f = create_min_function_class()
74
+ # TODO: Bogus parameters, not yet used
75
+ func = f.new(:closure_scope, :loader)
76
+ expect(func.is_a?(Puppet::Functions::Function)).to be_true
77
+ expect(func.call({}, 10,20)).to eql(10)
78
+ end
79
+
80
+ it 'an error is raised if called with too few arguments' do
81
+ f = create_min_function_class()
82
+ # TODO: Bogus parameters, not yet used
83
+ func = f.new(:closure_scope, :loader)
84
+ expect(func.is_a?(Puppet::Functions::Function)).to be_true
85
+ signature = if RUBY_VERSION =~ /^1\.8/
86
+ 'Object{2}'
87
+ else
88
+ 'Object x, Object y'
89
+ end
90
+ expect do
91
+ func.call({}, 10)
92
+ end.to raise_error(ArgumentError, "function 'min' called with mis-matched arguments
93
+ expected:
94
+ min(#{signature}) - arg count {2}
95
+ actual:
96
+ min(Integer) - arg count {1}")
97
+ end
98
+
99
+ it 'an error is raised if called with too many arguments' do
100
+ f = create_min_function_class()
101
+ # TODO: Bogus parameters, not yet used
102
+ func = f.new(:closure_scope, :loader)
103
+ expect(func.is_a?(Puppet::Functions::Function)).to be_true
104
+ signature = if RUBY_VERSION =~ /^1\.8/
105
+ 'Object{2}'
106
+ else
107
+ 'Object x, Object y'
108
+ end
109
+ expect do
110
+ func.call({}, 10, 10, 10)
111
+ end.to raise_error(ArgumentError, Regexp.new(Regexp.escape(
112
+ "function 'min' called with mis-matched arguments
113
+ expected:
114
+ min(#{signature}) - arg count {2}
115
+ actual:
116
+ min(Integer, Integer, Integer) - arg count {3}")))
117
+ end
118
+
119
+ it 'an error is raised if simple function-name and method are not matched' do
120
+ expect do
121
+ f = create_badly_named_method_function_class()
122
+ end.to raise_error(ArgumentError, /Function Creation Error, cannot create a default dispatcher for function 'mix', no method with this name found/)
123
+ end
124
+
125
+ it 'the implementation separates dispatchers for different functions' do
126
+ # this tests that meta programming / construction puts class attributes in the correct class
127
+ f1 = create_min_function_class()
128
+ f2 = create_max_function_class()
129
+
130
+ d1 = f1.dispatcher
131
+ d2 = f2.dispatcher
132
+
133
+ expect(d1).to_not eql(d2)
134
+ expect(d1.dispatchers[0]).to_not eql(d2.dispatchers[0])
135
+ end
136
+
137
+ context 'when using regular dispatch' do
138
+ it 'a function can be created using dispatch and called' do
139
+ f = create_min_function_class_using_dispatch()
140
+ func = f.new(:closure_scope, :loader)
141
+ expect(func.call({}, 3,4)).to eql(3)
142
+ end
143
+
144
+ it 'an error is raised with reference to given parameter names when called with mis-matched arguments' do
145
+ f = create_min_function_class_using_dispatch()
146
+ # TODO: Bogus parameters, not yet used
147
+ func = f.new(:closure_scope, :loader)
148
+ expect(func.is_a?(Puppet::Functions::Function)).to be_true
149
+ expect do
150
+ func.call({}, 10, 10, 10)
151
+ end.to raise_error(ArgumentError, Regexp.new(Regexp.escape(
152
+ "function 'min' called with mis-matched arguments
153
+ expected:
154
+ min(Numeric a, Numeric b) - arg count {2}
155
+ actual:
156
+ min(Integer, Integer, Integer) - arg count {3}")))
157
+ end
158
+
159
+ it 'an error includes optional indicators and count for last element' do
160
+ f = create_function_with_optionals_and_varargs()
161
+ # TODO: Bogus parameters, not yet used
162
+ func = f.new(:closure_scope, :loader)
163
+ expect(func.is_a?(Puppet::Functions::Function)).to be_true
164
+ signature = if RUBY_VERSION =~ /^1\.8/
165
+ 'Object{2,}'
166
+ else
167
+ 'Object x, Object y, Object a?, Object b?, Object c{0,}'
168
+ end
169
+ expect do
170
+ func.call({}, 10)
171
+ end.to raise_error(ArgumentError,
172
+ "function 'min' called with mis-matched arguments
173
+ expected:
174
+ min(#{signature}) - arg count {2,}
175
+ actual:
176
+ min(Integer) - arg count {1}")
177
+ end
178
+
179
+ it 'an error includes optional indicators and count for last element when defined via dispatch' do
180
+ f = create_function_with_optionals_and_varargs_via_dispatch()
181
+ # TODO: Bogus parameters, not yet used
182
+ func = f.new(:closure_scope, :loader)
183
+ expect(func.is_a?(Puppet::Functions::Function)).to be_true
184
+ expect do
185
+ func.call({}, 10)
186
+ end.to raise_error(ArgumentError,
187
+ "function 'min' called with mis-matched arguments
188
+ expected:
189
+ min(Numeric x, Numeric y, Numeric a?, Numeric b?, Numeric c{0,}) - arg count {2,}
190
+ actual:
191
+ min(Integer) - arg count {1}")
192
+ end
193
+
194
+ it 'a function can be created using dispatch and called' do
195
+ f = create_min_function_class_disptaching_to_two_methods()
196
+ func = f.new(:closure_scope, :loader)
197
+ expect(func.call({}, 3,4)).to eql(3)
198
+ expect(func.call({}, 'Apple', 'Banana')).to eql('Apple')
199
+ end
200
+
201
+ it 'an error is raised with reference to multiple methods when called with mis-matched arguments' do
202
+ f = create_min_function_class_disptaching_to_two_methods()
203
+ # TODO: Bogus parameters, not yet used
204
+ func = f.new(:closure_scope, :loader)
205
+ expect(func.is_a?(Puppet::Functions::Function)).to be_true
206
+ expect do
207
+ func.call({}, 10, 10, 10)
208
+ end.to raise_error(ArgumentError,
209
+ "function 'min' called with mis-matched arguments
210
+ expected one of:
211
+ min(Numeric a, Numeric b) - arg count {2}
212
+ min(String s1, String s2) - arg count {2}
213
+ actual:
214
+ min(Integer, Integer, Integer) - arg count {3}")
215
+ end
216
+
217
+ context 'can use injection' do
218
+ before :all do
219
+ injector = Puppet::Pops::Binder::Injector.create('test') do
220
+ bind.name('a_string').to('evoe')
221
+ bind.name('an_int').to(42)
222
+ end
223
+ Puppet.push_context({:injector => injector}, "injector for testing function API")
224
+ end
225
+
226
+ after :all do
227
+ Puppet.pop_context()
228
+ end
229
+
230
+ it 'attributes can be injected' do
231
+ f1 = create_function_with_class_injection()
232
+ f = f1.new(:closure_scope, :loader)
233
+ expect(f.test_attr2()).to eql("evoe")
234
+ expect(f.serial().produce(nil)).to eql(42)
235
+ expect(f.test_attr().class.name).to eql("FunctionAPISpecModule::TestDuck")
236
+ end
237
+
238
+ it 'parameters can be injected and woven with regular dispatch' do
239
+ f1 = create_function_with_param_injection_regular()
240
+ f = f1.new(:closure_scope, :loader)
241
+ expect(f.call(nil, 10, 20)).to eql("evoe! 10, and 20 < 42 = true")
242
+ expect(f.call(nil, 50, 20)).to eql("evoe! 50, and 20 < 42 = false")
243
+ end
244
+ end
245
+
246
+ context 'when requesting a type' do
247
+ it 'responds with a Callable for a single signature' do
248
+ tf = Puppet::Pops::Types::TypeFactory
249
+ fc = create_min_function_class_using_dispatch()
250
+ t = fc.dispatcher.to_type
251
+ expect(t.class).to be(Puppet::Pops::Types::PCallableType)
252
+ expect(t.param_types.class).to be(Puppet::Pops::Types::PTupleType)
253
+ expect(t.param_types.types).to eql([tf.numeric(), tf.numeric()])
254
+ expect(t.block_type).to be_nil
255
+ end
256
+
257
+ it 'responds with a Variant[Callable...] for multiple signatures' do
258
+ tf = Puppet::Pops::Types::TypeFactory
259
+ fc = create_min_function_class_disptaching_to_two_methods()
260
+ t = fc.dispatcher.to_type
261
+ expect(t.class).to be(Puppet::Pops::Types::PVariantType)
262
+ expect(t.types.size).to eql(2)
263
+ t1 = t.types[0]
264
+ expect(t1.param_types.class).to be(Puppet::Pops::Types::PTupleType)
265
+ expect(t1.param_types.types).to eql([tf.numeric(), tf.numeric()])
266
+ expect(t1.block_type).to be_nil
267
+ t2 = t.types[1]
268
+ expect(t2.param_types.class).to be(Puppet::Pops::Types::PTupleType)
269
+ expect(t2.param_types.types).to eql([tf.string(), tf.string()])
270
+ expect(t2.block_type).to be_nil
271
+ end
272
+ end
273
+
274
+ context 'supports lambdas' do
275
+ 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
+ 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)
281
+ end
282
+
283
+ it 'such that, a missing required block when called raises an error' do
284
+ # use a Function as callable
285
+ the_function = create_function_with_required_block_all_defaults().new(:closure_scope, :loader)
286
+ expect do
287
+ the_function.call({}, 10)
288
+ end.to raise_error(ArgumentError,
289
+ "function 'test' called with mis-matched arguments
290
+ expected:
291
+ test(Integer x, Callable block) - arg count {2}
292
+ actual:
293
+ test(Integer) - arg count {1}")
294
+ end
295
+
296
+ 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
+ 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)
302
+ end
303
+
304
+ it 'such that, an optional block can be omitted when called and gets the value nil' do
305
+ # use a Function as callable
306
+ the_function = create_function_with_optional_block_all_defaults().new(:closure_scope, :loader)
307
+ expect(the_function.call({}, 10)).to be_nil
308
+ end
309
+ end
310
+
311
+ context 'provides signature information' do
312
+ it 'about capture rest (varargs)' do
313
+ fc = create_function_with_optionals_and_varargs
314
+ signatures = fc.signatures
315
+ expect(signatures.size).to eql(1)
316
+ signature = signatures[0]
317
+ expect(signature.last_captures_rest?).to be_true
318
+ end
319
+
320
+ it 'about optional and required parameters' do
321
+ fc = create_function_with_optionals_and_varargs
322
+ signature = fc.signatures[0]
323
+ expect(signature.args_range).to eql( [2, Puppet::Pops::Types::INFINITY ] )
324
+ expect(signature.infinity?(signature.args_range[1])).to be_true
325
+ end
326
+
327
+ it 'about block not being allowed' do
328
+ fc = create_function_with_optionals_and_varargs
329
+ signature = fc.signatures[0]
330
+ expect(signature.block_range).to eql( [ 0, 0 ] )
331
+ expect(signature.block_type).to be_nil
332
+ end
333
+
334
+ it 'about required block' do
335
+ fc = create_function_with_required_block_all_defaults
336
+ signature = fc.signatures[0]
337
+ expect(signature.block_range).to eql( [ 1, 1 ] )
338
+ expect(signature.block_type).to_not be_nil
339
+ end
340
+
341
+ it 'about optional block' do
342
+ fc = create_function_with_optional_block_all_defaults
343
+ signature = fc.signatures[0]
344
+ expect(signature.block_range).to eql( [ 0, 1 ] )
345
+ expect(signature.block_type).to_not be_nil
346
+ end
347
+
348
+ it 'about the type' do
349
+ fc = create_function_with_optional_block_all_defaults
350
+ signature = fc.signatures[0]
351
+ expect(signature.type.class).to be(Puppet::Pops::Types::PCallableType)
352
+ end
353
+
354
+ # conditional on Ruby 1.8.7 which does not do parameter introspection
355
+ if Method.method_defined?(:parameters)
356
+ it 'about parameter names obtained from ruby introspection' do
357
+ fc = create_min_function_class
358
+ signature = fc.signatures[0]
359
+ expect(signature.parameter_names).to eql(['x', 'y'])
360
+ end
361
+ end
362
+
363
+ it 'about parameter names specified with dispatch' do
364
+ fc = create_min_function_class_using_dispatch
365
+ signature = fc.signatures[0]
366
+ expect(signature.parameter_names).to eql(['a', 'b'])
367
+ end
368
+
369
+ it 'about block_name when it is *not* given in the definition' do
370
+ # neither type, nor name
371
+ fc = create_function_with_required_block_all_defaults
372
+ signature = fc.signatures[0]
373
+ expect(signature.block_name).to eql('block')
374
+ # no name given, only type
375
+ fc = create_function_with_required_block_given_type
376
+ signature = fc.signatures[0]
377
+ expect(signature.block_name).to eql('block')
378
+ end
379
+
380
+ it 'about block_name when it *is* given in the definition' do
381
+ # neither type, nor name
382
+ fc = create_function_with_required_block_default_type
383
+ signature = fc.signatures[0]
384
+ expect(signature.block_name).to eql('the_block')
385
+ # no name given, only type
386
+ fc = create_function_with_required_block_fully_specified
387
+ signature = fc.signatures[0]
388
+ expect(signature.block_name).to eql('the_block')
389
+ end
390
+ end
391
+
392
+ context 'supports calling other functions' do
393
+ before(:all) do
394
+ Puppet.push_context( {:loaders => Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, []))})
395
+ end
396
+
397
+ after(:all) do
398
+ Puppet.pop_context()
399
+ end
400
+
401
+ it 'such that, other functions are callable by name' do
402
+ fc = Puppet::Functions.create_function(:test) do
403
+ def test()
404
+ # Call a function available in the puppet system
405
+ call_function('assert_type', 'Integer', 10)
406
+ end
407
+ end
408
+ # initiate the function the same way the loader initiates it
409
+ f = fc.new(:closure_scope, Puppet.lookup(:loaders).puppet_system_loader)
410
+ expect(f.call({})).to eql(10)
411
+ end
412
+
413
+ it 'such that, calling a non existing function raises an error' do
414
+ fc = Puppet::Functions.create_function(:test) do
415
+ def test()
416
+ # Call a function not available in the puppet system
417
+ call_function('no_such_function', 'Integer', 'hello')
418
+ end
419
+ end
420
+ # initiate the function the same way the loader initiates it
421
+ f = fc.new(:closure_scope, Puppet.lookup(:loaders).puppet_system_loader)
422
+ expect{f.call({})}.to raise_error(ArgumentError, "Function test(): cannot call function 'no_such_function' - not found")
423
+ end
424
+ end
425
+
426
+ context 'supports calling ruby functions with lambda from puppet' do
427
+ before(:all) do
428
+ Puppet.push_context( {:loaders => Puppet::Pops::Loaders.new(Puppet::Node::Environment.create(:testing, []))})
429
+ end
430
+
431
+ after(:all) do
432
+ Puppet.pop_context()
433
+ end
434
+
435
+ before(:each) do
436
+ Puppet[:strict_variables] = true
437
+
438
+ # These must be set since the is 3x logic that triggers on these even if the tests are explicit
439
+ # about selection of parser and evaluator
440
+ #
441
+ Puppet[:parser] = 'future'
442
+ Puppet[:evaluator] = 'future'
443
+ # Puppetx cannot be loaded until the correct parser has been set (injector is turned off otherwise)
444
+ require 'puppetx'
445
+ end
446
+
447
+ let(:parser) { Puppet::Pops::Parser::EvaluatingParser::Transitional.new }
448
+ let(:node) { 'node.example.com' }
449
+ let(:scope) { s = create_test_scope_for_node(node); s }
450
+
451
+ it 'function with required block can be called' do
452
+ # construct ruby function to call
453
+ fc = Puppet::Functions.create_function('testing::test') do
454
+ dispatch :test do
455
+ param 'Integer', 'x'
456
+ # block called 'the_block', and using "all_callables"
457
+ required_block_param #(all_callables(), 'the_block')
458
+ end
459
+ def test(x, block)
460
+ # call the block with x
461
+ block.call(closure_scope, x)
462
+ end
463
+ end
464
+ # add the function to the loader (as if it had been loaded from somewhere)
465
+ the_loader = loader()
466
+ f = fc.new({}, the_loader)
467
+ loader.add_function('testing::test', f)
468
+ # evaluate a puppet call
469
+ source = "testing::test(10) |$x| { $x+1 }"
470
+ program = parser.parse_string(source, __FILE__)
471
+ Puppet::Pops::Adapters::LoaderAdapter.adapt(program.model).loader = the_loader
472
+ expect(parser.evaluate(scope, program)).to eql(11)
473
+ end
474
+ end
475
+
476
+ end
477
+
478
+ def create_noargs_function_class
479
+ f = Puppet::Functions.create_function('test') do
480
+ def test()
481
+ 10
482
+ end
483
+ end
484
+ end
485
+
486
+ def create_min_function_class
487
+ f = Puppet::Functions.create_function('min') do
488
+ def min(x,y)
489
+ x <= y ? x : y
490
+ end
491
+ end
492
+ end
493
+
494
+ def create_max_function_class
495
+ f = Puppet::Functions.create_function('max') do
496
+ def max(x,y)
497
+ x >= y ? x : y
498
+ end
499
+ end
500
+ end
501
+
502
+ def create_badly_named_method_function_class
503
+ f = Puppet::Functions.create_function('mix') do
504
+ def mix_up(x,y)
505
+ x <= y ? x : y
506
+ end
507
+ end
508
+ end
509
+
510
+ def create_min_function_class_using_dispatch
511
+ f = Puppet::Functions.create_function('min') do
512
+ dispatch :min do
513
+ param 'Numeric', 'a'
514
+ param 'Numeric', 'b'
515
+ end
516
+ def min(x,y)
517
+ x <= y ? x : y
518
+ end
519
+ end
520
+ end
521
+
522
+ def create_min_function_class_disptaching_to_two_methods
523
+ f = Puppet::Functions.create_function('min') do
524
+ dispatch :min do
525
+ param 'Numeric', 'a'
526
+ param 'Numeric', 'b'
527
+ end
528
+
529
+ dispatch :min_s do
530
+ param 'String', 's1'
531
+ param 'String', 's2'
532
+ end
533
+
534
+ def min(x,y)
535
+ x <= y ? x : y
536
+ end
537
+
538
+ def min_s(x,y)
539
+ cmp = (x.downcase <=> y.downcase)
540
+ cmp <= 0 ? x : y
541
+ end
542
+ end
543
+ end
544
+
545
+ def create_function_with_optionals_and_varargs
546
+ f = Puppet::Functions.create_function('min') do
547
+ def min(x,y,a=1, b=1, *c)
548
+ x <= y ? x : y
549
+ end
550
+ end
551
+ end
552
+
553
+ def create_function_with_optionals_and_varargs_via_dispatch
554
+ f = Puppet::Functions.create_function('min') do
555
+ dispatch :min do
556
+ param 'Numeric', 'x'
557
+ param 'Numeric', 'y'
558
+ param 'Numeric', 'a'
559
+ param 'Numeric', 'b'
560
+ param 'Numeric', 'c'
561
+ arg_count 2, :default
562
+ end
563
+ def min(x,y,a=1, b=1, *c)
564
+ x <= y ? x : y
565
+ end
566
+ end
567
+ end
568
+
569
+ def create_function_with_class_injection
570
+ f = Puppet::Functions.create_function('test', Puppet::Functions::InternalFunction) do
571
+ attr_injected Puppet::Pops::Types::TypeFactory.type_of(FunctionAPISpecModule::TestDuck), :test_attr
572
+ attr_injected Puppet::Pops::Types::TypeFactory.string(), :test_attr2, "a_string"
573
+ attr_injected_producer Puppet::Pops::Types::TypeFactory.integer(), :serial, "an_int"
574
+
575
+ def test(x,y,a=1, b=1, *c)
576
+ x <= y ? x : y
577
+ end
578
+ end
579
+ end
580
+
581
+ def create_function_with_param_injection_regular
582
+ f = Puppet::Functions.create_function('test', Puppet::Functions::InternalFunction) do
583
+ attr_injected Puppet::Pops::Types::TypeFactory.type_of(FunctionAPISpecModule::TestDuck), :test_attr
584
+ attr_injected Puppet::Pops::Types::TypeFactory.string(), :test_attr2, "a_string"
585
+ attr_injected_producer Puppet::Pops::Types::TypeFactory.integer(), :serial, "an_int"
586
+
587
+ dispatch :test do
588
+ injected_param Puppet::Pops::Types::TypeFactory.string, 'x', 'a_string'
589
+ injected_producer_param Puppet::Pops::Types::TypeFactory.integer, 'y', 'an_int'
590
+ param 'Scalar', 'a'
591
+ param 'Scalar', 'b'
592
+ end
593
+
594
+ def test(x,y,a,b)
595
+ y_produced = y.produce(nil)
596
+ "#{x}! #{a}, and #{b} < #{y_produced} = #{ !!(a < y_produced && b < y_produced)}"
597
+ end
598
+ end
599
+ end
600
+
601
+ def create_function_with_required_block_all_defaults
602
+ f = Puppet::Functions.create_function('test') do
603
+ dispatch :test do
604
+ param 'Integer', 'x'
605
+ # use defaults, any callable, name is 'block'
606
+ required_block_param
607
+ end
608
+ def test(x, block)
609
+ # returns the block to make it easy to test what it got when called
610
+ block
611
+ end
612
+ end
613
+ end
614
+
615
+ def create_function_with_required_block_default_type
616
+ f = Puppet::Functions.create_function('test') do
617
+ dispatch :test do
618
+ param 'Integer', 'x'
619
+ # use defaults, any callable, name is 'block'
620
+ required_block_param 'the_block'
621
+ end
622
+ def test(x, block)
623
+ # returns the block to make it easy to test what it got when called
624
+ block
625
+ end
626
+ end
627
+ end
628
+
629
+ def create_function_with_required_block_given_type
630
+ f = Puppet::Functions.create_function('test') do
631
+ dispatch :test do
632
+ param 'Integer', 'x'
633
+ required_block_param
634
+ end
635
+ def test(x, block)
636
+ # returns the block to make it easy to test what it got when called
637
+ block
638
+ end
639
+ end
640
+ end
641
+
642
+ def create_function_with_required_block_fully_specified
643
+ f = Puppet::Functions.create_function('test') do
644
+ dispatch :test do
645
+ param 'Integer', 'x'
646
+ # use defaults, any callable, name is 'block'
647
+ required_block_param('Callable', 'the_block')
648
+ end
649
+ def test(x, block)
650
+ # returns the block to make it easy to test what it got when called
651
+ block
652
+ end
653
+ end
654
+ end
655
+
656
+ def create_function_with_optional_block_all_defaults
657
+ f = Puppet::Functions.create_function('test') do
658
+ dispatch :test do
659
+ param 'Integer', 'x'
660
+ # use defaults, any callable, name is 'block'
661
+ optional_block_param
662
+ end
663
+ def test(x, block=nil)
664
+ # returns the block to make it easy to test what it got when called
665
+ # a default of nil must be used or the call will fail with a missing parameter
666
+ block
667
+ end
668
+ end
669
+ end
670
+
671
+ end