puppet 5.3.7 → 5.4.0

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 (454) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +42 -29
  3. data/README.md +8 -6
  4. data/ext/cert_inspector +2 -2
  5. data/ext/envpuppet +1 -1
  6. data/ext/gentoo/init.d/puppetmaster +4 -4
  7. data/ext/ips/puppet-agent +11 -11
  8. data/ext/ips/puppet-master +11 -11
  9. data/ext/puppet-test +1 -2
  10. data/ext/redhat/client.init +2 -2
  11. data/ext/redhat/logrotate +1 -1
  12. data/ext/solaris/smf/puppet +11 -11
  13. data/ext/solaris/smf/svc-puppetd +5 -5
  14. data/ext/solaris/smf/svc-puppetmasterd +5 -5
  15. data/ext/windows/service/daemon.rb +1 -1
  16. data/install.rb +2 -3
  17. data/lib/puppet/agent.rb +1 -1
  18. data/lib/puppet/application/cert.rb +1 -3
  19. data/lib/puppet/application/describe.rb +0 -1
  20. data/lib/puppet/application/device.rb +12 -99
  21. data/lib/puppet/application/filebucket.rb +32 -11
  22. data/lib/puppet/application/lookup.rb +1 -11
  23. data/lib/puppet/application/script.rb +261 -0
  24. data/lib/puppet/configurer.rb +3 -4
  25. data/lib/puppet/configurer/plugin_handler.rb +26 -9
  26. data/lib/puppet/context.rb +1 -1
  27. data/lib/puppet/datatypes.rb +213 -0
  28. data/lib/puppet/datatypes/error.rb +21 -0
  29. data/lib/puppet/datatypes/impl/error.rb +40 -0
  30. data/lib/puppet/defaults.rb +51 -20
  31. data/lib/puppet/environments.rb +17 -0
  32. data/lib/puppet/error.rb +17 -0
  33. data/lib/puppet/etc.rb +2 -2
  34. data/lib/puppet/external/pson/pure/generator.rb +1 -1
  35. data/lib/puppet/external/pson/pure/parser.rb +1 -1
  36. data/lib/puppet/face/config.rb +45 -0
  37. data/lib/puppet/face/epp.rb +3 -3
  38. data/lib/puppet/face/help/action.erb +3 -0
  39. data/lib/puppet/face/module/build.rb +1 -0
  40. data/lib/puppet/face/module/generate.rb +5 -0
  41. data/lib/puppet/face/module/install.rb +1 -0
  42. data/lib/puppet/face/module/search.rb +6 -2
  43. data/lib/puppet/face/module/uninstall.rb +1 -0
  44. data/lib/puppet/face/module/upgrade.rb +1 -0
  45. data/lib/puppet/face/parser.rb +0 -1
  46. data/lib/puppet/face/plugin.rb +1 -3
  47. data/lib/puppet/feature/base.rb +1 -1
  48. data/lib/puppet/feature/bolt.rb +3 -0
  49. data/lib/puppet/file_bucket/dipper.rb +1 -2
  50. data/lib/puppet/file_serving/http_metadata.rb +1 -1
  51. data/lib/puppet/file_system/uniquefile.rb +2 -2
  52. data/lib/puppet/forge.rb +6 -0
  53. data/lib/puppet/functions.rb +70 -88
  54. data/lib/puppet/functions/all.rb +6 -2
  55. data/lib/puppet/functions/annotate.rb +1 -1
  56. data/lib/puppet/functions/any.rb +7 -3
  57. data/lib/puppet/functions/contain.rb +6 -0
  58. data/lib/puppet/functions/convert_to.rb +32 -0
  59. data/lib/puppet/functions/defined.rb +0 -3
  60. data/lib/puppet/functions/each.rb +10 -6
  61. data/lib/puppet/functions/filter.rb +16 -10
  62. data/lib/puppet/functions/find_file.rb +0 -1
  63. data/lib/puppet/functions/include.rb +6 -0
  64. data/lib/puppet/functions/map.rb +12 -9
  65. data/lib/puppet/functions/module_directory.rb +41 -0
  66. data/lib/puppet/functions/new.rb +1 -4
  67. data/lib/puppet/functions/regsubst.rb +1 -1
  68. data/lib/puppet/functions/require.rb +6 -0
  69. data/lib/puppet/generate/type.rb +1 -1
  70. data/lib/puppet/gettext/config.rb +2 -2
  71. data/lib/puppet/gettext/stubs.rb +1 -1
  72. data/lib/puppet/indirector/catalog/compiler.rb +0 -1
  73. data/lib/puppet/indirector/file_bucket_file/file.rb +6 -2
  74. data/lib/puppet/indirector/file_server.rb +1 -1
  75. data/lib/puppet/indirector/node/ldap.rb +19 -3
  76. data/lib/puppet/indirector/request.rb +10 -6
  77. data/lib/puppet/indirector/rest.rb +11 -12
  78. data/lib/puppet/info_service/class_information_service.rb +1 -1
  79. data/lib/puppet/interface/action.rb +11 -0
  80. data/lib/puppet/interface/action_builder.rb +8 -0
  81. data/lib/puppet/interface/option_manager.rb +1 -1
  82. data/lib/puppet/loaders.rb +2 -0
  83. data/lib/puppet/module.rb +6 -2
  84. data/lib/puppet/module_tool/applications/builder.rb +4 -0
  85. data/lib/puppet/module_tool/applications/installer.rb +3 -0
  86. data/lib/puppet/module_tool/applications/uninstaller.rb +3 -0
  87. data/lib/puppet/module_tool/applications/unpacker.rb +1 -1
  88. data/lib/puppet/module_tool/applications/upgrader.rb +3 -0
  89. data/lib/puppet/module_tool/installed_modules.rb +1 -1
  90. data/lib/puppet/module_tool/metadata.rb +0 -1
  91. data/lib/puppet/network/authstore.rb +1 -1
  92. data/lib/puppet/network/http/api/indirected_routes.rb +1 -1
  93. data/lib/puppet/network/http/connection.rb +1 -9
  94. data/lib/puppet/network/http/factory.rb +0 -3
  95. data/lib/puppet/network/http/webrick.rb +1 -0
  96. data/lib/puppet/network/rights.rb +1 -1
  97. data/lib/puppet/node.rb +53 -0
  98. data/lib/puppet/node/environment.rb +1 -1
  99. data/lib/puppet/parameter/boolean.rb +1 -1
  100. data/lib/puppet/parser.rb +1 -0
  101. data/lib/puppet/parser/abstract_compiler.rb +36 -0
  102. data/lib/puppet/parser/ast/branch.rb +1 -1
  103. data/lib/puppet/parser/ast/pops_bridge.rb +8 -52
  104. data/lib/puppet/parser/compiler.rb +4 -54
  105. data/lib/puppet/parser/functions.rb +0 -1
  106. data/lib/puppet/parser/functions/create_resources.rb +6 -0
  107. data/lib/puppet/parser/functions/fqdn_rand.rb +6 -2
  108. data/lib/puppet/parser/functions/inline_template.rb +6 -0
  109. data/lib/puppet/parser/functions/new.rb +47 -32
  110. data/lib/puppet/parser/functions/realize.rb +6 -0
  111. data/lib/puppet/parser/functions/return.rb +1 -22
  112. data/lib/puppet/parser/functions/reverse_each.rb +1 -1
  113. data/lib/puppet/parser/functions/scanf.rb +1 -1
  114. data/lib/puppet/parser/functions/sha256.rb +5 -0
  115. data/lib/puppet/parser/functions/tag.rb +6 -0
  116. data/lib/puppet/parser/functions/tagged.rb +6 -0
  117. data/lib/puppet/parser/functions/template.rb +5 -0
  118. data/lib/puppet/parser/scope.rb +28 -4
  119. data/lib/puppet/parser/script_compiler.rb +118 -0
  120. data/lib/puppet/parser/type_loader.rb +1 -1
  121. data/lib/puppet/pops.rb +1 -1
  122. data/lib/puppet/pops/evaluator/access_operator.rb +38 -4
  123. data/lib/puppet/pops/evaluator/closure.rb +12 -4
  124. data/lib/puppet/pops/evaluator/compare_operator.rb +4 -4
  125. data/lib/puppet/pops/evaluator/epp_evaluator.rb +13 -0
  126. data/lib/puppet/pops/evaluator/evaluator_impl.rb +38 -10
  127. data/lib/puppet/pops/evaluator/literal_evaluator.rb +1 -1
  128. data/lib/puppet/pops/evaluator/runtime3_converter.rb +1 -1
  129. data/lib/puppet/pops/evaluator/runtime3_support.rb +2 -3
  130. data/lib/puppet/pops/functions/dispatch.rb +6 -5
  131. data/lib/puppet/pops/functions/function.rb +2 -2
  132. data/lib/puppet/pops/issues.rb +34 -2
  133. data/lib/puppet/pops/loader/base_loader.rb +10 -0
  134. data/lib/puppet/pops/loader/dependency_loader.rb +7 -0
  135. data/lib/puppet/pops/loader/loader.rb +21 -2
  136. data/lib/puppet/pops/loader/loader_paths.rb +180 -30
  137. data/lib/puppet/pops/loader/module_loaders.rb +202 -33
  138. data/lib/puppet/pops/loader/puppet_plan_instantiator.rb +84 -0
  139. data/lib/puppet/pops/loader/puppet_resource_type_impl_instantiator.rb +9 -9
  140. data/lib/puppet/pops/loader/ruby_data_type_instantiator.rb +40 -0
  141. data/lib/puppet/pops/loader/runtime3_type_loader.rb +6 -1
  142. data/lib/puppet/pops/loader/static_loader.rb +23 -8
  143. data/lib/puppet/pops/loader/task_instantiator.rb +69 -0
  144. data/lib/puppet/pops/loader/type_definition_instantiator.rb +4 -0
  145. data/lib/puppet/pops/loaders.rb +122 -11
  146. data/lib/puppet/pops/lookup/data_dig_function_provider.rb +1 -1
  147. data/lib/puppet/pops/lookup/interpolation.rb +1 -1
  148. data/lib/puppet/pops/lookup/lookup_adapter.rb +0 -1
  149. data/lib/puppet/pops/model/ast.pp +3 -0
  150. data/lib/puppet/pops/model/ast.rb +34 -1
  151. data/lib/puppet/pops/model/factory.rb +30 -3
  152. data/lib/puppet/pops/model/model_label_provider.rb +1 -0
  153. data/lib/puppet/pops/model/model_tree_dumper.rb +12 -1
  154. data/lib/puppet/pops/model/tree_dumper.rb +1 -1
  155. data/lib/puppet/pops/parser/code_merger.rb +2 -2
  156. data/lib/puppet/pops/parser/egrammar.ra +44 -15
  157. data/lib/puppet/pops/parser/eparser.rb +1687 -1571
  158. data/lib/puppet/pops/parser/epp_support.rb +1 -3
  159. data/lib/puppet/pops/parser/evaluating_parser.rb +1 -1
  160. data/lib/puppet/pops/parser/interpolation_support.rb +2 -2
  161. data/lib/puppet/pops/parser/lexer2.rb +4 -4
  162. data/lib/puppet/pops/parser/lexer_support.rb +2 -2
  163. data/lib/puppet/pops/parser/locatable.rb +1 -1
  164. data/lib/puppet/pops/parser/locator.rb +7 -13
  165. data/lib/puppet/pops/parser/parser_support.rb +3 -3
  166. data/lib/puppet/pops/parser/slurp_support.rb +0 -3
  167. data/lib/puppet/pops/pcore.rb +45 -0
  168. data/lib/puppet/pops/resource/param.rb +1 -1
  169. data/lib/puppet/pops/resource/resource_type_impl.rb +1 -1
  170. data/lib/puppet/pops/serialization/abstract_reader.rb +4 -0
  171. data/lib/puppet/pops/serialization/abstract_writer.rb +6 -0
  172. data/lib/puppet/pops/serialization/extension.rb +1 -0
  173. data/lib/puppet/pops/serialization/from_data_converter.rb +64 -10
  174. data/lib/puppet/pops/serialization/json_path.rb +2 -1
  175. data/lib/puppet/pops/serialization/object.rb +3 -4
  176. data/lib/puppet/pops/serialization/serializer.rb +2 -1
  177. data/lib/puppet/pops/serialization/to_data_converter.rb +7 -3
  178. data/lib/puppet/pops/time/timespan.rb +1 -1
  179. data/lib/puppet/pops/types/iterable.rb +38 -9
  180. data/lib/puppet/pops/types/p_init_type.rb +1 -1
  181. data/lib/puppet/pops/types/p_meta_type.rb +4 -0
  182. data/lib/puppet/pops/types/p_object_type.rb +146 -14
  183. data/lib/puppet/pops/types/p_object_type_extension.rb +218 -0
  184. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +0 -1
  185. data/lib/puppet/pops/types/p_sem_ver_type.rb +10 -2
  186. data/lib/puppet/pops/types/p_type_set_type.rb +0 -1
  187. data/lib/puppet/pops/types/p_uri_type.rb +190 -0
  188. data/lib/puppet/pops/types/puppet_object.rb +15 -1
  189. data/lib/puppet/pops/types/ruby_generator.rb +46 -54
  190. data/lib/puppet/pops/types/string_converter.rb +22 -1
  191. data/lib/puppet/pops/types/type_acceptor.rb +1 -1
  192. data/lib/puppet/pops/types/type_calculator.rb +13 -4
  193. data/lib/puppet/pops/types/type_factory.rb +29 -5
  194. data/lib/puppet/pops/types/type_formatter.rb +67 -4
  195. data/lib/puppet/pops/types/type_parser.rb +92 -4
  196. data/lib/puppet/pops/types/type_with_members.rb +43 -0
  197. data/lib/puppet/pops/types/types.rb +212 -80
  198. data/lib/puppet/pops/validation/checker4_0.rb +10 -6
  199. data/lib/puppet/pops/validation/tasks_checker.rb +60 -0
  200. data/lib/puppet/pops/validation/validator_factory_4_0.rb +6 -1
  201. data/lib/puppet/property.rb +1 -1
  202. data/lib/puppet/provider.rb +18 -8
  203. data/lib/puppet/provider/augeas/augeas.rb +3 -4
  204. data/lib/puppet/provider/exec.rb +0 -2
  205. data/lib/puppet/provider/group/groupadd.rb +25 -1
  206. data/lib/puppet/provider/group/windows_adsi.rb +7 -4
  207. data/lib/puppet/provider/mount.rb +25 -8
  208. data/lib/puppet/provider/nameservice.rb +9 -4
  209. data/lib/puppet/provider/nameservice/directoryservice.rb +3 -3
  210. data/lib/puppet/provider/nameservice/objectadd.rb +13 -24
  211. data/lib/puppet/provider/nameservice/pw.rb +14 -14
  212. data/lib/puppet/provider/package/appdmg.rb +0 -1
  213. data/lib/puppet/provider/package/apple.rb +0 -1
  214. data/lib/puppet/provider/package/gem.rb +2 -2
  215. data/lib/puppet/provider/package/macports.rb +2 -2
  216. data/lib/puppet/provider/package/pkg.rb +3 -0
  217. data/lib/puppet/provider/package/pkgdmg.rb +0 -1
  218. data/lib/puppet/provider/package/portage.rb +0 -1
  219. data/lib/puppet/provider/package/yum.rb +23 -8
  220. data/lib/puppet/provider/package/zypper.rb +2 -2
  221. data/lib/puppet/provider/scheduled_task/win32_taskscheduler.rb +2 -2
  222. data/lib/puppet/provider/service/init.rb +1 -0
  223. data/lib/puppet/provider/service/launchd.rb +6 -7
  224. data/lib/puppet/provider/service/redhat.rb +3 -2
  225. data/lib/puppet/provider/service/systemd.rb +2 -2
  226. data/lib/puppet/provider/ssh_authorized_key/parsed.rb +1 -1
  227. data/lib/puppet/provider/user/aix.rb +3 -2
  228. data/lib/puppet/provider/user/openbsd.rb +1 -1
  229. data/lib/puppet/provider/user/pw.rb +1 -1
  230. data/lib/puppet/provider/user/user_role_add.rb +7 -1
  231. data/lib/puppet/provider/user/useradd.rb +36 -6
  232. data/lib/puppet/provider/user/windows_adsi.rb +1 -1
  233. data/lib/puppet/provider/yumrepo/inifile.rb +2 -4
  234. data/lib/puppet/provider/zfs/zfs.rb +23 -3
  235. data/lib/puppet/provider/zpool/zpool.rb +1 -1
  236. data/lib/puppet/reference/configuration.rb +0 -2
  237. data/lib/puppet/reference/type.rb +0 -1
  238. data/lib/puppet/resource.rb +1 -2
  239. data/lib/puppet/resource/catalog.rb +1 -1
  240. data/lib/puppet/resource/status.rb +0 -1
  241. data/lib/puppet/resource/type.rb +4 -4
  242. data/lib/puppet/resource/type_collection.rb +1 -1
  243. data/lib/puppet/settings/base_setting.rb +1 -1
  244. data/lib/puppet/settings/environment_conf.rb +0 -1
  245. data/lib/puppet/settings/ini_file.rb +66 -12
  246. data/lib/puppet/ssl/certificate_authority.rb +1 -1
  247. data/lib/puppet/ssl/certificate_request.rb +2 -2
  248. data/lib/puppet/ssl/certificate_revocation_list.rb +2 -1
  249. data/lib/puppet/ssl/certificate_signer.rb +11 -0
  250. data/lib/puppet/ssl/host.rb +2 -2
  251. data/lib/puppet/syntax_checkers/base64.rb +1 -1
  252. data/lib/puppet/transaction.rb +37 -14
  253. data/lib/puppet/transaction/report.rb +3 -1
  254. data/lib/puppet/type.rb +17 -4
  255. data/lib/puppet/type/cron.rb +1 -1
  256. data/lib/puppet/type/exec.rb +5 -4
  257. data/lib/puppet/type/file.rb +3 -3
  258. data/lib/puppet/type/file/checksum.rb +7 -1
  259. data/lib/puppet/type/file/checksum_value.rb +4 -3
  260. data/lib/puppet/type/group.rb +3 -0
  261. data/lib/puppet/type/k5login.rb +101 -0
  262. data/lib/puppet/type/macauthorization.rb +1 -1
  263. data/lib/puppet/type/mount.rb +6 -2
  264. data/lib/puppet/type/tidy.rb +6 -4
  265. data/lib/puppet/type/user.rb +26 -39
  266. data/lib/puppet/type/yumrepo.rb +9 -0
  267. data/lib/puppet/type/zfs.rb +4 -0
  268. data/lib/puppet/util.rb +8 -15
  269. data/lib/puppet/util/character_encoding.rb +2 -2
  270. data/lib/puppet/util/checksums.rb +82 -1
  271. data/lib/puppet/util/errors.rb +0 -2
  272. data/lib/puppet/util/filetype.rb +2 -2
  273. data/lib/puppet/util/json_lockfile.rb +1 -1
  274. data/lib/puppet/util/log.rb +1 -1
  275. data/lib/puppet/util/log/destinations.rb +10 -1
  276. data/lib/puppet/util/monkey_patches.rb +1 -1
  277. data/lib/puppet/util/network_device/cisco/device.rb +5 -5
  278. data/lib/puppet/util/network_device/config.rb +2 -3
  279. data/lib/puppet/util/platform.rb +13 -0
  280. data/lib/puppet/util/plist.rb +4 -4
  281. data/lib/puppet/util/rdoc/generators/puppet_generator.rb +2 -2
  282. data/lib/puppet/util/rdoc/parser/puppet_parser_rdoc2.rb +1 -1
  283. data/lib/puppet/util/reference.rb +8 -1
  284. data/lib/puppet/util/windows/adsi.rb +18 -15
  285. data/lib/puppet/util/windows/principal.rb +6 -7
  286. data/lib/puppet/util/windows/process.rb +1 -1
  287. data/lib/puppet/util/windows/registry.rb +2 -2
  288. data/lib/puppet/util/windows/sid.rb +7 -62
  289. data/lib/puppet/vendor/deep_merge/README.md +2 -2
  290. data/lib/puppet/vendor/pathspec/lib/pathspec/gitignorespec.rb +18 -18
  291. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version.rb +2 -2
  292. data/lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/version_range.rb +5 -5
  293. data/lib/puppet/vendor/semantic_puppet/locales/config.yaml +1 -1
  294. data/lib/puppet/version.rb +1 -1
  295. data/lib/puppet_pal.rb +874 -0
  296. data/locales/ja/puppet.po +140 -163
  297. data/locales/puppet.pot +940 -597
  298. data/man/man5/puppet.conf.5 +16 -91
  299. data/man/man8/puppet-agent.8 +2 -6
  300. data/man/man8/puppet-apply.8 +2 -2
  301. data/man/man8/puppet-ca.8 +1 -1
  302. data/man/man8/puppet-catalog.8 +1 -1
  303. data/man/man8/puppet-cert.8 +1 -1
  304. data/man/man8/puppet-certificate.8 +1 -1
  305. data/man/man8/puppet-certificate_request.8 +1 -1
  306. data/man/man8/puppet-certificate_revocation_list.8 +1 -1
  307. data/man/man8/puppet-config.8 +1 -1
  308. data/man/man8/puppet-describe.8 +1 -1
  309. data/man/man8/puppet-device.8 +11 -33
  310. data/man/man8/puppet-doc.8 +1 -1
  311. data/man/man8/puppet-epp.8 +1 -1
  312. data/man/man8/puppet-facts.8 +1 -1
  313. data/man/man8/puppet-filebucket.8 +4 -22
  314. data/man/man8/puppet-generate.8 +1 -1
  315. data/man/man8/puppet-help.8 +1 -1
  316. data/man/man8/puppet-key.8 +1 -1
  317. data/man/man8/puppet-lookup.8 +1 -1
  318. data/man/man8/puppet-man.8 +1 -1
  319. data/man/man8/puppet-master.8 +1 -1
  320. data/man/man8/puppet-module.8 +2 -11
  321. data/man/man8/puppet-node.8 +1 -1
  322. data/man/man8/puppet-parser.8 +1 -1
  323. data/man/man8/puppet-plugin.8 +1 -1
  324. data/man/man8/puppet-report.8 +1 -1
  325. data/man/man8/puppet-resource.8 +1 -1
  326. data/man/man8/puppet-status.8 +1 -1
  327. data/man/man8/puppet.8 +2 -2
  328. data/spec/integration/application/lookup_spec.rb +0 -21
  329. data/spec/integration/parser/compiler_spec.rb +18 -0
  330. data/spec/integration/parser/script_compiler_spec.rb +113 -0
  331. data/spec/integration/provider/mount_spec.rb +2 -0
  332. data/spec/integration/type/file_spec.rb +11 -3
  333. data/spec/integration/util/windows/adsi_spec.rb +1 -86
  334. data/spec/integration/util/windows/principal_spec.rb +1 -10
  335. data/spec/shared_contexts/checksum.rb +4 -1
  336. data/spec/shared_contexts/digests.rb +46 -1
  337. data/spec/shared_contexts/types_setup.rb +8 -3
  338. data/spec/unit/agent_spec.rb +2 -2
  339. data/spec/unit/application/cert_spec.rb +5 -17
  340. data/spec/unit/application/device_spec.rb +2 -96
  341. data/spec/unit/application/filebucket_spec.rb +18 -4
  342. data/spec/unit/configurer/plugin_handler_spec.rb +5 -32
  343. data/spec/unit/configurer_spec.rb +3 -3
  344. data/spec/unit/datatypes_spec.rb +304 -0
  345. data/spec/unit/defaults_spec.rb +41 -20
  346. data/spec/unit/face/config_spec.rb +46 -1
  347. data/spec/unit/face/epp_face_spec.rb +7 -3
  348. data/spec/unit/face/module/search_spec.rb +11 -0
  349. data/spec/unit/face/parser_spec.rb +2 -2
  350. data/spec/unit/file_bucket/dipper_spec.rb +12 -1
  351. data/spec/unit/forge/module_release_spec.rb +70 -0
  352. data/spec/unit/functions/break_spec.rb +34 -2
  353. data/spec/unit/functions/contain_spec.rb +1 -0
  354. data/spec/unit/functions/convert_to_spec.rb +22 -0
  355. data/spec/unit/functions/epp_spec.rb +5 -0
  356. data/spec/unit/functions/include_spec.rb +15 -0
  357. data/spec/unit/functions/module_directory_spec.rb +43 -0
  358. data/spec/unit/functions/new_spec.rb +14 -14
  359. data/spec/unit/functions/require_spec.rb +2 -0
  360. data/spec/unit/functions/shared.rb +12 -0
  361. data/spec/unit/functions/step_spec.rb +1 -1
  362. data/spec/unit/functions4_spec.rb +49 -4
  363. data/spec/unit/indirector/catalog/compiler_spec.rb +3 -3
  364. data/spec/unit/indirector/file_bucket_file/file_spec.rb +148 -94
  365. data/spec/unit/indirector/node/ldap_spec.rb +15 -12
  366. data/spec/unit/indirector/rest_spec.rb +0 -43
  367. data/spec/unit/interface/action_spec.rb +33 -0
  368. data/spec/unit/module_tool/applications/builder_spec.rb +7 -0
  369. data/spec/unit/module_tool/applications/installer_spec.rb +8 -0
  370. data/spec/unit/module_tool/applications/uninstaller_spec.rb +8 -0
  371. data/spec/unit/module_tool/applications/upgrader_spec.rb +6 -0
  372. data/spec/unit/network/http/connection_spec.rb +1 -1
  373. data/spec/unit/network/http/factory_spec.rb +28 -35
  374. data/spec/unit/parser/compiler_spec.rb +0 -8
  375. data/spec/unit/parser/environment_compiler_spec.rb +36 -0
  376. data/spec/unit/parser/functions/create_resources_spec.rb +9 -0
  377. data/spec/unit/parser/functions/inline_template_spec.rb +7 -0
  378. data/spec/unit/parser/functions/realize_spec.rb +9 -0
  379. data/spec/unit/parser/functions/tag_spec.rb +7 -0
  380. data/spec/unit/parser/functions/tagged_spec.rb +25 -0
  381. data/spec/unit/parser/functions/template_spec.rb +8 -0
  382. data/spec/unit/parser/scope_spec.rb +19 -0
  383. data/spec/unit/pops/evaluator/conditionals_spec.rb +1 -1
  384. data/spec/unit/pops/loaders/loader_spec.rb +516 -0
  385. data/spec/unit/pops/loaders/loaders_spec.rb +11 -0
  386. data/spec/unit/pops/loaders/module_loaders_spec.rb +43 -0
  387. data/spec/unit/pops/loaders/static_loader_spec.rb +15 -7
  388. data/spec/unit/pops/model/model_spec.rb +5 -0
  389. data/spec/unit/pops/parser/lexer2_spec.rb +15 -0
  390. data/spec/unit/pops/parser/locator_spec.rb +20 -0
  391. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +33 -0
  392. data/spec/unit/pops/parser/parse_calls_spec.rb +28 -0
  393. data/spec/unit/pops/parser/parse_conditionals_spec.rb +12 -0
  394. data/spec/unit/pops/parser/parse_plan_spec.rb +48 -0
  395. data/spec/unit/pops/serialization/packer_spec.rb +8 -0
  396. data/spec/unit/pops/serialization/serialization_spec.rb +30 -0
  397. data/spec/unit/pops/serialization/to_from_hr_spec.rb +31 -0
  398. data/spec/unit/pops/types/error_spec.rb +207 -0
  399. data/spec/unit/pops/types/p_init_type_spec.rb +98 -0
  400. data/spec/unit/pops/types/p_object_type_spec.rb +275 -10
  401. data/spec/unit/pops/types/p_uri_type_spec.rb +191 -0
  402. data/spec/unit/pops/types/ruby_generator_spec.rb +82 -44
  403. data/spec/unit/pops/types/task_spec.rb +353 -0
  404. data/spec/unit/pops/types/type_calculator_spec.rb +76 -5
  405. data/spec/unit/pops/types/type_formatter_spec.rb +31 -13
  406. data/spec/unit/pops/types/type_parser_spec.rb +13 -1
  407. data/spec/unit/pops/types/types_spec.rb +60 -0
  408. data/spec/unit/pops/validator/validator_spec.rb +76 -0
  409. data/spec/unit/provider/group/groupadd_spec.rb +77 -1
  410. data/spec/unit/provider/group/pw_spec.rb +4 -4
  411. data/spec/unit/provider/group/windows_adsi_spec.rb +22 -79
  412. data/spec/unit/provider/mount_spec.rb +18 -5
  413. data/spec/unit/provider/nameservice_spec.rb +5 -5
  414. data/spec/unit/provider/package/dnf_spec.rb +2 -2
  415. data/spec/unit/provider/package/gem_spec.rb +1 -1
  416. data/spec/unit/provider/package/pkg_spec.rb +3 -0
  417. data/spec/unit/provider/package/yum_spec.rb +40 -0
  418. data/spec/unit/provider/service/launchd_spec.rb +2 -1
  419. data/spec/unit/provider/service/redhat_spec.rb +5 -0
  420. data/spec/unit/provider/service/systemd_spec.rb +1 -1
  421. data/spec/unit/provider/user/hpux_spec.rb +2 -2
  422. data/spec/unit/provider/user/openbsd_spec.rb +2 -2
  423. data/spec/unit/provider/user/pw_spec.rb +14 -14
  424. data/spec/unit/provider/user/user_role_add_spec.rb +19 -2
  425. data/spec/unit/provider/user/useradd_spec.rb +188 -22
  426. data/spec/unit/provider/user/windows_adsi_spec.rb +4 -4
  427. data/spec/unit/provider/zfs/zfs_spec.rb +55 -1
  428. data/spec/unit/provider_spec.rb +48 -0
  429. data/spec/unit/puppet_pal_2pec.rb +1005 -0
  430. data/spec/unit/puppet_pal_spec.rb +11 -0
  431. data/spec/unit/settings/ini_file_spec.rb +313 -2
  432. data/spec/unit/ssl/certificate_request_spec.rb +42 -1
  433. data/spec/unit/ssl/certificate_revocation_list_spec.rb +2 -1
  434. data/spec/unit/transaction/report_spec.rb +1 -0
  435. data/spec/unit/transaction_spec.rb +112 -21
  436. data/spec/unit/type/file/checksum_spec.rb +20 -0
  437. data/spec/unit/type/file_spec.rb +8 -0
  438. data/spec/unit/type/group_spec.rb +8 -0
  439. data/spec/unit/type/k5login_spec.rb +22 -1
  440. data/spec/unit/type/scheduled_task_spec.rb +15 -0
  441. data/spec/unit/type/user_spec.rb +11 -1
  442. data/spec/unit/type/yumrepo_spec.rb +5 -0
  443. data/spec/unit/util/checksums_spec.rb +3 -3
  444. data/spec/unit/util/log/destinations_spec.rb +14 -0
  445. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  446. data/spec/unit/util/plist_spec.rb +3 -3
  447. data/spec/unit/util/windows/adsi_spec.rb +27 -31
  448. data/spec/unit/util/windows/sid_spec.rb +15 -86
  449. data/spec/unit/util_spec.rb +17 -3
  450. data/tasks/manpages.rake +1 -1
  451. metadata +216 -178
  452. data/lib/puppet/bindings.rb +0 -148
  453. data/lib/puppet/configurer/downloader_factory.rb +0 -44
  454. data/spec/unit/configurer/downloader_factory_spec.rb +0 -129
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+ require 'puppet/pops'
3
+ require 'puppet_spec/compiler'
4
+
5
+ module Puppet::Pops
6
+ module Types
7
+ describe 'Error type' do
8
+ context 'when used in Puppet expressions' do
9
+ include PuppetSpec::Compiler
10
+ it 'is equal to itself only' do
11
+ expect(eval_and_collect_notices(<<-CODE)).to eq(%w(true true false false))
12
+ $t = Error
13
+ notice(Error =~ Type[Error])
14
+ notice(Error == Error)
15
+ notice(Error < Error)
16
+ notice(Error > Error)
17
+ CODE
18
+ end
19
+
20
+ context "when parameterized" do
21
+ it 'is equal other types with the same parameterization' do
22
+ code = <<-CODE
23
+ notice(Error['puppet/error'] == Error['puppet/error', default])
24
+ notice(Error['puppet/error', 'ouch'] == Error['puppet/error', 'ouch'])
25
+ notice(Error['puppet/error', 'ouch'] != Error['puppet/error', 'ouch!'])
26
+ CODE
27
+ expect(eval_and_collect_notices(code)).to eq(%w(true true true))
28
+ end
29
+
30
+ it 'is assignable from more qualified types' do
31
+ expect(eval_and_collect_notices(<<-CODE)).to eq(%w(true true true))
32
+ notice(Error > Error['puppet/error'])
33
+ notice(Error['puppet/error'] > Error['puppet/error', 'ouch'])
34
+ notice(Error['puppet/error', default] > Error['puppet/error', 'ouch'])
35
+ CODE
36
+ end
37
+
38
+ it 'is not assignable unless kind is assignable' do
39
+ expect(eval_and_collect_notices(<<-CODE)).to eq(%w(true false true false true false true))
40
+ notice(Error[/a/] > Error['hah'])
41
+ notice(Error[/a/] > Error['hbh'])
42
+ notice(Error[Enum[a,b,c]] > Error[a])
43
+ notice(Error[Enum[a,b,c]] > Error[d])
44
+ notice(Error[Pattern[/a/, /b/]] > Error[a])
45
+ notice(Error[Pattern[/a/, /b/]] > Error[c])
46
+ notice(Error[Pattern[/a/, /b/]] > Error[Enum[a, b]])
47
+ CODE
48
+ end
49
+
50
+ it 'presents parsable string form' do
51
+ code = <<-CODE
52
+ notice(Error['a'])
53
+ notice(Error[/a/])
54
+ notice(Error[Enum['a', 'b']])
55
+ notice(Error[Pattern[/a/, /b/]])
56
+ notice(Error['a', default])
57
+ notice(Error[/a/, default])
58
+ notice(Error[Enum['a', 'b'], default])
59
+ notice(Error[Pattern[/a/, /b/], default])
60
+ notice(Error[default,'a'])
61
+ notice(Error[default,/a/])
62
+ notice(Error[default,Enum['a', 'b']])
63
+ notice(Error[default,Pattern[/a/, /b/]])
64
+ notice(Error['a','a'])
65
+ notice(Error[/a/,/a/])
66
+ notice(Error[Enum['a', 'b'],Enum['a', 'b']])
67
+ notice(Error[Pattern[/a/, /b/],Pattern[/a/, /b/]])
68
+ CODE
69
+ expect(eval_and_collect_notices(code)).to eq([
70
+ "Error['a']",
71
+ 'Error[/a/]',
72
+ "Error[Enum['a', 'b']]",
73
+ "Error[Pattern[/a/, /b/]]",
74
+ "Error['a']",
75
+ 'Error[/a/]',
76
+ "Error[Enum['a', 'b']]",
77
+ "Error[Pattern[/a/, /b/]]",
78
+ "Error[default, 'a']",
79
+ 'Error[default, /a/]',
80
+ "Error[default, Enum['a', 'b']]",
81
+ "Error[default, Pattern[/a/, /b/]]",
82
+ "Error['a', 'a']",
83
+ 'Error[/a/, /a/]',
84
+ "Error[Enum['a', 'b'], Enum['a', 'b']]",
85
+ "Error[Pattern[/a/, /b/], Pattern[/a/, /b/]]",
86
+ ])
87
+ end
88
+ end
89
+
90
+ context 'an Error instance' do
91
+ it 'can be created using positional arguments' do
92
+ code = <<-CODE
93
+ $o = Error('bad things happened', 'puppet/error', {'detail' => 'val'}, 'OOPS')
94
+ notice($o)
95
+ notice(type($o))
96
+ CODE
97
+ expect(eval_and_collect_notices(code)).to eq([
98
+ "Error({'msg' => 'bad things happened', 'kind' => 'puppet/error', 'details' => {'detail' => 'val'}, 'issue_code' => 'OOPS'})",
99
+ "Error['puppet/error', 'OOPS']"
100
+ ])
101
+ end
102
+
103
+ it 'can be created using named arguments' do
104
+ code = <<-CODE
105
+ $o = Error(msg => 'Sorry, not implemented', kind => 'puppet/error', issue_code => 'NOT_IMPLEMENTED')
106
+ notice($o)
107
+ notice(type($o))
108
+ CODE
109
+ expect(eval_and_collect_notices(code)).to eq([
110
+ "Error({'msg' => 'Sorry, not implemented', 'kind' => 'puppet/error', 'issue_code' => 'NOT_IMPLEMENTED'})",
111
+ "Error['puppet/error', 'NOT_IMPLEMENTED']"
112
+ ])
113
+ end
114
+
115
+ it 'exposes message' do
116
+ code = <<-CODE
117
+ $o = Error(msg => 'Sorry, not implemented', kind => 'puppet/error', issue_code => 'NOT_IMPLEMENTED')
118
+ notice($o.message)
119
+ CODE
120
+ expect(eval_and_collect_notices(code)).to eq(["Sorry, not implemented"])
121
+ end
122
+
123
+ it 'exposes kind' do
124
+ code = <<-CODE
125
+ $o = Error(msg => 'Sorry, not implemented', kind => 'puppet/error', issue_code => 'NOT_IMPLEMENTED')
126
+ notice($o.kind)
127
+ CODE
128
+ expect(eval_and_collect_notices(code)).to eq(["puppet/error"])
129
+ end
130
+
131
+ it 'exposes issue_code' do
132
+ code = <<-CODE
133
+ $o = Error(msg => 'Sorry, not implemented', kind => 'puppet/error', issue_code => 'NOT_IMPLEMENTED')
134
+ notice($o.issue_code)
135
+ CODE
136
+ expect(eval_and_collect_notices(code)).to eq(["NOT_IMPLEMENTED"])
137
+ end
138
+
139
+ it 'exposes details' do
140
+ code = <<-CODE
141
+ $o = Error(msg => 'Sorry, not implemented', kind => 'puppet/error', details => { 'detailk' => 'detailv' })
142
+ notice($o.details)
143
+ CODE
144
+ expect(eval_and_collect_notices(code)).to eq(["{detailk => detailv}"])
145
+ end
146
+
147
+ it 'is an instance of its inferred type' do
148
+ code = <<-CODE
149
+ $o = Error('bad things happened', 'puppet/error')
150
+ notice($o =~ type($o))
151
+ CODE
152
+ expect(eval_and_collect_notices(code)).to eq(['true'])
153
+ end
154
+
155
+ it 'is an instance of Error with matching kind' do
156
+ code = <<-CODE
157
+ $o = Error('bad things happened', 'puppet/error')
158
+ notice($o =~ Error[/puppet\\/error/])
159
+ CODE
160
+ expect(eval_and_collect_notices(code)).to eq(['true'])
161
+ end
162
+
163
+ it 'is an instance of Error with matching issue_code' do
164
+ code = <<-CODE
165
+ $o = Error('bad things happened', 'puppet/error', {}, 'FEE')
166
+ notice($o =~ Error[default, 'FEE'])
167
+ CODE
168
+ expect(eval_and_collect_notices(code)).to eq(['true'])
169
+ end
170
+
171
+ it 'is an instance of Error with matching kind and issue_code' do
172
+ code = <<-CODE
173
+ $o = Error('bad things happened', 'puppet/error', {}, 'FEE')
174
+ notice($o =~ Error['puppet/error', 'FEE'])
175
+ CODE
176
+ expect(eval_and_collect_notices(code)).to eq(['true'])
177
+ end
178
+
179
+ it 'is not an instance of Error unless kind matches' do
180
+ code = <<-CODE
181
+ $o = Error('bad things happened', 'puppetlabs/error')
182
+ notice($o =~ Error[/puppet\\/error/])
183
+ CODE
184
+ expect(eval_and_collect_notices(code)).to eq(['false'])
185
+ end
186
+
187
+ it 'is not an instance of Error unless issue_code matches' do
188
+ code = <<-CODE
189
+ $o = Error('bad things happened', 'puppetlabs/error', {}, 'BAR')
190
+ notice($o =~ Error[default, 'FOO'])
191
+ CODE
192
+ expect(eval_and_collect_notices(code)).to eq(['false'])
193
+ end
194
+
195
+ it 'is not an instance of Error unless both kind and issue is a match' do
196
+ code = <<-CODE
197
+ $o = Error('bad things happened', 'puppet/error', {}, 'FEE')
198
+ notice($o =~ Error['puppetlabs/error', 'FEE'])
199
+ notice($o =~ Error['puppet/error', 'FUM'])
200
+ CODE
201
+ expect(eval_and_collect_notices(code)).to eq(['false', 'false'])
202
+ end
203
+ end
204
+ end
205
+ end
206
+ end
207
+ end
@@ -279,6 +279,104 @@ describe 'The Init Type' do
279
279
  CODE
280
280
  expect(eval_and_collect_notices(code)).to eql(["One({'init_one' => 'w'})"])
281
281
  end
282
+
283
+ context 'computes if x is an instance such that' do
284
+ %w(true false True False TRUE FALSE tRuE FaLsE Yes No yes no YES NO YeS nO y n Y N).each do |str|
285
+ it "string '#{str}' is an instance of Init[Boolean]" do
286
+ expect(eval_and_collect_notices("notice('#{str}' =~ Init[Boolean])")).to eql(['true'])
287
+ end
288
+ end
289
+
290
+ it 'arbitrary string is not an instance of Init[Boolean]' do
291
+ expect(eval_and_collect_notices("notice('blue' =~ Init[Boolean])")).to eql(['false'])
292
+ end
293
+
294
+ it 'empty string is not an instance of Init[Boolean]' do
295
+ expect(eval_and_collect_notices("notice('' =~ Init[Boolean])")).to eql(['false'])
296
+ end
297
+
298
+ it 'undef string is not an instance of Init[Boolean]' do
299
+ expect(eval_and_collect_notices("notice(undef =~ Init[Boolean])")).to eql(['false'])
300
+ end
301
+
302
+ %w(0 1 0634 0x3b -0xba 0b1001 +0b1111 23.14 -2.3 2e-21 1.23e18 -0.23e18).each do |str|
303
+ it "string '#{str}' is an instance of Init[Numeric]" do
304
+ expect(eval_and_collect_notices("notice('#{str}' =~ Init[Numeric])")).to eql(['true'])
305
+ end
306
+ end
307
+
308
+ it 'non numeric string is not an instance of Init[Numeric]' do
309
+ expect(eval_and_collect_notices("notice('blue' =~ Init[Numeric])")).to eql(['false'])
310
+ end
311
+
312
+ it 'empty string is not an instance of Init[Numeric]' do
313
+ expect(eval_and_collect_notices("notice('' =~ Init[Numeric])")).to eql(['false'])
314
+ end
315
+
316
+ it 'undef is not an instance of Init[Numeric]' do
317
+ expect(eval_and_collect_notices("notice(undef =~ Init[Numeric])")).to eql(['false'])
318
+ end
319
+
320
+ %w(0 1 0634 0x3b -0xba 0b1001 +0b1111 23.14 -2.3 2e-21 1.23e18 -0.23e18).each do |str|
321
+ it "string '#{str}' is an instance of Init[Float]" do
322
+ expect(eval_and_collect_notices("notice('#{str}' =~ Init[Float])")).to eql(['true'])
323
+ end
324
+ end
325
+
326
+ it 'non numeric string is not an instance of Init[Float]' do
327
+ expect(eval_and_collect_notices("notice('blue' =~ Init[Float])")).to eql(['false'])
328
+ end
329
+
330
+ it 'empty string is not an instance of Init[Float]' do
331
+ expect(eval_and_collect_notices("notice('' =~ Init[Float])")).to eql(['false'])
332
+ end
333
+
334
+ it 'undef is not an instance of Init[Float]' do
335
+ expect(eval_and_collect_notices("notice(undef =~ Init[Float])")).to eql(['false'])
336
+ end
337
+
338
+ %w(0 1 0634 0x3b -0xba 0b1001 0b1111).each do |str|
339
+ it "string '#{str}' is an instance of Init[Integer]" do
340
+ expect(eval_and_collect_notices("notice('#{str}' =~ Init[Integer])")).to eql(['true'])
341
+ end
342
+ end
343
+
344
+ %w(23.14 -2.3 2e-21 1.23e18 -0.23e18).each do |str|
345
+ it "valid float string '#{str}' is not an instance of Init[Integer]" do
346
+ expect(eval_and_collect_notices("notice('#{str}' =~ Init[Integer])")).to eql(['false'])
347
+ end
348
+ end
349
+
350
+ it 'non numeric string is not an instance of Init[Integer]' do
351
+ expect(eval_and_collect_notices("notice('blue' =~ Init[Integer])")).to eql(['false'])
352
+ end
353
+
354
+ it 'empty string is not an instance of Init[Integer]' do
355
+ expect(eval_and_collect_notices("notice('' =~ Init[Integer])")).to eql(['false'])
356
+ end
357
+
358
+ it 'undef is not an instance of Init[Integer]' do
359
+ expect(eval_and_collect_notices("notice(undef =~ Init[Integer])")).to eql(['false'])
360
+ end
361
+
362
+ %w(1.2.3 1.1.1-a3 1.2.3+b3 1.2.3-a3+b3).each do |str|
363
+ it "string '#{str}' is an instance of Init[SemVer]" do
364
+ expect(eval_and_collect_notices("notice('#{str}' =~ Init[SemVer])")).to eql(['true'])
365
+ end
366
+ end
367
+
368
+ it 'non SemVer compliant string is not an instance of Init[SemVer]' do
369
+ expect(eval_and_collect_notices("notice('blue' =~ Init[SemVer])")).to eql(['false'])
370
+ end
371
+
372
+ it 'empty string is not an instance of Init[SemVer]' do
373
+ expect(eval_and_collect_notices("notice('' =~ Init[SemVer])")).to eql(['false'])
374
+ end
375
+
376
+ it 'undef is not an instance of Init[SemVer]' do
377
+ expect(eval_and_collect_notices("notice(undef =~ Init[SemVer])")).to eql(['false'])
378
+ end
379
+ end
282
380
  end
283
381
  end
284
382
  end
@@ -9,13 +9,17 @@ describe 'The Object Type' do
9
9
 
10
10
  let(:parser) { TypeParser.singleton }
11
11
  let(:pp_parser) { Parser::EvaluatingParser.new }
12
+ let(:env) { Puppet::Node::Environment.create(:testing, []) }
13
+ let(:node) { Puppet::Node.new('testnode', :environment => env) }
12
14
  let(:loader) { Loaders.find_loader(nil) }
13
15
  let(:factory) { TypeFactory }
14
16
 
15
- around(:each) do |example|
16
- Puppet.override(:loaders => Loaders.new(Puppet::Node::Environment.create(:testing, []))) do
17
- example.run
18
- end
17
+ before(:each) do
18
+ Puppet.push_context(:loaders => Loaders.new(env))
19
+ end
20
+
21
+ after(:each) do
22
+ Puppet.pop_context()
19
23
  end
20
24
 
21
25
  def type_object_t(name, body_string)
@@ -765,14 +769,30 @@ describe 'The Object Type' do
765
769
  expect(obj.to_s).to eql("Object[{name => 'MyObject', attributes => {'a' => Integer}}]")
766
770
  end
767
771
 
768
- it 'produced hash that does not include defaults' do
772
+ it 'produced hash that does not include default for equality_include_type' do
773
+ obj = t = parse_object('MyObject', <<-OBJECT)
774
+ attributes => { a => Integer },
775
+ equality_include_type => true
776
+ OBJECT
777
+ expect(obj.to_s).to eql("Object[{name => 'MyObject', attributes => {'a' => Integer}}]")
778
+ end
779
+
780
+ it 'constants are presented in a separate hash if they use a generic type' do
769
781
  obj = t = parse_object('MyObject', <<-OBJECT)
770
782
  attributes => {
771
- a => { type => Integer, value => 23, kind => constant, final => true },
783
+ a => { type => Integer, value => 23, kind => constant },
784
+ },
785
+ OBJECT
786
+ expect(obj.to_s).to eql("Object[{name => 'MyObject', constants => {'a' => 23}}]")
787
+ end
788
+
789
+ it 'constants are not presented in a separate hash unless they use a generic type' do
790
+ obj = t = parse_object('MyObject', <<-OBJECT)
791
+ attributes => {
792
+ a => { type => Integer[0, 30], value => 23, kind => constant },
772
793
  },
773
- equality_include_type => true
774
794
  OBJECT
775
- expect(obj.to_s).to eql("Object[{name => 'MyObject', attributes => {'a' => {type => Integer, kind => constant, value => 23}}}]")
795
+ expect(obj.to_s).to eql("Object[{name => 'MyObject', attributes => {'a' => {type => Integer[0, 30], kind => constant, value => 23}}}]")
776
796
  end
777
797
 
778
798
  it 'can create an equal copy from produced hash' do
@@ -1109,11 +1129,13 @@ describe 'The Object Type' do
1109
1129
  "name => 'MyFirstObject', "+
1110
1130
  "attributes => {"+
1111
1131
  "'first_a' => Integer, "+
1112
- "'first_b' => {type => String, kind => constant, value => 'the first constant'}, "+
1113
1132
  "'first_c' => {type => String, final => true, kind => derived}, "+
1114
1133
  "'first_d' => {type => String, kind => given_or_derived}, "+
1115
1134
  "'first_e' => String"+
1116
1135
  "}, "+
1136
+ "constants => {"+
1137
+ "'first_b' => 'the first constant'"+
1138
+ "}, "+
1117
1139
  "functions => {"+
1118
1140
  "'first_x' => Callable[Integer], "+
1119
1141
  "'first_y' => Callable[String]"+
@@ -1125,9 +1147,11 @@ describe 'The Object Type' do
1125
1147
  "parent => MyFirstObject, "+
1126
1148
  "attributes => {"+
1127
1149
  "'second_a' => Integer, "+
1128
- "'second_b' => {type => String, kind => constant, value => 'the second constant'}, "+
1129
1150
  "'first_e' => {type => Enum['fee', 'foo', 'fum'], final => true, override => true, value => 'fee'}"+
1130
1151
  "}, "+
1152
+ "constants => {"+
1153
+ "'second_b' => 'the second constant'"+
1154
+ "}, "+
1131
1155
  "functions => {"+
1132
1156
  "'second_x' => Callable[Integer], "+
1133
1157
  "'second_y' => Callable[String]"+
@@ -1136,6 +1160,247 @@ describe 'The Object Type' do
1136
1160
  "}]"
1137
1161
  ])
1138
1162
  end
1163
+
1164
+ context 'object with type parameters' do
1165
+ it 'can be declared' do
1166
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['ok'])
1167
+ type MyType = Object[
1168
+ type_parameters => {
1169
+ p1 => String
1170
+ }]
1171
+ notice('ok')
1172
+ PUPPET
1173
+ end
1174
+
1175
+ it 'can be referenced' do
1176
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(["MyType['hello']"])
1177
+ type MyType = Object[
1178
+ type_parameters => {
1179
+ p1 => String
1180
+ }]
1181
+
1182
+ notice(MyType['hello'])
1183
+ PUPPET
1184
+ end
1185
+
1186
+ it 'leading unset parameters are represented as default in string representation' do
1187
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(["MyType[default, 'world']"])
1188
+ type MyType = Object[
1189
+ type_parameters => {
1190
+ p1 => String,
1191
+ p2 => String,
1192
+ }]
1193
+
1194
+ notice(MyType[default, 'world'])
1195
+ PUPPET
1196
+ end
1197
+
1198
+ it 'trailing unset parameters are skipped in string representation' do
1199
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(["MyType['my']"])
1200
+ type MyType = Object[
1201
+ type_parameters => {
1202
+ p1 => String,
1203
+ p2 => String,
1204
+ }]
1205
+
1206
+ notice(MyType['my'])
1207
+ PUPPET
1208
+ end
1209
+
1210
+ it 'a type with more than 2 type parameters uses named arguments in string representation' do
1211
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(["MyType[{'p1' => 'my'}]"])
1212
+ type MyType = Object[
1213
+ type_parameters => {
1214
+ p1 => String,
1215
+ p2 => String,
1216
+ p3 => String,
1217
+ }]
1218
+
1219
+ notice(MyType['my'])
1220
+ PUPPET
1221
+ end
1222
+
1223
+ it 'can be used without parameters' do
1224
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(["Object[{name => 'MyType', type_parameters => {'p1' => String}}]"])
1225
+ type MyType = Object[
1226
+ type_parameters => {
1227
+ p1 => String
1228
+ }]
1229
+
1230
+ notice(MyType)
1231
+ PUPPET
1232
+ end
1233
+
1234
+ it 'involves type parameter values when testing instance of' do
1235
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['true', 'false', 'true'])
1236
+ type MyType = Object[
1237
+ type_parameters => {
1238
+ p1 => String
1239
+ },
1240
+ attributes => {
1241
+ p1 => String
1242
+ }]
1243
+
1244
+ $x = MyType('world')
1245
+ notice($x =~ MyType)
1246
+ notice($x =~ MyType['hello'])
1247
+ notice($x =~ MyType['world'])
1248
+ PUPPET
1249
+ end
1250
+
1251
+ it 'involves type parameter values when testing assignability' do
1252
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['true', 'false', 'true', 'true', 'false', 'true'])
1253
+ type MyType = Object[
1254
+ type_parameters => {
1255
+ p1 => String
1256
+ },
1257
+ attributes => {
1258
+ p1 => String
1259
+ }]
1260
+
1261
+ $x = MyType['world']
1262
+ notice($x <= MyType)
1263
+ notice($x <= MyType['hello'])
1264
+ notice($x <= MyType['world'])
1265
+
1266
+ notice(MyType >= $x)
1267
+ notice(MyType['hello'] >= $x)
1268
+ notice(MyType['world'] >= $x)
1269
+ PUPPET
1270
+ end
1271
+
1272
+ it 'parameters can be types' do
1273
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['true', 'true', 'true', 'true', 'false'])
1274
+ type MyType = Object[
1275
+ type_parameters => {
1276
+ p1 => Variant[String,Regexp,Type[Enum],Type[Pattern],Type[NotUndef]],
1277
+ p2 => Variant[String,Regexp,Type[Enum],Type[Pattern],Type[NotUndef]],
1278
+ },
1279
+ attributes => {
1280
+ p1 => String,
1281
+ p2 => String
1282
+ }]
1283
+ $x = MyType('good bye', 'cruel world')
1284
+ notice($x =~ MyType)
1285
+ notice($x =~ MyType[Enum['hello', 'good bye']])
1286
+ notice($x =~ MyType[Enum['hello', 'good bye'], Pattern[/world/, /universe/]])
1287
+ notice($x =~ MyType[NotUndef, NotUndef])
1288
+ notice($x =~ MyType[Enum['hello', 'yo']])
1289
+ PUPPET
1290
+ end
1291
+
1292
+ it 'parameters can be provided using named arguments' do
1293
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['true', 'false', 'true'])
1294
+ type MyType = Object[
1295
+ type_parameters => {
1296
+ p1 => String,
1297
+ p2 => String
1298
+ },
1299
+ attributes => {
1300
+ p1 => String,
1301
+ p2 => String
1302
+ }]
1303
+ $x = MyType('good bye', 'cruel world')
1304
+ notice($x =~ MyType)
1305
+ notice($x =~ MyType[p1 => 'hello', p2 => 'cruel world'])
1306
+ notice($x =~ MyType[p1 => 'good bye', p2 => 'cruel world'])
1307
+ PUPPET
1308
+ end
1309
+
1310
+ it 'at least one parameter must be given' do
1311
+ expect{eval_and_collect_notices(<<-PUPPET, node)}.to raise_error(/The MyType-Type cannot be parameterized using an empty parameter list/)
1312
+ type MyType = Object[
1313
+ type_parameters => {
1314
+ p1 => Variant[String,Regexp,Type[Enum],Type[Pattern]],
1315
+ },
1316
+ attributes => {
1317
+ p1 => String,
1318
+ }]
1319
+ notice(MyType[default])
1320
+ PUPPET
1321
+ end
1322
+
1323
+ it 'undef is a valid value for a type parameter' do
1324
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['true', 'false'])
1325
+ type MyType = Object[
1326
+ type_parameters => {
1327
+ p1 => Optional[String],
1328
+ },
1329
+ attributes => {
1330
+ p1 => Optional[String],
1331
+ }]
1332
+ notice(MyType() =~ MyType[undef])
1333
+ notice(MyType('hello') =~ MyType[undef])
1334
+ PUPPET
1335
+ end
1336
+
1337
+ it 'Type parameters does not mean that type must be parameterized' do
1338
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['true'])
1339
+ type MyType = Object[
1340
+ type_parameters => {
1341
+ p1 => Variant[Undef,String,Regexp,Type[Enum],Type[Pattern]],
1342
+ p2 => Variant[Undef,String,Regexp,Type[Enum],Type[Pattern]],
1343
+ },
1344
+ attributes => {
1345
+ p1 => String,
1346
+ p2 => String
1347
+ }]
1348
+ notice(MyType('hello', 'world') =~ MyType)
1349
+ PUPPET
1350
+ end
1351
+
1352
+ it 'A parameterized type is assignable to another parameterized type if base type and parameters are assignable' do
1353
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['true'])
1354
+ type MyType = Object[
1355
+ type_parameters => {
1356
+ p1 => Variant[Undef,String,Regexp,Type[Enum],Type[Pattern]],
1357
+ p2 => Variant[Undef,String,Regexp,Type[Enum],Type[Pattern]],
1358
+ },
1359
+ attributes => {
1360
+ p1 => String,
1361
+ p2 => String
1362
+ }]
1363
+ notice(MyType[Pattern[/a/,/b/]] > MyType[Enum['a','b']])
1364
+ PUPPET
1365
+ end
1366
+
1367
+ it 'Instance is inferred to parameterized type' do
1368
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['true', 'true', 'true', 'true', 'true'])
1369
+ type MyType = Object[
1370
+ type_parameters => {
1371
+ p1 => Variant[Undef,String,Regexp,Type[Enum],Type[Pattern]],
1372
+ p2 => Variant[Undef,String,Regexp,Type[Enum],Type[Pattern]],
1373
+ },
1374
+ attributes => {
1375
+ p1 => String,
1376
+ p2 => String
1377
+ }]
1378
+ $x = MyType('hello', 'world')
1379
+ notice(type($x, generalized) == MyType)
1380
+ notice(type($x) < MyType)
1381
+ notice(type($x) < MyType['hello'])
1382
+ notice(type($x) < MyType[/hello/, /world/])
1383
+ notice(type($x) == MyType['hello', 'world'])
1384
+ PUPPET
1385
+ end
1386
+
1387
+ it 'Attributes of instance of parameterized type can be accessed using function calls' do
1388
+ expect(eval_and_collect_notices(<<-PUPPET, node)).to eql(['hello', 'world'])
1389
+ type MyType = Object[
1390
+ type_parameters => {
1391
+ p1 => Variant[Undef,String,Regexp,Type[Enum],Type[Pattern]],
1392
+ p2 => Variant[Undef,String,Regexp,Type[Enum],Type[Pattern]],
1393
+ },
1394
+ attributes => {
1395
+ p1 => String,
1396
+ p2 => String
1397
+ }]
1398
+ $x = MyType('hello', 'world')
1399
+ notice($x.p1)
1400
+ notice($x.p2)
1401
+ PUPPET
1402
+ end
1403
+ end
1139
1404
  end
1140
1405
 
1141
1406
  context "when used with function 'new'" do