puppet 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (745) hide show
  1. data/CONTRIBUTING.md +5 -5
  2. data/Gemfile +2 -2
  3. data/LICENSE +2 -2
  4. data/README.md +5 -0
  5. data/conf/puppet.conf +1 -1
  6. data/ext/project_data.yaml +2 -0
  7. data/ext/redhat/puppet.spec.erb +0 -9
  8. data/ext/upload_facts.rb +1 -1
  9. data/lib/hiera_puppet.rb +6 -14
  10. data/lib/puppet/application/agent.rb +3 -4
  11. data/lib/puppet/application/apply.rb +1 -1
  12. data/lib/puppet/application/ca.rb +1 -0
  13. data/lib/puppet/application/cert.rb +1 -1
  14. data/lib/puppet/application/filebucket.rb +1 -1
  15. data/lib/puppet/application/inspect.rb +2 -2
  16. data/lib/puppet/application/lookup.rb +8 -20
  17. data/lib/puppet/application/master.rb +1 -1
  18. data/lib/puppet/application/resource.rb +1 -5
  19. data/lib/puppet/data_providers/hiera_config.rb +2 -4
  20. data/lib/puppet/data_providers/hiera_interpolate.rb +12 -105
  21. data/lib/puppet/data_providers/json_data_provider_factory.rb +1 -8
  22. data/lib/puppet/data_providers/yaml_data_provider_factory.rb +2 -8
  23. data/lib/puppet/defaults.rb +104 -25
  24. data/lib/puppet/face/config.rb +1 -1
  25. data/lib/puppet/face/help/man.erb +1 -1
  26. data/lib/puppet/file_system/uniquefile.rb +2 -2
  27. data/lib/puppet/file_system/windows.rb +1 -15
  28. data/lib/puppet/functions/assert_type.rb +1 -1
  29. data/lib/puppet/functions/dig.rb +39 -0
  30. data/lib/puppet/functions/hiera_include.rb +2 -2
  31. data/lib/puppet/functions/inline_epp.rb +1 -1
  32. data/lib/puppet/functions/lest.rb +53 -0
  33. data/lib/puppet/functions/lookup.rb +40 -30
  34. data/lib/puppet/functions/new.rb +502 -0
  35. data/lib/puppet/functions/regsubst.rb +11 -10
  36. data/lib/puppet/functions/then.rb +74 -0
  37. data/lib/puppet/functions/type.rb +4 -4
  38. data/lib/puppet/functions/with.rb +1 -1
  39. data/lib/puppet/functions.rb +69 -0
  40. data/lib/puppet/indirector/catalog/compiler.rb +4 -1
  41. data/lib/puppet/indirector/msgpack.rb +1 -1
  42. data/lib/puppet/indirector/resource_type/parser.rb +5 -0
  43. data/lib/puppet/indirector/rest.rb +5 -1
  44. data/lib/puppet/indirector/terminus.rb +4 -4
  45. data/lib/puppet/loaders.rb +2 -0
  46. data/lib/puppet/metatype/manager.rb +19 -2
  47. data/lib/puppet/module.rb +3 -3
  48. data/lib/puppet/module_tool/applications/application.rb +1 -1
  49. data/lib/puppet/module_tool/applications/builder.rb +2 -2
  50. data/lib/puppet/module_tool/skeleton/templates/generator/Gemfile +6 -2
  51. data/lib/puppet/module_tool/skeleton/templates/generator/Rakefile +19 -4
  52. data/lib/puppet/module_tool/skeleton/templates/generator/{tests → examples}/init.pp.erb +1 -1
  53. data/lib/puppet/module_tool/skeleton/templates/generator/spec/classes/init_spec.rb.erb +0 -1
  54. data/lib/puppet/network/auth_config_parser.rb +1 -1
  55. data/lib/puppet/network/http/api/indirected_routes.rb +0 -2
  56. data/lib/puppet/network/http/api/master/v3/environment.rb +6 -2
  57. data/lib/puppet/network/http/rack/rest.rb +10 -1
  58. data/lib/puppet/parser/ast/pops_bridge.rb +20 -3
  59. data/lib/puppet/parser/compiler/catalog_validator/relationship_validator.rb +24 -2
  60. data/lib/puppet/parser/e4_parser_adapter.rb +13 -12
  61. data/lib/puppet/parser/environment_compiler.rb +2 -2
  62. data/lib/puppet/parser/functions/hiera_include.rb +2 -2
  63. data/lib/puppet/parser/functions/inline_epp.rb +1 -1
  64. data/lib/puppet/parser/functions/lookup.rb +0 -3
  65. data/lib/puppet/parser/resource.rb +14 -5
  66. data/lib/puppet/parser/scope.rb +18 -15
  67. data/lib/puppet/plugins/data_providers/data_provider.rb +19 -8
  68. data/lib/puppet/pops/adapters.rb +5 -1
  69. data/lib/puppet/pops/evaluator/access_operator.rb +77 -15
  70. data/lib/puppet/pops/evaluator/closure.rb +10 -5
  71. data/lib/puppet/pops/evaluator/compare_operator.rb +34 -4
  72. data/lib/puppet/pops/evaluator/evaluator_impl.rb +75 -22
  73. data/lib/puppet/pops/evaluator/literal_evaluator.rb +7 -6
  74. data/lib/puppet/pops/evaluator/runtime3_converter.rb +13 -1
  75. data/lib/puppet/pops/evaluator/runtime3_support.rb +14 -4
  76. data/lib/puppet/pops/functions/dispatcher.rb +1 -1
  77. data/lib/puppet/pops/issues.rb +18 -2
  78. data/lib/puppet/pops/loader/base_loader.rb +48 -7
  79. data/lib/puppet/pops/loader/dependency_loader.rb +27 -2
  80. data/lib/puppet/pops/loader/loader.rb +12 -0
  81. data/lib/puppet/pops/loader/predefined_loader.rb +29 -0
  82. data/lib/puppet/pops/loader/runtime3_type_loader.rb +57 -0
  83. data/lib/puppet/pops/loader/static_loader.rb +92 -5
  84. data/lib/puppet/pops/loader/type_definition_instantiator.rb +25 -3
  85. data/lib/puppet/pops/loaders.rb +84 -14
  86. data/lib/puppet/pops/lookup/explainer.rb +38 -1
  87. data/lib/puppet/pops/lookup/interpolation.rb +115 -0
  88. data/lib/puppet/pops/lookup/sub_lookup.rb +86 -0
  89. data/lib/puppet/pops/merge_strategy.rb +0 -10
  90. data/lib/puppet/pops/model/ast_transformer.rb +8 -1
  91. data/lib/puppet/pops/model/factory.rb +31 -8
  92. data/lib/puppet/pops/model/model.rb +8 -0
  93. data/lib/puppet/pops/model/model_label_provider.rb +1 -0
  94. data/lib/puppet/pops/model/model_meta.rb +7 -1
  95. data/lib/puppet/pops/model/model_tree_dumper.rb +4 -0
  96. data/lib/puppet/pops/parser/egrammar.ra +24 -7
  97. data/lib/puppet/pops/parser/eparser.rb +863 -798
  98. data/lib/puppet/pops/parser/evaluating_parser.rb +4 -0
  99. data/lib/puppet/pops/parser/locator.rb +8 -4
  100. data/lib/puppet/pops/pcore.rb +30 -0
  101. data/lib/puppet/pops/types/class_loader.rb +2 -4
  102. data/lib/puppet/pops/types/implementation_registry.rb +146 -0
  103. data/lib/puppet/pops/types/iterable.rb +4 -4
  104. data/lib/puppet/pops/types/p_object_type.rb +846 -0
  105. data/lib/puppet/pops/types/p_runtime_type.rb +102 -0
  106. data/lib/puppet/pops/types/p_sem_ver_range_type.rb +164 -0
  107. data/lib/puppet/pops/types/p_sem_ver_type.rb +113 -0
  108. data/lib/puppet/pops/types/puppet_object.rb +21 -0
  109. data/lib/puppet/pops/types/recursion_guard.rb +10 -0
  110. data/lib/puppet/pops/types/ruby_generator.rb +258 -0
  111. data/lib/puppet/pops/types/string_converter.rb +922 -0
  112. data/lib/puppet/pops/types/type_asserter.rb +2 -2
  113. data/lib/puppet/pops/types/type_calculator.rb +30 -6
  114. data/lib/puppet/pops/types/type_conversion_error.rb +15 -0
  115. data/lib/puppet/pops/types/type_factory.rb +49 -16
  116. data/lib/puppet/pops/types/type_formatter.rb +341 -106
  117. data/lib/puppet/pops/types/type_mismatch_describer.rb +132 -41
  118. data/lib/puppet/pops/types/type_parser.rb +205 -197
  119. data/lib/puppet/pops/types/types.rb +722 -202
  120. data/lib/puppet/pops/validation/checker4_0.rb +66 -4
  121. data/lib/puppet/pops/validation/validator_factory_4_0.rb +1 -0
  122. data/lib/puppet/pops/validation.rb +1 -1
  123. data/lib/puppet/pops/visitor.rb +3 -1
  124. data/lib/puppet/pops.rb +6 -0
  125. data/lib/puppet/property.rb +1 -1
  126. data/lib/puppet/provider/augeas/augeas.rb +1 -1
  127. data/lib/puppet/provider/package/pip.rb +64 -20
  128. data/lib/puppet/provider/package/pip3.rb +2 -0
  129. data/lib/puppet/provider/package/puppet_gem.rb +0 -0
  130. data/lib/puppet/provider/package/rpm.rb +112 -0
  131. data/lib/puppet/provider/package/yum.rb +7 -68
  132. data/lib/puppet/provider/service/daemontools.rb +3 -3
  133. data/lib/puppet/provider/service/init.rb +4 -2
  134. data/lib/puppet/provider/service/runit.rb +3 -3
  135. data/lib/puppet/provider/service/smf.rb +6 -3
  136. data/lib/puppet/provider/service/systemd.rb +59 -73
  137. data/lib/puppet/provider/user/user_role_add.rb +3 -1
  138. data/lib/puppet/reference/providers.rb +2 -3
  139. data/lib/puppet/resource/catalog.rb +34 -30
  140. data/lib/puppet/resource/type_collection.rb +23 -8
  141. data/lib/puppet/resource.rb +54 -37
  142. data/lib/puppet/settings/base_setting.rb +9 -3
  143. data/lib/puppet/settings/symbolic_enum_setting.rb +17 -0
  144. data/lib/puppet/settings.rb +5 -3
  145. data/lib/puppet/ssl/oids.rb +24 -2
  146. data/lib/puppet/test/test_helper.rb +0 -1
  147. data/lib/puppet/transaction.rb +0 -24
  148. data/lib/puppet/type/exec.rb +17 -17
  149. data/lib/puppet/type/file/content.rb +8 -8
  150. data/lib/puppet/type/file/ensure.rb +4 -4
  151. data/lib/puppet/type/file/source.rb +4 -4
  152. data/lib/puppet/type/file/target.rb +2 -2
  153. data/lib/puppet/type/file.rb +15 -5
  154. data/lib/puppet/type/filebucket.rb +1 -1
  155. data/lib/puppet/type/mount.rb +18 -1
  156. data/lib/puppet/type/package.rb +3 -3
  157. data/lib/puppet/type/schedule.rb +5 -5
  158. data/lib/puppet/type/service.rb +15 -0
  159. data/lib/puppet/type/sshkey.rb +5 -3
  160. data/lib/puppet/type/stage.rb +1 -1
  161. data/lib/puppet/type/tidy.rb +3 -3
  162. data/lib/puppet/type/zone.rb +5 -5
  163. data/lib/puppet/type.rb +13 -7
  164. data/lib/puppet/util/feature.rb +1 -1
  165. data/lib/puppet/util/monkey_patches.rb +18 -5
  166. data/lib/puppet/util/network_device/cisco/device.rb +16 -6
  167. data/lib/puppet/util/network_device/cisco/interface.rb +5 -6
  168. data/lib/puppet/util/plist.rb +3 -3
  169. data/lib/puppet/util/windows/file.rb +40 -10
  170. data/lib/puppet/util/windows.rb +1 -0
  171. data/lib/puppet/version.rb +1 -1
  172. data/spec/fixtures/unit/application/environments/production/data/common.yaml +13 -0
  173. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/third_utf8.json +3 -0
  174. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/data1/utf8.yaml +3 -0
  175. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/hiera.yaml +5 -1
  176. data/spec/fixtures/unit/data_providers/environments/hiera_env_config/manifests/site.pp +2 -2
  177. data/spec/fixtures/unit/data_providers/environments/production/modules/abc/lib/puppet/functions/abc/data.rb +2 -1
  178. data/spec/fixtures/unit/data_providers/environments/production/modules/abc/manifests/init.pp +2 -1
  179. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/data/empty_key.json +1 -0
  180. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/hiera.yaml +5 -0
  181. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/manifests/init.pp +2 -0
  182. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_json/metadata.json +9 -0
  183. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/data/empty_key.yaml +1 -0
  184. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/hiera.yaml +5 -0
  185. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/manifests/init.pp +2 -0
  186. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_key_yaml/metadata.json +9 -0
  187. data/spec/fixtures/unit/functions/lookup/environments/production/modules/empty_yaml/data/empty.yaml +1 -0
  188. data/spec/fixtures/unit/parser/lexer/subclass_name_duplication.pp +0 -0
  189. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/usee/lib/puppet/type/usee_type.rb +5 -0
  190. data/spec/fixtures/unit/pops/loaders/loaders/dependent_modules_with_metadata/modules/user/manifests/init.pp +6 -0
  191. data/spec/fixtures/unit/pops/parser/lexer/subclass_name_duplication.pp +0 -0
  192. data/spec/fixtures/unit/provider/service/smf/svcs.out +4 -3
  193. data/spec/integration/agent/logging_spec.rb +0 -0
  194. data/spec/integration/application/apply_spec.rb +0 -0
  195. data/spec/integration/application/doc_spec.rb +0 -0
  196. data/spec/integration/configurer_spec.rb +0 -0
  197. data/spec/integration/data_binding_spec.rb +0 -34
  198. data/spec/integration/defaults_spec.rb +0 -0
  199. data/spec/integration/faces/ca_spec.rb +0 -0
  200. data/spec/integration/faces/documentation_spec.rb +0 -0
  201. data/spec/integration/file_serving/fileset_spec.rb +0 -0
  202. data/spec/integration/file_serving/terminus_helper_spec.rb +0 -0
  203. data/spec/integration/indirector/catalog/compiler_spec.rb +0 -0
  204. data/spec/integration/indirector/direct_file_server_spec.rb +0 -0
  205. data/spec/integration/indirector/file_content/file_server_spec.rb +0 -0
  206. data/spec/integration/indirector/file_metadata/file_server_spec.rb +0 -0
  207. data/spec/integration/indirector/node/ldap_spec.rb +0 -0
  208. data/spec/integration/module_tool/tar/mini_spec.rb +27 -27
  209. data/spec/integration/network/formats_spec.rb +0 -0
  210. data/spec/integration/node/environment_spec.rb +0 -0
  211. data/spec/integration/node/facts_spec.rb +0 -0
  212. data/spec/integration/node_spec.rb +0 -0
  213. data/spec/integration/parser/catalog_spec.rb +14 -2
  214. data/spec/integration/parser/collection_spec.rb +0 -0
  215. data/spec/integration/parser/compiler_spec.rb +94 -3
  216. data/spec/integration/parser/functions/require_spec.rb +0 -0
  217. data/spec/integration/parser/parameter_defaults_spec.rb +19 -1
  218. data/spec/integration/parser/resource_expressions_spec.rb +1 -1
  219. data/spec/integration/provider/mailalias/aliases_spec.rb +0 -0
  220. data/spec/integration/provider/mount_spec.rb +0 -0
  221. data/spec/integration/provider/service/init_spec.rb +0 -0
  222. data/spec/integration/provider/ssh_authorized_key_spec.rb +0 -0
  223. data/spec/integration/reference/providers_spec.rb +0 -0
  224. data/spec/integration/reports_spec.rb +0 -0
  225. data/spec/integration/resource/catalog_spec.rb +0 -0
  226. data/spec/integration/resource/type_collection_spec.rb +8 -0
  227. data/spec/integration/ssl/certificate_authority_spec.rb +0 -0
  228. data/spec/integration/ssl/certificate_request_spec.rb +0 -0
  229. data/spec/integration/ssl/certificate_revocation_list_spec.rb +0 -0
  230. data/spec/integration/ssl/host_spec.rb +0 -0
  231. data/spec/integration/transaction/report_spec.rb +0 -0
  232. data/spec/integration/transaction_spec.rb +0 -0
  233. data/spec/integration/type/exec_spec.rb +0 -0
  234. data/spec/integration/type/file_spec.rb +0 -0
  235. data/spec/integration/type/package_spec.rb +0 -0
  236. data/spec/integration/type/tidy_spec.rb +0 -0
  237. data/spec/integration/type_spec.rb +0 -0
  238. data/spec/integration/util/autoload_spec.rb +0 -0
  239. data/spec/integration/util/rdoc/parser_spec.rb +0 -0
  240. data/spec/integration/util/settings_spec.rb +26 -0
  241. data/spec/integration/util/windows/registry_spec.rb +0 -0
  242. data/spec/integration/util/windows/security_spec.rb +0 -0
  243. data/spec/integration/util/windows/user_spec.rb +0 -0
  244. data/spec/integration/util_spec.rb +0 -0
  245. data/spec/lib/puppet/face/1.0.0/huzzah.rb +0 -0
  246. data/spec/lib/puppet/face/basetest.rb +0 -0
  247. data/spec/lib/puppet/face/huzzah.rb +0 -0
  248. data/spec/lib/puppet_spec/compiler.rb +11 -4
  249. data/spec/lib/puppet_spec/files.rb +0 -0
  250. data/spec/lib/puppet_spec/fixtures.rb +0 -0
  251. data/spec/lib/puppet_spec/verbose.rb +0 -0
  252. data/spec/shared_behaviours/all_parsedfile_providers.rb +0 -0
  253. data/spec/shared_behaviours/file_server_terminus.rb +0 -0
  254. data/spec/shared_behaviours/file_serving.rb +0 -0
  255. data/spec/shared_behaviours/memory_terminus.rb +0 -0
  256. data/spec/shared_behaviours/path_parameters.rb +0 -0
  257. data/spec/shared_behaviours/things_that_declare_options.rb +0 -0
  258. data/spec/shared_contexts/types_setup.rb +4 -0
  259. data/spec/spec_helper.rb +0 -0
  260. data/spec/unit/agent/locker_spec.rb +0 -0
  261. data/spec/unit/agent_spec.rb +0 -0
  262. data/spec/unit/application/agent_spec.rb +0 -0
  263. data/spec/unit/application/apply_spec.rb +0 -0
  264. data/spec/unit/application/cert_spec.rb +0 -0
  265. data/spec/unit/application/certificate_spec.rb +0 -0
  266. data/spec/unit/application/config_spec.rb +0 -0
  267. data/spec/unit/application/describe_spec.rb +0 -0
  268. data/spec/unit/application/device_spec.rb +0 -0
  269. data/spec/unit/application/doc_spec.rb +0 -0
  270. data/spec/unit/application/face_base_spec.rb +0 -0
  271. data/spec/unit/application/facts_spec.rb +0 -0
  272. data/spec/unit/application/filebucket_spec.rb +0 -0
  273. data/spec/unit/application/indirection_base_spec.rb +0 -0
  274. data/spec/unit/application/inspect_spec.rb +19 -8
  275. data/spec/unit/application/lookup_spec.rb +92 -10
  276. data/spec/unit/application/master_spec.rb +0 -0
  277. data/spec/unit/application/resource_spec.rb +0 -0
  278. data/spec/unit/application_spec.rb +0 -0
  279. data/spec/unit/appmgmt_spec.rb +44 -35
  280. data/spec/unit/capability_spec.rb +33 -53
  281. data/spec/unit/configurer/downloader_factory_spec.rb +0 -0
  282. data/spec/unit/configurer/downloader_spec.rb +0 -0
  283. data/spec/unit/configurer/fact_handler_spec.rb +0 -0
  284. data/spec/unit/configurer/plugin_handler_spec.rb +0 -0
  285. data/spec/unit/configurer_spec.rb +0 -0
  286. data/spec/unit/confine/exists_spec.rb +0 -0
  287. data/spec/unit/confine/false_spec.rb +0 -0
  288. data/spec/unit/confine/feature_spec.rb +0 -0
  289. data/spec/unit/confine/true_spec.rb +0 -0
  290. data/spec/unit/confine/variable_spec.rb +0 -0
  291. data/spec/unit/confine_collection_spec.rb +0 -0
  292. data/spec/unit/confine_spec.rb +0 -0
  293. data/spec/unit/confiner_spec.rb +0 -0
  294. data/spec/unit/daemon_spec.rb +0 -0
  295. data/spec/unit/data_providers/function_data_provider_spec.rb +19 -1
  296. data/spec/unit/data_providers/hiera_data_provider_spec.rb +2 -2
  297. data/spec/unit/defaults_spec.rb +18 -0
  298. data/spec/unit/external/pson_spec.rb +0 -0
  299. data/spec/unit/face/catalog_spec.rb +0 -0
  300. data/spec/unit/face/certificate_spec.rb +0 -0
  301. data/spec/unit/face/config_spec.rb +0 -0
  302. data/spec/unit/face/facts_spec.rb +0 -0
  303. data/spec/unit/face/file_spec.rb +0 -0
  304. data/spec/unit/face/help_spec.rb +0 -0
  305. data/spec/unit/face/node_spec.rb +0 -0
  306. data/spec/unit/face/plugin_spec.rb +0 -0
  307. data/spec/unit/face_spec.rb +0 -0
  308. data/spec/unit/file_bucket/dipper_spec.rb +0 -0
  309. data/spec/unit/file_bucket/file_spec.rb +0 -0
  310. data/spec/unit/file_serving/base_spec.rb +0 -0
  311. data/spec/unit/file_serving/configuration/parser_spec.rb +0 -0
  312. data/spec/unit/file_serving/configuration_spec.rb +0 -0
  313. data/spec/unit/file_serving/content_spec.rb +0 -0
  314. data/spec/unit/file_serving/fileset_spec.rb +0 -0
  315. data/spec/unit/file_serving/metadata_spec.rb +0 -0
  316. data/spec/unit/file_serving/mount/file_spec.rb +0 -0
  317. data/spec/unit/file_serving/mount/modules_spec.rb +0 -0
  318. data/spec/unit/file_serving/mount/pluginfacts_spec.rb +0 -0
  319. data/spec/unit/file_serving/mount/plugins_spec.rb +0 -0
  320. data/spec/unit/file_serving/mount_spec.rb +0 -0
  321. data/spec/unit/file_serving/terminus_helper_spec.rb +0 -0
  322. data/spec/unit/file_serving/terminus_selector_spec.rb +0 -0
  323. data/spec/unit/file_system/uniquefile_spec.rb +20 -0
  324. data/spec/unit/file_system_spec.rb +61 -0
  325. data/spec/unit/functions/assert_type_spec.rb +8 -0
  326. data/spec/unit/functions/defined_spec.rb +0 -0
  327. data/spec/unit/functions/dig_spec.rb +58 -0
  328. data/spec/unit/functions/hiera_spec.rb +0 -0
  329. data/spec/unit/functions/lest_spec.rb +34 -0
  330. data/spec/unit/functions/lookup_spec.rb +109 -3
  331. data/spec/unit/functions/new_spec.rb +543 -0
  332. data/spec/unit/functions/regsubst_spec.rb +8 -0
  333. data/spec/unit/functions/split_spec.rb +0 -0
  334. data/spec/unit/functions/then_spec.rb +40 -0
  335. data/spec/unit/functions/versioncmp_spec.rb +0 -0
  336. data/spec/unit/functions4_spec.rb +78 -10
  337. data/spec/unit/graph/relationship_graph_spec.rb +0 -0
  338. data/spec/unit/graph/simple_graph_spec.rb +0 -0
  339. data/spec/unit/hiera_puppet_spec.rb +49 -8
  340. data/spec/unit/indirector/catalog/compiler_spec.rb +7 -0
  341. data/spec/unit/indirector/catalog/json_spec.rb +0 -0
  342. data/spec/unit/indirector/catalog/msgpack_spec.rb +0 -0
  343. data/spec/unit/indirector/catalog/rest_spec.rb +0 -0
  344. data/spec/unit/indirector/catalog/static_compiler_spec.rb +0 -0
  345. data/spec/unit/indirector/catalog/store_configs_spec.rb +0 -0
  346. data/spec/unit/indirector/catalog/yaml_spec.rb +0 -0
  347. data/spec/unit/indirector/certificate/ca_spec.rb +0 -0
  348. data/spec/unit/indirector/certificate/disabled_ca_spec.rb +0 -0
  349. data/spec/unit/indirector/certificate/file_spec.rb +0 -0
  350. data/spec/unit/indirector/certificate/rest_spec.rb +0 -0
  351. data/spec/unit/indirector/certificate_request/ca_spec.rb +0 -0
  352. data/spec/unit/indirector/certificate_request/disabled_ca_spec.rb +0 -0
  353. data/spec/unit/indirector/certificate_request/file_spec.rb +0 -0
  354. data/spec/unit/indirector/certificate_request/rest_spec.rb +0 -0
  355. data/spec/unit/indirector/certificate_revocation_list/ca_spec.rb +0 -0
  356. data/spec/unit/indirector/certificate_revocation_list/disabled_ca_spec.rb +0 -0
  357. data/spec/unit/indirector/certificate_revocation_list/file_spec.rb +0 -0
  358. data/spec/unit/indirector/certificate_revocation_list/rest_spec.rb +0 -0
  359. data/spec/unit/indirector/certificate_status/file_spec.rb +0 -0
  360. data/spec/unit/indirector/certificate_status/rest_spec.rb +0 -0
  361. data/spec/unit/indirector/code_spec.rb +0 -0
  362. data/spec/unit/indirector/direct_file_server_spec.rb +0 -0
  363. data/spec/unit/indirector/envelope_spec.rb +0 -0
  364. data/spec/unit/indirector/exec_spec.rb +0 -0
  365. data/spec/unit/indirector/face_spec.rb +0 -0
  366. data/spec/unit/indirector/facts/facter_spec.rb +0 -0
  367. data/spec/unit/indirector/facts/network_device_spec.rb +0 -0
  368. data/spec/unit/indirector/facts/store_configs_spec.rb +0 -0
  369. data/spec/unit/indirector/facts/yaml_spec.rb +0 -0
  370. data/spec/unit/indirector/file_bucket_file/file_spec.rb +0 -0
  371. data/spec/unit/indirector/file_bucket_file/rest_spec.rb +0 -0
  372. data/spec/unit/indirector/file_content/file_server_spec.rb +0 -0
  373. data/spec/unit/indirector/file_content/file_spec.rb +0 -0
  374. data/spec/unit/indirector/file_content/rest_spec.rb +0 -0
  375. data/spec/unit/indirector/file_metadata/file_server_spec.rb +0 -0
  376. data/spec/unit/indirector/file_metadata/file_spec.rb +0 -0
  377. data/spec/unit/indirector/file_metadata/rest_spec.rb +0 -0
  378. data/spec/unit/indirector/file_server_spec.rb +0 -0
  379. data/spec/unit/indirector/indirection_spec.rb +0 -0
  380. data/spec/unit/indirector/json_spec.rb +0 -0
  381. data/spec/unit/indirector/key/ca_spec.rb +0 -0
  382. data/spec/unit/indirector/key/disabled_ca_spec.rb +0 -0
  383. data/spec/unit/indirector/key/file_spec.rb +0 -0
  384. data/spec/unit/indirector/ldap_spec.rb +0 -0
  385. data/spec/unit/indirector/memory_spec.rb +0 -0
  386. data/spec/unit/indirector/msgpack_spec.rb +11 -1
  387. data/spec/unit/indirector/node/exec_spec.rb +0 -0
  388. data/spec/unit/indirector/node/ldap_spec.rb +0 -0
  389. data/spec/unit/indirector/node/memory_spec.rb +0 -0
  390. data/spec/unit/indirector/node/msgpack_spec.rb +0 -0
  391. data/spec/unit/indirector/node/plain_spec.rb +0 -0
  392. data/spec/unit/indirector/node/rest_spec.rb +0 -0
  393. data/spec/unit/indirector/node/store_configs_spec.rb +0 -0
  394. data/spec/unit/indirector/node/yaml_spec.rb +0 -0
  395. data/spec/unit/indirector/plain_spec.rb +0 -0
  396. data/spec/unit/indirector/report/msgpack_spec.rb +0 -0
  397. data/spec/unit/indirector/report/processor_spec.rb +0 -0
  398. data/spec/unit/indirector/report/rest_spec.rb +0 -0
  399. data/spec/unit/indirector/report/yaml_spec.rb +0 -0
  400. data/spec/unit/indirector/request_spec.rb +0 -0
  401. data/spec/unit/indirector/resource/ral_spec.rb +0 -0
  402. data/spec/unit/indirector/resource/store_configs_spec.rb +0 -0
  403. data/spec/unit/indirector/resource_type/parser_spec.rb +5 -0
  404. data/spec/unit/indirector/resource_type/rest_spec.rb +0 -0
  405. data/spec/unit/indirector/rest_spec.rb +12 -0
  406. data/spec/unit/indirector/ssl_file_spec.rb +0 -0
  407. data/spec/unit/indirector/status/rest_spec.rb +0 -0
  408. data/spec/unit/indirector/store_configs_spec.rb +0 -0
  409. data/spec/unit/indirector/terminus_spec.rb +0 -0
  410. data/spec/unit/indirector/yaml_spec.rb +0 -0
  411. data/spec/unit/indirector_spec.rb +0 -0
  412. data/spec/unit/interface/action_builder_spec.rb +0 -0
  413. data/spec/unit/interface/action_manager_spec.rb +0 -0
  414. data/spec/unit/interface/action_spec.rb +0 -0
  415. data/spec/unit/interface/documentation_spec.rb +0 -0
  416. data/spec/unit/interface/face_collection_spec.rb +0 -0
  417. data/spec/unit/interface/option_builder_spec.rb +0 -0
  418. data/spec/unit/interface/option_spec.rb +0 -0
  419. data/spec/unit/interface_spec.rb +0 -0
  420. data/spec/unit/man_spec.rb +0 -0
  421. data/spec/unit/module_spec.rb +30 -6
  422. data/spec/unit/module_tool/applications/builder_spec.rb +23 -3
  423. data/spec/unit/module_tool_spec.rb +0 -0
  424. data/spec/unit/network/auth_config_parser_spec.rb +16 -0
  425. data/spec/unit/network/authconfig_spec.rb +0 -0
  426. data/spec/unit/network/authstore_spec.rb +0 -0
  427. data/spec/unit/network/format_handler_spec.rb +0 -0
  428. data/spec/unit/network/format_spec.rb +0 -0
  429. data/spec/unit/network/formats_spec.rb +0 -0
  430. data/spec/unit/network/http/api/indirected_routes_spec.rb +21 -13
  431. data/spec/unit/network/http/api/master/v3/environment_spec.rb +60 -0
  432. data/spec/unit/network/http/api/master/v3_spec.rb +0 -0
  433. data/spec/unit/network/http/compression_spec.rb +0 -0
  434. data/spec/unit/network/http/connection_spec.rb +0 -0
  435. data/spec/unit/network/http/factory_spec.rb +0 -0
  436. data/spec/unit/network/http/handler_spec.rb +0 -0
  437. data/spec/unit/network/http/nocache_pool_spec.rb +0 -0
  438. data/spec/unit/network/http/pool_spec.rb +0 -0
  439. data/spec/unit/network/http/rack/rest_spec.rb +7 -0
  440. data/spec/unit/network/http/rack_spec.rb +0 -0
  441. data/spec/unit/network/http/session_spec.rb +0 -0
  442. data/spec/unit/network/http/site_spec.rb +0 -0
  443. data/spec/unit/network/http/webrick/rest_spec.rb +0 -0
  444. data/spec/unit/network/http/webrick_spec.rb +0 -0
  445. data/spec/unit/network/http_pool_spec.rb +0 -0
  446. data/spec/unit/network/http_spec.rb +0 -0
  447. data/spec/unit/network/resolver_spec.rb +0 -0
  448. data/spec/unit/network/rights_spec.rb +0 -0
  449. data/spec/unit/network/server_spec.rb +0 -0
  450. data/spec/unit/node/environment_spec.rb +10 -0
  451. data/spec/unit/node/facts_spec.rb +0 -0
  452. data/spec/unit/node_spec.rb +0 -0
  453. data/spec/unit/other/selinux_spec.rb +0 -0
  454. data/spec/unit/parameter/path_spec.rb +0 -0
  455. data/spec/unit/parameter/value_collection_spec.rb +0 -0
  456. data/spec/unit/parameter/value_spec.rb +0 -0
  457. data/spec/unit/parameter_spec.rb +0 -0
  458. data/spec/unit/parser/ast/leaf_spec.rb +0 -0
  459. data/spec/unit/parser/compiler_spec.rb +20 -1
  460. data/spec/unit/parser/files_spec.rb +0 -0
  461. data/spec/unit/parser/functions/create_resources_spec.rb +2 -2
  462. data/spec/unit/parser/functions/defined_spec.rb +0 -0
  463. data/spec/unit/parser/functions/digest_spec.rb +0 -0
  464. data/spec/unit/parser/functions/fail_spec.rb +0 -0
  465. data/spec/unit/parser/functions/file_spec.rb +0 -0
  466. data/spec/unit/parser/functions/fqdn_rand_spec.rb +0 -0
  467. data/spec/unit/parser/functions/generate_spec.rb +0 -0
  468. data/spec/unit/parser/functions/hiera_spec.rb +0 -0
  469. data/spec/unit/parser/functions/include_spec.rb +0 -0
  470. data/spec/unit/parser/functions/inline_template_spec.rb +0 -0
  471. data/spec/unit/parser/functions/realize_spec.rb +0 -0
  472. data/spec/unit/parser/functions/regsubst_spec.rb +0 -0
  473. data/spec/unit/parser/functions/require_spec.rb +0 -0
  474. data/spec/unit/parser/functions/scanf_spec.rb +0 -0
  475. data/spec/unit/parser/functions/shared.rb +1 -1
  476. data/spec/unit/parser/functions/shellquote_spec.rb +0 -0
  477. data/spec/unit/parser/functions/split_spec.rb +0 -0
  478. data/spec/unit/parser/functions/sprintf_spec.rb +0 -0
  479. data/spec/unit/parser/functions/tag_spec.rb +0 -0
  480. data/spec/unit/parser/functions/template_spec.rb +0 -0
  481. data/spec/unit/parser/functions/versioncmp_spec.rb +0 -0
  482. data/spec/unit/parser/functions_spec.rb +0 -0
  483. data/spec/unit/parser/relationship_spec.rb +0 -0
  484. data/spec/unit/parser/resource/param_spec.rb +0 -0
  485. data/spec/unit/parser/resource_spec.rb +8 -1
  486. data/spec/unit/parser/scope_spec.rb +45 -0
  487. data/spec/unit/parser/templatewrapper_spec.rb +0 -0
  488. data/spec/unit/parser/type_loader_spec.rb +0 -0
  489. data/spec/unit/pops/evaluator/access_ops_spec.rb +14 -0
  490. data/spec/unit/pops/evaluator/evaluating_parser_spec.rb +13 -5
  491. data/spec/unit/pops/loaders/loaders_spec.rb +8 -8
  492. data/spec/unit/pops/loaders/static_loader_spec.rb +92 -1
  493. data/spec/unit/pops/lookup/interpolation_spec.rb +313 -0
  494. data/spec/unit/pops/parser/lexer2_spec.rb +2 -9
  495. data/spec/unit/pops/parser/parse_application_spec.rb +3 -8
  496. data/spec/unit/pops/parser/parse_basic_expressions_spec.rb +19 -0
  497. data/spec/unit/pops/parser/parse_capabilities_spec.rb +3 -10
  498. data/spec/unit/pops/parser/parse_site_spec.rb +19 -10
  499. data/spec/unit/pops/parser/parser_rspec_helper.rb +0 -4
  500. data/spec/unit/pops/types/enumeration_spec.rb +13 -12
  501. data/spec/unit/pops/types/iterable_spec.rb +2 -2
  502. data/spec/unit/pops/types/p_object_type_spec.rb +1060 -0
  503. data/spec/unit/pops/types/p_sem_ver_type_spec.rb +285 -0
  504. data/spec/unit/pops/types/recursion_guard_spec.rb +19 -17
  505. data/spec/unit/pops/types/ruby_generator_spec.rb +261 -0
  506. data/spec/unit/pops/types/string_converter_spec.rb +904 -0
  507. data/spec/unit/pops/types/type_asserter_spec.rb +3 -3
  508. data/spec/unit/pops/types/type_calculator_spec.rb +462 -412
  509. data/spec/unit/pops/types/type_factory_spec.rb +129 -88
  510. data/spec/unit/pops/types/type_formatter_spec.rb +80 -8
  511. data/spec/unit/pops/types/type_mismatch_describer_spec.rb +27 -2
  512. data/spec/unit/pops/types/type_parser_spec.rb +55 -16
  513. data/spec/unit/pops/types/types_spec.rb +320 -0
  514. data/spec/unit/pops/validator/validator_spec.rb +84 -10
  515. data/spec/unit/property/ensure_spec.rb +0 -0
  516. data/spec/unit/property/keyvalue_spec.rb +0 -0
  517. data/spec/unit/property/list_spec.rb +0 -0
  518. data/spec/unit/property/ordered_list_spec.rb +0 -0
  519. data/spec/unit/property_spec.rb +0 -0
  520. data/spec/unit/provider/augeas/augeas_spec.rb +0 -0
  521. data/spec/unit/provider/cisco_spec.rb +0 -0
  522. data/spec/unit/provider/command_spec.rb +0 -0
  523. data/spec/unit/provider/cron/crontab_spec.rb +0 -0
  524. data/spec/unit/provider/exec/posix_spec.rb +0 -0
  525. data/spec/unit/provider/exec/shell_spec.rb +0 -0
  526. data/spec/unit/provider/exec/windows_spec.rb +0 -0
  527. data/spec/unit/provider/exec_spec.rb +0 -0
  528. data/spec/unit/provider/file/posix_spec.rb +0 -0
  529. data/spec/unit/provider/file/windows_spec.rb +0 -0
  530. data/spec/unit/provider/group/groupadd_spec.rb +0 -0
  531. data/spec/unit/provider/group/ldap_spec.rb +0 -0
  532. data/spec/unit/provider/group/pw_spec.rb +0 -0
  533. data/spec/unit/provider/group/windows_adsi_spec.rb +0 -0
  534. data/spec/unit/provider/host/parsed_spec.rb +0 -0
  535. data/spec/unit/provider/interface/cisco_spec.rb +0 -0
  536. data/spec/unit/provider/ldap_spec.rb +0 -0
  537. data/spec/unit/provider/macauthorization_spec.rb +0 -0
  538. data/spec/unit/provider/mcx/mcxcontent_spec.rb +0 -0
  539. data/spec/unit/provider/mount/parsed_spec.rb +0 -0
  540. data/spec/unit/provider/mount_spec.rb +0 -0
  541. data/spec/unit/provider/naginator_spec.rb +0 -0
  542. data/spec/unit/provider/nameservice/directoryservice_spec.rb +0 -0
  543. data/spec/unit/provider/nameservice_spec.rb +0 -0
  544. data/spec/unit/provider/network_device_spec.rb +0 -0
  545. data/spec/unit/provider/package/aix_spec.rb +0 -0
  546. data/spec/unit/provider/package/appdmg_spec.rb +0 -0
  547. data/spec/unit/provider/package/apt_spec.rb +0 -0
  548. data/spec/unit/provider/package/aptitude_spec.rb +0 -0
  549. data/spec/unit/provider/package/aptrpm_spec.rb +0 -0
  550. data/spec/unit/provider/package/dpkg_spec.rb +0 -0
  551. data/spec/unit/provider/package/freebsd_spec.rb +0 -0
  552. data/spec/unit/provider/package/gem_spec.rb +0 -0
  553. data/spec/unit/provider/package/hpux_spec.rb +0 -0
  554. data/spec/unit/provider/package/macports_spec.rb +0 -0
  555. data/spec/unit/provider/package/nim_spec.rb +0 -0
  556. data/spec/unit/provider/package/openbsd_spec.rb +0 -0
  557. data/spec/unit/provider/package/opkg_spec.rb +0 -0
  558. data/spec/unit/provider/package/pacman_spec.rb +0 -0
  559. data/spec/unit/provider/package/pip3_spec.rb +9 -262
  560. data/spec/unit/provider/package/pip_spec.rb +85 -22
  561. data/spec/unit/provider/package/pkg_spec.rb +0 -0
  562. data/spec/unit/provider/package/pkgutil_spec.rb +0 -0
  563. data/spec/unit/provider/package/puppet_gem_spec.rb +0 -0
  564. data/spec/unit/provider/package/rpm_spec.rb +160 -3
  565. data/spec/unit/provider/package/sun_spec.rb +0 -0
  566. data/spec/unit/provider/package/windows/package_spec.rb +0 -0
  567. data/spec/unit/provider/package/windows_spec.rb +0 -0
  568. data/spec/unit/provider/package/yum_spec.rb +23 -134
  569. data/spec/unit/provider/package/zypper_spec.rb +0 -0
  570. data/spec/unit/provider/parsedfile_spec.rb +0 -0
  571. data/spec/unit/provider/selboolean_spec.rb +0 -0
  572. data/spec/unit/provider/selmodule_spec.rb +0 -0
  573. data/spec/unit/provider/service/base_spec.rb +0 -0
  574. data/spec/unit/provider/service/bsd_spec.rb +0 -0
  575. data/spec/unit/provider/service/daemontools_spec.rb +0 -0
  576. data/spec/unit/provider/service/debian_spec.rb +0 -0
  577. data/spec/unit/provider/service/freebsd_spec.rb +0 -0
  578. data/spec/unit/provider/service/gentoo_spec.rb +0 -0
  579. data/spec/unit/provider/service/init_spec.rb +0 -0
  580. data/spec/unit/provider/service/launchd_spec.rb +0 -0
  581. data/spec/unit/provider/service/openbsd_spec.rb +0 -0
  582. data/spec/unit/provider/service/openrc_spec.rb +0 -0
  583. data/spec/unit/provider/service/openwrt_spec.rb +0 -0
  584. data/spec/unit/provider/service/rcng_spec.rb +0 -0
  585. data/spec/unit/provider/service/redhat_spec.rb +0 -0
  586. data/spec/unit/provider/service/runit_spec.rb +0 -0
  587. data/spec/unit/provider/service/smf_spec.rb +14 -2
  588. data/spec/unit/provider/service/src_spec.rb +0 -0
  589. data/spec/unit/provider/service/systemd_spec.rb +34 -42
  590. data/spec/unit/provider/service/upstart_spec.rb +0 -0
  591. data/spec/unit/provider/service/windows_spec.rb +0 -0
  592. data/spec/unit/provider/ssh_authorized_key/parsed_spec.rb +0 -0
  593. data/spec/unit/provider/sshkey/parsed_spec.rb +0 -0
  594. data/spec/unit/provider/user/directoryservice_spec.rb +0 -0
  595. data/spec/unit/provider/user/hpux_spec.rb +0 -0
  596. data/spec/unit/provider/user/ldap_spec.rb +0 -0
  597. data/spec/unit/provider/user/openbsd_spec.rb +0 -0
  598. data/spec/unit/provider/user/pw_spec.rb +0 -0
  599. data/spec/unit/provider/user/user_role_add_spec.rb +0 -0
  600. data/spec/unit/provider/user/useradd_spec.rb +0 -0
  601. data/spec/unit/provider/user/windows_adsi_spec.rb +0 -0
  602. data/spec/unit/provider/vlan/cisco_spec.rb +0 -0
  603. data/spec/unit/provider/zfs/zfs_spec.rb +0 -0
  604. data/spec/unit/provider/zone/solaris_spec.rb +0 -0
  605. data/spec/unit/provider/zpool/zpool_spec.rb +0 -0
  606. data/spec/unit/provider_spec.rb +0 -0
  607. data/spec/unit/puppet_spec.rb +0 -0
  608. data/spec/unit/relationship_spec.rb +0 -0
  609. data/spec/unit/reports/http_spec.rb +0 -0
  610. data/spec/unit/reports/store_spec.rb +0 -0
  611. data/spec/unit/reports_spec.rb +0 -0
  612. data/spec/unit/resource/capability_finder_spec.rb +10 -2
  613. data/spec/unit/resource/catalog_spec.rb +27 -0
  614. data/spec/unit/resource/status_spec.rb +0 -0
  615. data/spec/unit/resource/type_collection_helper_spec.rb +0 -0
  616. data/spec/unit/resource/type_collection_spec.rb +0 -0
  617. data/spec/unit/resource/type_spec.rb +0 -0
  618. data/spec/unit/resource_spec.rb +0 -0
  619. data/spec/unit/settings/directory_setting_spec.rb +0 -0
  620. data/spec/unit/settings/duration_setting_spec.rb +0 -0
  621. data/spec/unit/settings/file_setting_spec.rb +6 -0
  622. data/spec/unit/settings/path_setting_spec.rb +0 -0
  623. data/spec/unit/settings/priority_setting_spec.rb +0 -0
  624. data/spec/unit/settings_spec.rb +1 -1
  625. data/spec/unit/ssl/base_spec.rb +0 -0
  626. data/spec/unit/ssl/certificate_authority/interface_spec.rb +0 -0
  627. data/spec/unit/ssl/certificate_authority_spec.rb +0 -0
  628. data/spec/unit/ssl/certificate_factory_spec.rb +0 -0
  629. data/spec/unit/ssl/certificate_request_spec.rb +0 -0
  630. data/spec/unit/ssl/certificate_revocation_list_spec.rb +0 -0
  631. data/spec/unit/ssl/certificate_spec.rb +0 -0
  632. data/spec/unit/ssl/configuration_spec.rb +0 -0
  633. data/spec/unit/ssl/host_spec.rb +0 -0
  634. data/spec/unit/ssl/inventory_spec.rb +0 -0
  635. data/spec/unit/ssl/key_spec.rb +0 -0
  636. data/spec/unit/status_spec.rb +0 -0
  637. data/spec/unit/transaction/additional_resource_generator_spec.rb +80 -65
  638. data/spec/unit/transaction/event_manager_spec.rb +0 -0
  639. data/spec/unit/transaction/event_spec.rb +0 -0
  640. data/spec/unit/transaction/report_spec.rb +0 -0
  641. data/spec/unit/transaction/resource_harness_spec.rb +0 -0
  642. data/spec/unit/transaction_spec.rb +0 -0
  643. data/spec/unit/type/augeas_spec.rb +0 -0
  644. data/spec/unit/type/component_spec.rb +0 -0
  645. data/spec/unit/type/computer_spec.rb +0 -0
  646. data/spec/unit/type/cron_spec.rb +0 -0
  647. data/spec/unit/type/exec_spec.rb +0 -0
  648. data/spec/unit/type/file/checksum_spec.rb +0 -0
  649. data/spec/unit/type/file/checksum_value_spec.rb +0 -0
  650. data/spec/unit/type/file/content_spec.rb +0 -0
  651. data/spec/unit/type/file/ctime_spec.rb +0 -0
  652. data/spec/unit/type/file/ensure_spec.rb +0 -0
  653. data/spec/unit/type/file/group_spec.rb +0 -0
  654. data/spec/unit/type/file/mode_spec.rb +0 -0
  655. data/spec/unit/type/file/mtime_spec.rb +0 -0
  656. data/spec/unit/type/file/owner_spec.rb +0 -0
  657. data/spec/unit/type/file/selinux_spec.rb +0 -0
  658. data/spec/unit/type/file/source_spec.rb +0 -0
  659. data/spec/unit/type/file/type_spec.rb +0 -0
  660. data/spec/unit/type/file_spec.rb +0 -0
  661. data/spec/unit/type/filebucket_spec.rb +0 -0
  662. data/spec/unit/type/group_spec.rb +0 -0
  663. data/spec/unit/type/host_spec.rb +0 -0
  664. data/spec/unit/type/interface_spec.rb +0 -0
  665. data/spec/unit/type/k5login_spec.rb +0 -0
  666. data/spec/unit/type/macauthorization_spec.rb +0 -0
  667. data/spec/unit/type/mailalias_spec.rb +0 -0
  668. data/spec/unit/type/maillist_spec.rb +0 -0
  669. data/spec/unit/type/mcx_spec.rb +0 -0
  670. data/spec/unit/type/mount_spec.rb +51 -10
  671. data/spec/unit/type/nagios_spec.rb +0 -0
  672. data/spec/unit/type/noop_metaparam_spec.rb +0 -0
  673. data/spec/unit/type/package/package_settings_spec.rb +0 -0
  674. data/spec/unit/type/package_spec.rb +0 -0
  675. data/spec/unit/type/resources_spec.rb +0 -0
  676. data/spec/unit/type/schedule_spec.rb +0 -0
  677. data/spec/unit/type/selboolean_spec.rb +0 -0
  678. data/spec/unit/type/selmodule_spec.rb +0 -0
  679. data/spec/unit/type/service_spec.rb +16 -0
  680. data/spec/unit/type/ssh_authorized_key_spec.rb +0 -0
  681. data/spec/unit/type/sshkey_spec.rb +0 -0
  682. data/spec/unit/type/stage_spec.rb +0 -0
  683. data/spec/unit/type/tidy_spec.rb +0 -0
  684. data/spec/unit/type/user_spec.rb +0 -0
  685. data/spec/unit/type/vlan_spec.rb +0 -0
  686. data/spec/unit/type/whit_spec.rb +0 -0
  687. data/spec/unit/type/yumrepo_spec.rb +0 -0
  688. data/spec/unit/type/zfs_spec.rb +0 -0
  689. data/spec/unit/type/zone_spec.rb +0 -0
  690. data/spec/unit/type/zpool_spec.rb +0 -0
  691. data/spec/unit/type_spec.rb +14 -0
  692. data/spec/unit/util/autoload_spec.rb +0 -0
  693. data/spec/unit/util/backups_spec.rb +0 -0
  694. data/spec/unit/util/checksums_spec.rb +0 -0
  695. data/spec/unit/util/colors_spec.rb +0 -0
  696. data/spec/unit/util/command_line_spec.rb +0 -0
  697. data/spec/unit/util/constant_inflector_spec.rb +0 -0
  698. data/spec/unit/util/diff_spec.rb +0 -0
  699. data/spec/unit/util/errors_spec.rb +0 -0
  700. data/spec/unit/util/execution_spec.rb +0 -0
  701. data/spec/unit/util/execution_stub_spec.rb +0 -0
  702. data/spec/unit/util/feature_spec.rb +1 -1
  703. data/spec/unit/util/filetype_spec.rb +0 -0
  704. data/spec/unit/util/ldap/connection_spec.rb +0 -0
  705. data/spec/unit/util/ldap/generator_spec.rb +0 -0
  706. data/spec/unit/util/ldap/manager_spec.rb +0 -0
  707. data/spec/unit/util/log/destinations_spec.rb +0 -0
  708. data/spec/unit/util/log_spec.rb +0 -0
  709. data/spec/unit/util/logging_spec.rb +0 -0
  710. data/spec/unit/util/metric_spec.rb +0 -0
  711. data/spec/unit/util/monkey_patches_spec.rb +79 -3
  712. data/spec/unit/util/nagios_maker_spec.rb +0 -0
  713. data/spec/unit/util/network_device/cisco/device_spec.rb +1 -1
  714. data/spec/unit/util/network_device/cisco/facts_spec.rb +0 -0
  715. data/spec/unit/util/network_device/cisco/interface_spec.rb +0 -0
  716. data/spec/unit/util/network_device/config_spec.rb +0 -0
  717. data/spec/unit/util/network_device/ipcalc_spec.rb +0 -0
  718. data/spec/unit/util/network_device/transport/base_spec.rb +0 -0
  719. data/spec/unit/util/network_device/transport/ssh_spec.rb +0 -0
  720. data/spec/unit/util/network_device/transport/telnet_spec.rb +0 -0
  721. data/spec/unit/util/package_spec.rb +0 -0
  722. data/spec/unit/util/posix_spec.rb +0 -0
  723. data/spec/unit/util/rdoc_spec.rb +0 -0
  724. data/spec/unit/util/resource_template_spec.rb +0 -0
  725. data/spec/unit/util/retry_action_spec.rb +0 -0
  726. data/spec/unit/util/run_mode_spec.rb +0 -0
  727. data/spec/unit/util/selinux_spec.rb +0 -0
  728. data/spec/unit/util/storage_spec.rb +0 -0
  729. data/spec/unit/util/suidmanager_spec.rb +0 -0
  730. data/spec/unit/util/symbolic_file_mode_spec.rb +0 -0
  731. data/spec/unit/util/tagging_spec.rb +0 -0
  732. data/spec/unit/util/user_attr_spec.rb +0 -0
  733. data/spec/unit/util/warnings_spec.rb +0 -0
  734. data/spec/unit/util/windows/adsi_spec.rb +0 -0
  735. data/spec/unit/util/windows/file_spec.rb +34 -0
  736. data/spec/unit/util/windows/root_certs_spec.rb +0 -0
  737. data/spec/unit/util/windows/sid_spec.rb +0 -0
  738. data/spec/unit/util_spec.rb +0 -0
  739. data/spec/watchr.rb +0 -0
  740. metadata +3402 -3337
  741. checksums.yaml +0 -7
  742. data/ext/puppet-nm-dispatcher +0 -13
  743. data/lib/puppet/pops/types/types_meta.rb +0 -0
  744. data/spec/integration/provider/package_spec.rb +0 -35
  745. data/spec/unit/data_providers/hiera_interpolation_spec.rb +0 -57
@@ -4,6 +4,7 @@ require_relative 'recursion_guard'
4
4
  require_relative 'type_acceptor'
5
5
  require_relative 'type_asserter'
6
6
  require_relative 'type_assertion_error'
7
+ require_relative 'type_conversion_error'
7
8
  require_relative 'type_formatter'
8
9
  require_relative 'type_calculator'
9
10
  require_relative 'type_factory'
@@ -11,10 +12,10 @@ require_relative 'type_parser'
11
12
  require_relative 'class_loader'
12
13
  require_relative 'type_mismatch_describer'
13
14
 
14
- require 'rgen/metamodel_builder'
15
-
16
15
  module Puppet::Pops
17
16
  module Types
17
+
18
+ EMPTY_HASH = {}.freeze
18
19
  # The Types model is a model of Puppet Language types.
19
20
  #
20
21
  # The exact relationship between types is not visible in this model wrt. the PDataType which is an abstraction
@@ -64,7 +65,7 @@ class PAnyType < TypedModelObject
64
65
  # @api public
65
66
  def assignable?(o, guard = nil)
66
67
  case o
67
- when Class
68
+ when Class
68
69
  # Safe to call _assignable directly since a Class never is a Unit or Variant
69
70
  _assignable?(TypeCalculator.singleton.type(o), guard)
70
71
  when PUnitType
@@ -115,6 +116,14 @@ class PAnyType < TypedModelObject
115
116
  false
116
117
  end
117
118
 
119
+ # Called from the `PTypeAliasType` when it detects self recursion. The default is to do nothing
120
+ # but some self recursive constructs are illegal such as when a `PObjectType` somehow inherits itself
121
+ # @param originator [PTypeAliasType] the starting point for the check
122
+ # @raise Puppet::Error if an illegal self recursion is detected
123
+ # @api private
124
+ def check_self_recursion(originator)
125
+ end
126
+
118
127
  # Generalizes value specific types. Types that are not value specific will return `self` otherwise
119
128
  # the generalized type is returned.
120
129
  #
@@ -136,6 +145,18 @@ class PAnyType < TypedModelObject
136
145
  self
137
146
  end
138
147
 
148
+ # Called from the TypeParser once it has found a type using the Loader to enable that this type can
149
+ # resolve internal type expressions using a loader. Presently, this method is a no-op for all types
150
+ # except the {{PTypeAliasType}}.
151
+ #
152
+ # @param type_parser [TypeParser] type parser
153
+ # @param loader [Loader::Loader] loader to use
154
+ # @return [PTypeAliasType] the receiver of the call, i.e. `self`
155
+ # @api private
156
+ def resolve(type_parser, loader)
157
+ self
158
+ end
159
+
139
160
  # Responds `true` for all callables, variants of callables and unless _optional_ is
140
161
  # false, all optional callables.
141
162
  # @param optional [Boolean]
@@ -177,11 +198,22 @@ class PAnyType < TypedModelObject
177
198
  end
178
199
 
179
200
  # Returns true if the given argument _o_ is an instance of this type
201
+ # @param guard [RecursionGuard] guard against recursion. Only used by internal calls
180
202
  # @return [Boolean]
181
- def instance?(o)
203
+ # @api public
204
+ def instance?(o, guard = nil)
182
205
  true
183
206
  end
184
207
 
208
+ # An object is considered to really be an instance of a type when something other than a
209
+ # TypeAlias or a Variant responds true to a call to {#instance?}.
210
+ #
211
+ # @return [Integer] -1 = is not instance, 0 = recursion detected, 1 = is instance
212
+ # @api private
213
+ def really_instance?(o, guard = nil)
214
+ instance?(o, guard) ? 1 : -1
215
+ end
216
+
185
217
  def eql?(o)
186
218
  self.class == o.class
187
219
  end
@@ -206,6 +238,29 @@ class PAnyType < TypedModelObject
206
238
  TypeFormatter.string(self)
207
239
  end
208
240
 
241
+ # Returns the name of the type, without parameters
242
+ # @return [String] the name of the type
243
+ # @api public
244
+ def name
245
+ simple_name
246
+ end
247
+
248
+ def new_function(loader)
249
+ self.class.new_function(self, loader)
250
+ end
251
+
252
+ # This default implementation of of a new_function raises an Argument Error.
253
+ # Types for which creating a new instance is supported, should create and return
254
+ # a Puppet Function class by using Puppet:Loaders.create_loaded_function(:new, loader)
255
+ # and return that result.
256
+ #
257
+ # @raises ArgumentError
258
+ #
259
+ def self.new_function(instance, loader)
260
+ raise ArgumentError.new("Creation of new instance of type '#{instance.to_s}' is not supported")
261
+ end
262
+
263
+
209
264
  # The default instance of this type. Each type in the type system has this constant
210
265
  # declared.
211
266
  #
@@ -218,19 +273,6 @@ class PAnyType < TypedModelObject
218
273
  o.is_a?(PAnyType)
219
274
  end
220
275
 
221
- NAME_SEGMENT_SEPARATOR = '::'.freeze
222
-
223
- # @api private
224
- def class_from_string(str)
225
- begin
226
- str.split(NAME_SEGMENT_SEPARATOR).reduce(Object) do |memo, name_segment|
227
- memo.const_get(name_segment)
228
- end
229
- rescue NameError
230
- return nil
231
- end
232
- end
233
-
234
276
  # Produces the tuple entry at the given index given a tuple type, its from/to constraints on the last
235
277
  # type, and an index.
236
278
  # Produces nil if the index is out of bounds
@@ -238,7 +280,7 @@ class PAnyType < TypedModelObject
238
280
  #
239
281
  # @api private
240
282
  #
241
- def tuple_entry_at(tuple_t, from, to, index)
283
+ def tuple_entry_at(tuple_t, to, index)
242
284
  regular = (tuple_t.types.size - 1)
243
285
  if index < regular
244
286
  tuple_t.types[index]
@@ -324,7 +366,7 @@ class PTypeWithContainedType < PAnyType
324
366
  end
325
367
 
326
368
  def hash
327
- self.class.hash * 31 * @type.hash
369
+ self.class.hash ^ @type.hash
328
370
  end
329
371
 
330
372
  def eql?(o)
@@ -336,11 +378,11 @@ end
336
378
  # @api public
337
379
  #
338
380
  class PType < PTypeWithContainedType
339
- def instance?(o)
381
+ def instance?(o, guard = nil)
340
382
  if o.is_a?(PAnyType)
341
- type.nil? || type.assignable?(o)
383
+ type.nil? || type.assignable?(o, guard)
342
384
  else
343
- assignable?(TypeCalculator.infer(o))
385
+ assignable?(TypeCalculator.infer(o), guard)
344
386
  end
345
387
  end
346
388
 
@@ -398,8 +440,8 @@ class PNotUndefType < PTypeWithContainedType
398
440
  super(type.class == PAnyType ? nil : type)
399
441
  end
400
442
 
401
- def instance?(o)
402
- !(o.nil? || o == :undef) && (@type.nil? || @type.instance?(o))
443
+ def instance?(o, guard = nil)
444
+ !(o.nil? || o == :undef) && (@type.nil? || @type.instance?(o, guard))
403
445
  end
404
446
 
405
447
  def normalize(guard = nil)
@@ -409,7 +451,7 @@ class PNotUndefType < PTypeWithContainedType
409
451
  else
410
452
  if n.type.is_a?(POptionalType)
411
453
  # No point in having an optional in a NotUndef
412
- PNotUndef.new(n.type.type).normalize
454
+ PNotUndefType.new(n.type.type).normalize
413
455
  elsif !n.type.assignable?(PUndefType::DEFAULT)
414
456
  # THe type is NotUndef anyway, so it can be stripped of
415
457
  n.type
@@ -419,6 +461,15 @@ class PNotUndefType < PTypeWithContainedType
419
461
  end
420
462
  end
421
463
 
464
+ def new_function(loader)
465
+ # If only NotUndef, then use Unit's null converter
466
+ if type.nil?
467
+ PUnitType.new_function(self.class, loader)
468
+ else
469
+ type.new_function(loader)
470
+ end
471
+ end
472
+
422
473
  DEFAULT = PNotUndefType.new
423
474
 
424
475
  protected
@@ -432,7 +483,7 @@ end
432
483
  # @api public
433
484
  #
434
485
  class PUndefType < PAnyType
435
- def instance?(o)
486
+ def instance?(o, guard = nil)
436
487
  o.nil? || o == :undef
437
488
  end
438
489
 
@@ -455,10 +506,23 @@ end
455
506
  # @api private
456
507
  #
457
508
  class PUnitType < PAnyType
458
- def instance?(o)
509
+ def instance?(o, guard = nil)
459
510
  true
460
511
  end
461
512
 
513
+ # A "null" implementation - that simply returns the given argument
514
+ def self.new_function(_, loader)
515
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_unit, loader) do
516
+ dispatch :from_args do
517
+ param 'Any', :from
518
+ end
519
+
520
+ def from_args(from)
521
+ from
522
+ end
523
+ end
524
+ end
525
+
462
526
  DEFAULT = PUnitType.new
463
527
 
464
528
  protected
@@ -471,7 +535,7 @@ end
471
535
  # @api public
472
536
  #
473
537
  class PDefaultType < PAnyType
474
- def instance?(o)
538
+ def instance?(o, guard = nil)
475
539
  o == :default
476
540
  end
477
541
 
@@ -493,8 +557,8 @@ class PDataType < PAnyType
493
557
  self.class == o.class || o == PVariantType::DATA
494
558
  end
495
559
 
496
- def instance?(o)
497
- PVariantType::DATA.instance?(o)
560
+ def instance?(o, guard = nil)
561
+ PVariantType::DATA.instance?(o, guard)
498
562
  end
499
563
 
500
564
  DEFAULT = PDataType.new
@@ -521,8 +585,8 @@ end
521
585
  #
522
586
  class PScalarType < PAnyType
523
587
 
524
- def instance?(o)
525
- assignable?(TypeCalculator.infer(o))
588
+ def instance?(o, guard = nil)
589
+ assignable?(TypeCalculator.infer(o), guard)
526
590
  end
527
591
 
528
592
  DEFAULT = PScalarType.new
@@ -609,7 +673,7 @@ class PNumericType < PScalarType
609
673
  # @return [Boolean] `true` if this range intersects with the other range
610
674
  # @api public
611
675
  def intersect?(o)
612
- self.class == o.class && !(@to < o.from || o.to < @from)
676
+ self.class == o.class && !(@to < o.numeric_from || o.numeric_to < @from)
613
677
  end
614
678
 
615
679
  # Returns the lower bound of the numeric range or `nil` if no lower bound is set.
@@ -637,14 +701,14 @@ class PNumericType < PScalarType
637
701
  end
638
702
 
639
703
  def hash
640
- @from.hash * 31 + @to.hash
704
+ @from.hash ^ @to.hash
641
705
  end
642
706
 
643
707
  def eql?(o)
644
708
  self.class == o.class && @from == o.numeric_from && @to == o.numeric_to
645
709
  end
646
710
 
647
- def instance?(o)
711
+ def instance?(o, guard = nil)
648
712
  o.is_a?(Numeric) && o >= @from && o <= @to
649
713
  end
650
714
 
@@ -652,6 +716,56 @@ class PNumericType < PScalarType
652
716
  @from == -Float::INFINITY && @to == Float::INFINITY
653
717
  end
654
718
 
719
+ def self.new_function(_, loader)
720
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_numeric, loader) do
721
+ local_types do
722
+ type 'Convertible = Variant[Undef, Integer, Float, Boolean, String]'
723
+ type 'NamedArgs = Struct[{from => Convertible}]'
724
+ end
725
+
726
+ dispatch :from_args do
727
+ param 'Convertible', :from
728
+ end
729
+
730
+ dispatch :from_hash do
731
+ param 'NamedArgs', :hash_args
732
+ end
733
+ def from_args(from)
734
+ case from
735
+ when NilClass
736
+ throw :undefined_value
737
+ when Float
738
+ from
739
+ when Integer
740
+ from
741
+ when TrueClass
742
+ 1
743
+ when FalseClass
744
+ 0
745
+ when String
746
+ begin
747
+ if from[0] == '0' && (from[1].downcase == 'b' || from[1].downcase == 'x')
748
+ Integer(from)
749
+ else
750
+ Puppet::Pops::Utils.to_n(from)
751
+ end
752
+ rescue TypeError => e
753
+ raise TypeConversionError.new(e.message)
754
+ rescue ArgumentError => e
755
+ raise TypeConversionError.new(e.message)
756
+ end
757
+ else
758
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
759
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Numeric")
760
+ end
761
+ end
762
+
763
+ def from_hash(args_hash)
764
+ from_args(args_hash['from'])
765
+ end
766
+ end
767
+ end
768
+
655
769
  DEFAULT = PNumericType.new(-Float::INFINITY)
656
770
 
657
771
  protected
@@ -678,7 +792,7 @@ class PIntegerType < PNumericType
678
792
  DEFAULT
679
793
  end
680
794
 
681
- def instance?(o)
795
+ def instance?(o, guard = nil)
682
796
  o.is_a?(Integer) && o >= numeric_from && o <= numeric_to
683
797
  end
684
798
 
@@ -699,8 +813,8 @@ class PIntegerType < PNumericType
699
813
  # @api public
700
814
  def merge(o)
701
815
  if intersect?(o) || adjacent?(o)
702
- min = @from <= o.from ? @from : o.from
703
- max = @to >= o.to ? @to : o.to
816
+ min = @from <= o.numeric_from ? @from : o.numeric_from
817
+ max = @to >= o.numeric_to ? @to : o.numeric_to
704
818
  PIntegerType.new(min, max)
705
819
  else
706
820
  nil
@@ -742,6 +856,67 @@ class PIntegerType < PNumericType
742
856
  @from >= 0 ? self : PIntegerType.new(0, @to < 0 ? 0 : @to)
743
857
  end
744
858
 
859
+ def new_function(loader)
860
+ @@new_function ||= Puppet::Functions.create_loaded_function(:new, loader) do
861
+ local_types do
862
+ type 'Radix = Variant[Default, Integer[2,2], Integer[8,8], Integer[10,10], Integer[16,16]]'
863
+ type 'Convertible = Variant[Undef, Integer, Float, Boolean, String]'
864
+ type 'NamedArgs = Struct[{from => Convertible, Optional[radix] => Radix}]'
865
+ end
866
+
867
+ dispatch :from_args do
868
+ param 'Convertible', :from
869
+ optional_param 'Radix', :radix
870
+ end
871
+
872
+ dispatch :from_hash do
873
+ param 'NamedArgs', :hash_args
874
+ end
875
+
876
+ def from_args(from, radix = :default)
877
+ case from
878
+ when NilClass
879
+ throw :undefined_value
880
+ when Float
881
+ from.to_i
882
+ when Integer
883
+ from
884
+ when TrueClass
885
+ 1
886
+ when FalseClass
887
+ 0
888
+ when String
889
+ begin
890
+ radix == :default ? Integer(from) : Integer(from, assert_radix(radix))
891
+ rescue TypeError => e
892
+ raise TypeConversionError.new(e.message)
893
+ rescue ArgumentError => e
894
+ raise TypeConversionError.new(e.message)
895
+ end
896
+ else
897
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
898
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to an Integer")
899
+ end
900
+ end
901
+
902
+ def from_hash(args_hash)
903
+ from = args_hash['from']
904
+ radix = args_hash['radix'] || :default
905
+ from_args(from, radix)
906
+ end
907
+
908
+ def assert_radix(radix)
909
+ case radix
910
+ when 2, 8, 10, 16, :default
911
+ else
912
+ raise ArgumentError.new("Illegal radix: '#{radix}', expected 2, 8, 10, 16, or default")
913
+ end
914
+ radix
915
+ end
916
+
917
+ end
918
+ end
919
+
745
920
  DEFAULT = PIntegerType.new(-Float::INFINITY)
746
921
  end
747
922
 
@@ -752,7 +927,7 @@ class PFloatType < PNumericType
752
927
  DEFAULT
753
928
  end
754
929
 
755
- def instance?(o)
930
+ def instance?(o, guard = nil)
756
931
  o.is_a?(Float) && o >= numeric_from && o <= numeric_to
757
932
  end
758
933
 
@@ -772,6 +947,59 @@ class PFloatType < PNumericType
772
947
  end
773
948
  end
774
949
 
950
+ # Returns a new function that produces a Float value
951
+ #
952
+ def self.new_function(_, loader)
953
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_float, loader) do
954
+ local_types do
955
+ type 'Convertible = Variant[Undef, Integer, Float, Boolean, String]'
956
+ type 'NamedArgs = Struct[{from => Convertible}]'
957
+ end
958
+
959
+ dispatch :from_args do
960
+ param 'Convertible', :from
961
+ end
962
+
963
+ dispatch :from_hash do
964
+ param 'NamedArgs', :hash_args
965
+ end
966
+
967
+ def from_args(from)
968
+ case from
969
+ when NilClass
970
+ throw :undefined_value
971
+ when Float
972
+ from
973
+ when Integer
974
+ Float(from)
975
+ when TrueClass
976
+ 1.0
977
+ when FalseClass
978
+ 0.0
979
+ when String
980
+ begin
981
+ # support a binary as float
982
+ if from[0] == '0' && from[1].downcase == 'b'
983
+ from = Integer(from)
984
+ end
985
+ Float(from)
986
+ rescue TypeError => e
987
+ raise TypeConversionError.new(e.message)
988
+ rescue ArgumentError => e
989
+ raise TypeConversionError.new(e.message)
990
+ end
991
+ else
992
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
993
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Float")
994
+ end
995
+ end
996
+
997
+ def from_hash(args_hash)
998
+ from_args(args_hash['from'])
999
+ end
1000
+ end
1001
+ end
1002
+
775
1003
  DEFAULT = PFloatType.new(-Float::INFINITY)
776
1004
  end
777
1005
 
@@ -781,8 +1009,12 @@ class PCollectionType < PAnyType
781
1009
  attr_reader :element_type, :size_type
782
1010
 
783
1011
  def initialize(element_type, size_type = nil)
784
- @element_type = element_type
785
1012
  @size_type = size_type
1013
+ if !size_type.nil? && size_type.from == 0 && size_type.to == 0
1014
+ @element_type = PUnitType::DEFAULT
1015
+ else
1016
+ @element_type = element_type
1017
+ end
786
1018
  end
787
1019
 
788
1020
  def accept(visitor, guard)
@@ -809,8 +1041,8 @@ class PCollectionType < PAnyType
809
1041
  end
810
1042
  end
811
1043
 
812
- def instance?(o)
813
- assignable?(TypeCalculator.infer(o))
1044
+ def instance?(o, guard = nil)
1045
+ assignable?(TypeCalculator.infer(o), guard)
814
1046
  end
815
1047
 
816
1048
  # Returns an array with from (min) size to (max) size
@@ -818,8 +1050,13 @@ class PCollectionType < PAnyType
818
1050
  (@size_type || DEFAULT_SIZE).range
819
1051
  end
820
1052
 
1053
+ def has_empty_range?
1054
+ from, to = size_range
1055
+ from == 0 && to == 0
1056
+ end
1057
+
821
1058
  def hash
822
- @element_type.hash * 31 + @size_type.hash
1059
+ @element_type.hash ^ @size_type.hash
823
1060
  end
824
1061
 
825
1062
  def iterable?(guard = nil)
@@ -867,8 +1104,8 @@ class PIterableType < PTypeWithContainedType
867
1104
  @type
868
1105
  end
869
1106
 
870
- def instance?(o)
871
- if @type.nil? || @type.assignable?(PAnyType::DEFAULT)
1107
+ def instance?(o, guard = nil)
1108
+ if @type.nil? || @type.assignable?(PAnyType::DEFAULT, guard)
872
1109
  # Any element_type will do
873
1110
  case o
874
1111
  when Iterable, String, Hash, Array, Range, PEnumType
@@ -881,7 +1118,7 @@ class PIterableType < PTypeWithContainedType
881
1118
  false
882
1119
  end
883
1120
  else
884
- assignable?(TypeCalculator.infer(o))
1121
+ assignable?(TypeCalculator.infer(o), guard)
885
1122
  end
886
1123
  end
887
1124
 
@@ -916,8 +1153,8 @@ class PIteratorType < PTypeWithContainedType
916
1153
  @type
917
1154
  end
918
1155
 
919
- def instance?(o)
920
- o.is_a?(Iterable) && (@element_type.nil? || @element_type.assignable?(o.element_type))
1156
+ def instance?(o, guard = nil)
1157
+ o.is_a?(Iterable) && (@type.nil? || @type.assignable?(o.element_type, guard))
921
1158
  end
922
1159
 
923
1160
  def iterable?(guard = nil)
@@ -925,7 +1162,7 @@ class PIteratorType < PTypeWithContainedType
925
1162
  end
926
1163
 
927
1164
  def iterable_type(guard = nil)
928
- @type.nil? ? PIteratbleType::DEFAULT : PIterableType.new(@element_type)
1165
+ @type.nil? ? PIterableType::DEFAULT : PIterableType.new(@type)
929
1166
  end
930
1167
 
931
1168
  DEFAULT = PIteratorType.new(nil)
@@ -934,7 +1171,7 @@ class PIteratorType < PTypeWithContainedType
934
1171
 
935
1172
  # @api private
936
1173
  def _assignable?(o, guard)
937
- o.is_a?(PIteratorType) && (@element_type.nil? || @element_type.assignable?(o.element_type, guard))
1174
+ o.is_a?(PIteratorType) && (@type.nil? || @type.assignable?(o.element_type, guard))
938
1175
  end
939
1176
  end
940
1177
 
@@ -958,7 +1195,7 @@ class PStringType < PScalarType
958
1195
  end
959
1196
 
960
1197
  def hash
961
- @size_type.hash * 31 + @values.hash
1198
+ @size_type.hash ^ @values.hash
962
1199
  end
963
1200
 
964
1201
  def iterable?(guard = nil)
@@ -973,15 +1210,41 @@ class PStringType < PScalarType
973
1210
  self.class == o.class && @size_type == o.size_type && @values == o.values
974
1211
  end
975
1212
 
976
- def instance?(o)
1213
+ def instance?(o, guard = nil)
977
1214
  # true if size compliant
978
- if o.is_a?(String) && (@size_type.nil? || @size_type.instance?(o.size))
1215
+ if o.is_a?(String) && (@size_type.nil? || @size_type.instance?(o.size, guard))
979
1216
  @values.empty? || @values.include?(o)
980
1217
  else
981
1218
  false
982
1219
  end
983
1220
  end
984
1221
 
1222
+ def self.new_function(_, loader)
1223
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_string, loader) do
1224
+ local_types do
1225
+ type 'Format = Pattern[/^%([\s\+\-#0\[\{<\(\|]*)([1-9][0-9]*)?(?:\.([0-9]+))?([a-zA-Z])/]'
1226
+ type 'ContainerFormat = Struct[{
1227
+ Optional[format] => String,
1228
+ Optional[separator] => String,
1229
+ Optional[separator2] => String,
1230
+ Optional[string_formats] => Hash[Type, Format]
1231
+ }]'
1232
+ type 'TypeMap = Hash[Type, Variant[Format, ContainerFormat]]'
1233
+ type 'Convertible = Any'
1234
+ type 'Formats = Variant[Default, String[1], TypeMap]'
1235
+ end
1236
+
1237
+ dispatch :from_args do
1238
+ param 'Convertible', :from
1239
+ optional_param 'Formats', :string_formats
1240
+ end
1241
+
1242
+ def from_args(from, formats = :default)
1243
+ StringConverter.singleton.convert(from, formats)
1244
+ end
1245
+ end
1246
+ end
1247
+
985
1248
  DEFAULT = PStringType.new(nil)
986
1249
  NON_EMPTY = PStringType.new(PIntegerType.new(1))
987
1250
 
@@ -1040,7 +1303,12 @@ class PRegexpType < PScalarType
1040
1303
  attr_reader :pattern
1041
1304
 
1042
1305
  def initialize(pattern)
1043
- @pattern = pattern
1306
+ if pattern.is_a?(Regexp)
1307
+ @regexp = pattern
1308
+ @pattern = pattern.source
1309
+ else
1310
+ @pattern = pattern
1311
+ end
1044
1312
  end
1045
1313
 
1046
1314
  def regexp
@@ -1123,10 +1391,38 @@ end
1123
1391
  #
1124
1392
  class PBooleanType < PScalarType
1125
1393
 
1126
- def instance?(o)
1394
+ def instance?(o, guard = nil)
1127
1395
  o == true || o == false
1128
1396
  end
1129
1397
 
1398
+ def self.new_function(_, loader)
1399
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_boolean, loader) do
1400
+ dispatch :from_args do
1401
+ param 'Variant[Undef, Integer, Float, Boolean, String]', :from
1402
+ end
1403
+
1404
+ def from_args(from)
1405
+ from = from.downcase if from.is_a?(String)
1406
+ case from
1407
+ when NilClass
1408
+ throw :undefined_value
1409
+ when Float
1410
+ from != 0.0
1411
+ when Integer
1412
+ from != 0
1413
+ when true, false
1414
+ from
1415
+ when 'false', 'no', 'n'
1416
+ false
1417
+ when 'true', 'yes', 'y'
1418
+ true
1419
+ else
1420
+ raise TypeConversionError.new("Value '#{from}' of type '#{from.class}' cannot be converted to Boolean")
1421
+ end
1422
+ end
1423
+ end
1424
+ end
1425
+
1130
1426
  DEFAULT = PBooleanType.new
1131
1427
 
1132
1428
  protected
@@ -1151,7 +1447,7 @@ class PStructElement < TypedModelObject
1151
1447
  end
1152
1448
 
1153
1449
  def hash
1154
- value_type.hash * 31 + key_type.hash
1450
+ value_type.hash ^ key_type.hash
1155
1451
  end
1156
1452
 
1157
1453
  def name
@@ -1180,7 +1476,11 @@ class PStructElement < TypedModelObject
1180
1476
  end
1181
1477
 
1182
1478
  def eql?(o)
1183
- self.class == o.class && value_type == o.value_type && key_type == o.key_type
1479
+ self == o
1480
+ end
1481
+
1482
+ def ==(o)
1483
+ self.class == o.class && value_type == o.value_type && key_type == o.key_type
1184
1484
  end
1185
1485
  end
1186
1486
 
@@ -1241,8 +1541,8 @@ class PStructType < PAnyType
1241
1541
  tc = TypeCalculator.singleton
1242
1542
  PIterableType.new(
1243
1543
  PTupleType.new([
1244
- tc.unwrap_single_variant(PVariantType.new(@elements.map {|se| se.key_type })),
1245
- tc.unwrap_single_variant(PVariantType.new(@elements.map {|se| se.value_type }))],
1544
+ PVariantType.maybe_create(@elements.map {|se| se.key_type }),
1545
+ PVariantType.maybe_create(@elements.map {|se| se.value_type })],
1246
1546
  PHashType::KEY_PAIR_TUPLE_SIZE))
1247
1547
  end
1248
1548
  end
@@ -1255,7 +1555,7 @@ class PStructType < PAnyType
1255
1555
  @elements
1256
1556
  end
1257
1557
 
1258
- def instance?(o)
1558
+ def instance?(o, guard = nil)
1259
1559
  return false unless o.is_a?(Hash)
1260
1560
  matched = 0
1261
1561
  @elements.all? do |e|
@@ -1263,14 +1563,20 @@ class PStructType < PAnyType
1263
1563
  v = o[key]
1264
1564
  if v.nil? && !o.include?(key)
1265
1565
  # Entry is missing. Only OK when key is optional
1266
- e.key_type.assignable?(PUndefType::DEFAULT)
1566
+ e.key_type.assignable?(PUndefType::DEFAULT, guard)
1267
1567
  else
1268
1568
  matched += 1
1269
- e.value_type.instance?(v)
1569
+ e.value_type.instance?(v, guard)
1270
1570
  end
1271
1571
  end && matched == o.size
1272
1572
  end
1273
1573
 
1574
+ def new_function(loader)
1575
+ # Simply delegate to Hash type and let the higher level assertion deal with
1576
+ # compliance with the Struct type regarding the produced result.
1577
+ PHashType.new_function(self, loader)
1578
+ end
1579
+
1274
1580
  DEFAULT = PStructType.new(EMPTY_ARRAY)
1275
1581
 
1276
1582
  protected
@@ -1292,16 +1598,26 @@ class PStructType < PAnyType
1292
1598
  elsif o.is_a?(Types::PHashType)
1293
1599
  required = 0
1294
1600
  required_elements_assignable = elements.all? do |e|
1295
- if e.key_type.assignable?(PUndefType::DEFAULT)
1601
+ key_type = e.key_type
1602
+ if key_type.assignable?(PUndefType::DEFAULT)
1603
+ # Element is optional so Hash does not need to provide it
1296
1604
  true
1297
1605
  else
1298
1606
  required += 1
1299
- e.value_type.assignable?(o.element_type, guard)
1607
+ if e.value_type.assignable?(o.element_type, guard)
1608
+ # Hash must have something that is assignable. We don't care about the name or size of the key though
1609
+ # because we have no instance of a hash to compare against.
1610
+ key_type.generalize.assignable?(o.key_type)
1611
+ else
1612
+ false
1613
+ end
1300
1614
  end
1301
1615
  end
1302
1616
  if required_elements_assignable
1303
- size_o = o.size_type || collection_default_size_t
1617
+ size_o = o.size_type || PCollectionType::DEFAULT_SIZE
1304
1618
  PIntegerType.new(required, elements.size).assignable?(size_o, guard)
1619
+ else
1620
+ false
1305
1621
  end
1306
1622
  else
1307
1623
  false
@@ -1391,14 +1707,14 @@ class PTupleType < PAnyType
1391
1707
  end
1392
1708
  end
1393
1709
 
1394
- def instance?(o)
1710
+ def instance?(o, guard = nil)
1395
1711
  return false unless o.is_a?(Array)
1396
1712
  # compute the tuple's min/max size, and check if that size matches
1397
1713
  size_t = size_type || PIntegerType.new(*size_range)
1398
1714
 
1399
- return false unless size_t.instance?(o.size)
1715
+ return false unless size_t.instance?(o.size, guard)
1400
1716
  o.each_with_index do |element, index|
1401
- return false unless (types[index] || types[-1]).instance?(element)
1717
+ return false unless (types[index] || types[-1]).instance?(element, guard)
1402
1718
  end
1403
1719
  true
1404
1720
  end
@@ -1408,14 +1724,14 @@ class PTupleType < PAnyType
1408
1724
  end
1409
1725
 
1410
1726
  def iterable_type(guard = nil)
1411
- PIterableType.new(TypeCalculator.singleton.unwrap_single_variant(PVariantType.new(types)))
1727
+ PIterableType.new(PVariantType.maybe_create(types))
1412
1728
  end
1413
1729
 
1414
1730
  # Returns the number of elements accepted [min, max] in the tuple
1415
1731
  def size_range
1416
1732
  if @size_type.nil?
1417
1733
  types_size = @types.size
1418
- [types_size, types_size]
1734
+ types_size == 0 ? [0, Float::INFINITY] : [types_size, types_size]
1419
1735
  else
1420
1736
  @size_type.range
1421
1737
  end
@@ -1437,13 +1753,19 @@ class PTupleType < PAnyType
1437
1753
  end
1438
1754
 
1439
1755
  def hash
1440
- @size_type.hash * 31 + @types.hash
1756
+ @size_type.hash ^ @types.hash
1441
1757
  end
1442
1758
 
1443
1759
  def eql?(o)
1444
1760
  self.class == o.class && @types == o.types && @size_type == o.size_type
1445
1761
  end
1446
1762
 
1763
+ def new_function(loader)
1764
+ # Simply delegate to Array type and let the higher level assertion deal with
1765
+ # compliance with the Tuple type regarding the produced result.
1766
+ PArrayType.new_function(self, loader)
1767
+ end
1768
+
1447
1769
  DATA = PTupleType.new([PDataType::DEFAULT], PCollectionType::DEFAULT_SIZE)
1448
1770
  DEFAULT = PTupleType.new(EMPTY_ARRAY)
1449
1771
 
@@ -1452,36 +1774,33 @@ class PTupleType < PAnyType
1452
1774
  # @api private
1453
1775
  def _assignable?(o, guard)
1454
1776
  return true if self == o
1777
+ return false unless o.is_a?(PTupleType) || o.is_a?(PArrayType)
1455
1778
  s_types = types
1456
- return true if s_types.empty? && (o.is_a?(PArrayType))
1457
1779
  size_s = size_type || PIntegerType.new(*size_range)
1458
1780
 
1459
1781
  if o.is_a?(PTupleType)
1460
1782
  size_o = o.size_type || PIntegerType.new(*o.size_range)
1461
-
1462
- # not assignable if the number of types in o is outside number of types in t1
1463
- if size_s.assignable?(size_o, guard)
1783
+ return false unless size_s.assignable?(size_o, guard)
1784
+ unless s_types.empty?
1464
1785
  o_types = o.types
1786
+ return false if o_types.empty?
1465
1787
  o_types.size.times do |index|
1466
1788
  return false unless (s_types[index] || s_types[-1]).assignable?(o_types[index], guard)
1467
1789
  end
1468
- return true
1469
- else
1470
- return false
1471
1790
  end
1472
- elsif o.is_a?(PArrayType)
1473
- o_entry = o.element_type
1474
- # Array of anything can not be assigned (unless tuple is tuple of anything) - this case
1475
- # was handled at the top of this method.
1476
- #
1477
- return false if o_entry.nil?
1791
+ else
1478
1792
  size_o = o.size_type || PCollectionType::DEFAULT_SIZE
1479
1793
  return false unless size_s.assignable?(size_o, guard)
1480
- [s_types.size, size_o.range[1]].min.times { |index| return false unless (s_types[index] || s_types[-1]).assignable?(o_entry, guard) }
1481
- true
1482
- else
1483
- false
1794
+ unless s_types.empty?
1795
+ o_entry = o.element_type
1796
+ # Array of anything can not be assigned (unless tuple is tuple of anything) - this case
1797
+ # was handled at the top of this method.
1798
+ #
1799
+ return false if o_entry.nil?
1800
+ [s_types.size, size_o.range[1]].min.times { |index| return false unless (s_types[index] || s_types[-1]).assignable?(o_entry, guard) }
1801
+ end
1484
1802
  end
1803
+ true
1485
1804
  end
1486
1805
  end
1487
1806
 
@@ -1531,8 +1850,8 @@ class PCallableType < PAnyType
1531
1850
  end
1532
1851
  end
1533
1852
 
1534
- def instance?(o)
1535
- assignable?(TypeCalculator.infer(o))
1853
+ def instance?(o, guard = nil)
1854
+ assignable?(TypeCalculator.infer(o), guard)
1536
1855
  end
1537
1856
 
1538
1857
  # @api private
@@ -1570,7 +1889,7 @@ class PCallableType < PAnyType
1570
1889
  end
1571
1890
 
1572
1891
  def hash
1573
- @param_types.hash * 31 + @block_type.hash
1892
+ @param_types.hash ^ @block_type.hash
1574
1893
  end
1575
1894
 
1576
1895
  def eql?(o)
@@ -1589,7 +1908,9 @@ class PCallableType < PAnyType
1589
1908
 
1590
1909
  # NOTE: these tests are made in reverse as it is calling the callable that is constrained
1591
1910
  # (it's lower bound), not its upper bound
1592
- return false unless o.param_types.assignable?(@param_types, guard)
1911
+ other_param_types = o.param_types
1912
+
1913
+ return false if other_param_types.nil? || !other_param_types.assignable?(@param_types, guard)
1593
1914
  # names are ignored, they are just information
1594
1915
  # Blocks must be compatible
1595
1916
  this_block_t = @block_type || PUndefType::DEFAULT
@@ -1626,12 +1947,50 @@ class PArrayType < PCollectionType
1626
1947
  end
1627
1948
  end
1628
1949
 
1629
- def instance?(o)
1950
+ def instance?(o, guard = nil)
1630
1951
  return false unless o.is_a?(Array)
1631
1952
  element_t = element_type
1632
- return false unless element_t.nil? || o.all? {|element| element_t.instance?(element) }
1953
+ return false unless element_t.nil? || o.all? {|element| element_t.instance?(element, guard) }
1633
1954
  size_t = size_type
1634
- size_t.nil? || size_t.instance?(o.size)
1955
+ size_t.nil? || size_t.instance?(o.size, guard)
1956
+ end
1957
+
1958
+ # Returns a new function that produces an Array
1959
+ #
1960
+ def self.new_function(_, loader)
1961
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_array, loader) do
1962
+
1963
+ dispatch :from_args do
1964
+ param 'Any', :from
1965
+ optional_param 'Boolean', :wrap
1966
+ end
1967
+
1968
+ def from_args(from, wrap = false)
1969
+ case from
1970
+ when NilClass
1971
+ if wrap
1972
+ [nil]
1973
+ else
1974
+ throw :undefined_value
1975
+ end
1976
+ when Array
1977
+ from
1978
+ when Hash
1979
+ wrap ? [from] : from.to_a
1980
+ else
1981
+ if wrap
1982
+ [from]
1983
+ else
1984
+ if PIterableType::DEFAULT.instance?(from)
1985
+ Iterable.on(from).to_a
1986
+ else
1987
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
1988
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Array")
1989
+ end
1990
+ end
1991
+ end
1992
+ end
1993
+ end
1635
1994
  end
1636
1995
 
1637
1996
  DATA = PArrayType.new(PDataType::DEFAULT, DEFAULT_SIZE)
@@ -1664,7 +2023,7 @@ class PArrayType < PCollectionType
1664
2023
  return false if o_regular.size + o_to > max
1665
2024
  # each tuple type must be assignable to the element type
1666
2025
  o_required.times do |index|
1667
- o_entry = tuple_entry_at(o, o_from, o_to, index)
2026
+ o_entry = tuple_entry_at(o, o_to, index)
1668
2027
  return false unless s_entry.assignable?(o_entry, guard)
1669
2028
  end
1670
2029
  # ... and so must the last, possibly optional (ranged) type
@@ -1684,7 +2043,11 @@ class PHashType < PCollectionType
1684
2043
 
1685
2044
  def initialize(key_type, value_type, size_type = nil)
1686
2045
  super(value_type, size_type)
1687
- @key_type = key_type
2046
+ if !size_type.nil? && size_type.from == 0 && size_type.to == 0
2047
+ @key_type = PUnitType::DEFAULT
2048
+ else
2049
+ @key_type = key_type
2050
+ end
1688
2051
  end
1689
2052
 
1690
2053
  def accept(visitor, guard)
@@ -1717,17 +2080,17 @@ class PHashType < PCollectionType
1717
2080
  end
1718
2081
 
1719
2082
  def hash
1720
- @key_type.hash * 31 + super
2083
+ super ^ @key_type.hash
1721
2084
  end
1722
2085
 
1723
- def instance?(o)
2086
+ def instance?(o, guard = nil)
1724
2087
  return false unless o.is_a?(Hash)
1725
2088
  key_t = key_type
1726
2089
  element_t = element_type
1727
- if (key_t.nil? || o.keys.all? {|key| key_t.instance?(key) }) &&
1728
- (element_t.nil? || o.values.all? {|value| element_t.instance?(value) })
2090
+ if (key_t.nil? || o.keys.all? {|key| key_t.instance?(key, guard) }) &&
2091
+ (element_t.nil? || o.values.all? {|value| element_t.instance?(value, guard) })
1729
2092
  size_t = size_type
1730
- size_t.nil? || size_t.instance?(o.size)
2093
+ size_t.nil? || size_t.instance?(o.size, guard)
1731
2094
  else
1732
2095
  false
1733
2096
  end
@@ -1753,6 +2116,53 @@ class PHashType < PCollectionType
1753
2116
  self == EMPTY
1754
2117
  end
1755
2118
 
2119
+ # Returns a new function that produces a Hash
2120
+ #
2121
+ def self.new_function(_, loader)
2122
+ @new_function ||= Puppet::Functions.create_loaded_function(:new_hash, loader) do
2123
+ local_types do
2124
+ type 'KeyValueArray = Array[Tuple[Any,Any],1]'
2125
+ end
2126
+
2127
+ dispatch :from_tuples do
2128
+ param 'KeyValueArray', :from
2129
+ end
2130
+
2131
+ dispatch :from_array do
2132
+ param 'Any', :from
2133
+ end
2134
+
2135
+ def from_tuples(tuple_array)
2136
+ Hash[tuple_array]
2137
+ end
2138
+
2139
+ def from_array(from)
2140
+ case from
2141
+ when NilClass
2142
+ throw :undefined_value
2143
+ when Array
2144
+ if from.size == 0
2145
+ {}
2146
+ else
2147
+ unless from.size % 2 == 0
2148
+ raise TypeConversionError.new("odd number of arguments for Hash")
2149
+ end
2150
+ Hash[*from]
2151
+ end
2152
+ when Hash
2153
+ from
2154
+ else
2155
+ if PIterableType::DEFAULT.instance?(from)
2156
+ Hash[*Iterable.on(from).to_a]
2157
+ else
2158
+ t = Puppet::Pops::Types::TypeCalculator.singleton.infer(from).generalize
2159
+ raise TypeConversionError.new("Value of type '#{t}' cannot be converted to Hash")
2160
+ end
2161
+ end
2162
+ end
2163
+ end
2164
+ end
2165
+
1756
2166
  DEFAULT = PHashType.new(nil, nil)
1757
2167
  KEY_PAIR_TUPLE_SIZE = PIntegerType.new(2,2)
1758
2168
  DEFAULT_KEY_PAIR_TUPLE = PTupleType.new([PUnitType::DEFAULT, PUnitType::DEFAULT], KEY_PAIR_TUPLE_SIZE)
@@ -1775,8 +2185,8 @@ class PHashType < PCollectionType
1775
2185
  # hash must accept all value types
1776
2186
  # hash must accept the size of the struct
1777
2187
  o_elements = o.elements
1778
- (size_type || DEFAULT_SIZE).instance?(o_elements.size) &&
1779
- o_elements.all? {|e| (key_type.nil? || key_type.instance?(e.name)) && (element_type.nil? || element_type.assignable?(e.value_type, guard)) }
2188
+ (size_type || DEFAULT_SIZE).instance?(o_elements.size, guard) &&
2189
+ o_elements.all? {|e| (key_type.nil? || key_type.instance?(e.name, guard)) && (element_type.nil? || element_type.assignable?(e.value_type, guard)) }
1780
2190
  else
1781
2191
  false
1782
2192
  end
@@ -1791,9 +2201,21 @@ class PVariantType < PAnyType
1791
2201
 
1792
2202
  attr_reader :types
1793
2203
 
2204
+ # Checks if the number of unique types in the given array is greater than one, and if so
2205
+ # creates a Variant with those types and returns it. If only one unique type is found,
2206
+ # that type is instead returned.
2207
+ #
2208
+ # @param types [Array<PAnyType>] the variants
2209
+ # @return [PAnyType] the resulting type
2210
+ # @api public
2211
+ def self.maybe_create(types)
2212
+ types = types.uniq
2213
+ types.size == 1 ? types[0] : new(types)
2214
+ end
2215
+
1794
2216
  # @param types [Array[PAnyType]] the variants
1795
2217
  def initialize(types)
1796
- @types = types.uniq.freeze
2218
+ @types = types.freeze
1797
2219
  end
1798
2220
 
1799
2221
  def accept(visitor, guard)
@@ -1813,7 +2235,7 @@ class PVariantType < PAnyType
1813
2235
  if self == DEFAULT || self == DATA
1814
2236
  self
1815
2237
  else
1816
- alter_type_array(@types, :generalize) { |altered| PVariantType.new(mod_types) }
2238
+ alter_type_array(@types, :generalize) { |altered| PVariantType.maybe_create(altered) }
1817
2239
  end
1818
2240
  end
1819
2241
 
@@ -1834,7 +2256,7 @@ class PVariantType < PAnyType
1834
2256
  types[0]
1835
2257
  elsif types.any? { |t| t.is_a?(PUndefType) }
1836
2258
  # Undef entry present. Use an OptionalType with a normalized Variant of all types that are not Undef
1837
- POptionalType.new(PVariantType.new(types.reject { |ot| ot.is_a?(PUndefType) }).normalize(guard)).normalize(guard)
2259
+ POptionalType.new(PVariantType.maybe_create(types.reject { |ot| ot.is_a?(PUndefType) }).normalize(guard)).normalize(guard)
1838
2260
  else
1839
2261
  # Merge all variants into this one
1840
2262
  types = types.map do |t|
@@ -1854,11 +2276,12 @@ class PVariantType < PAnyType
1854
2276
  types = merge_patterns(types)
1855
2277
  types = merge_int_ranges(types)
1856
2278
  types = merge_float_ranges(types)
2279
+ types = merge_version_ranges(types)
1857
2280
 
1858
2281
  if types.size == 1
1859
2282
  types[0]
1860
2283
  else
1861
- modified || types.size != size_before_merge ? PVariantType.new(types) : self
2284
+ modified || types.size != size_before_merge ? PVariantType.maybe_create(types) : self
1862
2285
  end
1863
2286
  end
1864
2287
  end
@@ -1868,9 +2291,17 @@ class PVariantType < PAnyType
1868
2291
  @types.hash
1869
2292
  end
1870
2293
 
1871
- def instance?(o)
2294
+ def instance?(o, guard = nil)
1872
2295
  # instance of variant if o is instance? of any of variant's types
1873
- @types.any? { |type| type.instance?(o) }
2296
+ @types.any? { |type| type.instance?(o, guard) }
2297
+ end
2298
+
2299
+ def really_instance?(o, guard = nil)
2300
+ @types.inject(-1) do |memo, type|
2301
+ ri = type.really_instance?(o, guard)
2302
+ memo = ri if ri > memo
2303
+ memo
2304
+ end
1874
2305
  end
1875
2306
 
1876
2307
  def kind_of_callable?(optional = true, guard = nil)
@@ -1922,7 +2353,7 @@ class PVariantType < PAnyType
1922
2353
  optionals = parts[0]
1923
2354
  if optionals.size > 1
1924
2355
  others = parts[1]
1925
- others << POptionalType.new(PVariantType.new(optionals.map { |optional| optional.type }).normalize)
2356
+ others << POptionalType.new(PVariantType.maybe_create(optionals.map { |optional| optional.type }).normalize)
1926
2357
  array = others
1927
2358
  end
1928
2359
  end
@@ -1936,7 +2367,7 @@ class PVariantType < PAnyType
1936
2367
  not_undefs = parts[0]
1937
2368
  if not_undefs.size > 1
1938
2369
  others = parts[1]
1939
- others << PNotUndefType.new(PVariantType.new(not_undefs.map { |not_undef| not_undef.type }).normalize)
2370
+ others << PNotUndefType.new(PVariantType.maybe_create(not_undefs.map { |not_undef| not_undef.type }).normalize)
1940
2371
  array = others
1941
2372
  end
1942
2373
  end
@@ -1990,10 +2421,19 @@ class PVariantType < PAnyType
1990
2421
  array
1991
2422
  end
1992
2423
 
2424
+ def merge_version_ranges(array)
2425
+ if array.size > 1
2426
+ parts = array.partition {|t| t.is_a?(PSemVerType) }
2427
+ ranges = parts[0]
2428
+ array = [PSemVerType.new(*ranges.map(&:ranges).flatten)] + parts[1] if ranges.size > 1
2429
+ end
2430
+ array
2431
+ end
2432
+
1993
2433
  # @api private
1994
2434
  def merge_ranges(ranges)
1995
2435
  result = []
1996
- while !ranges.empty?
2436
+ until ranges.empty?
1997
2437
  unmerged = []
1998
2438
  x = ranges.pop
1999
2439
  result << ranges.inject(x) do |memo, y|
@@ -2011,58 +2451,6 @@ class PVariantType < PAnyType
2011
2451
  end
2012
2452
  end
2013
2453
 
2014
- # @api public
2015
- #
2016
- class PRuntimeType < PAnyType
2017
- attr_reader :runtime, :runtime_type_name
2018
-
2019
- def initialize(runtime, runtime_type_name = nil)
2020
- @runtime = runtime
2021
- @runtime_type_name = runtime_type_name
2022
- end
2023
-
2024
- def hash
2025
- @runtime.hash * 31 + @runtime_type_name.hash
2026
- end
2027
-
2028
- def eql?(o)
2029
- self.class == o.class && @runtime == o.runtime && @runtime_type_name == o.runtime_type_name
2030
- end
2031
-
2032
- def instance?(o)
2033
- assignable?(TypeCalculator.infer(o))
2034
- end
2035
-
2036
- def iterable?(guard = nil)
2037
- c = class_from_string(@runtime_type_name)
2038
- c.nil? ? false : c < Iterable
2039
- end
2040
-
2041
- def iterable_type(guard = nil)
2042
- iterable?(guard) ? PIterableType.new(self) : nil
2043
- end
2044
-
2045
- DEFAULT = PRuntimeType.new(nil)
2046
-
2047
- protected
2048
-
2049
- # Assignable if o's has the same runtime and the runtime name resolves to
2050
- # a class that is the same or subclass of t1's resolved runtime type name
2051
- # @api private
2052
- def _assignable?(o, guard)
2053
- return false unless o.is_a?(PRuntimeType)
2054
- return false unless @runtime == o.runtime
2055
- return true if @runtime_type_name.nil? # t1 is wider
2056
- return false if o.runtime_type_name.nil? # t1 not nil, so o can not be wider
2057
-
2058
- # NOTE: This only supports Ruby, must change when/if the set of runtimes is expanded
2059
- c1 = class_from_string(@runtime_type_name)
2060
- c2 = class_from_string(o.runtime_type_name)
2061
- return false unless c1.is_a?(Module) && c2.is_a?(Module)
2062
- !!(c2 <= c1)
2063
- end
2064
- end
2065
-
2066
2454
  # Abstract representation of a type that can be placed in a Catalog.
2067
2455
  # @api public
2068
2456
  #
@@ -2070,8 +2458,8 @@ class PCatalogEntryType < PAnyType
2070
2458
 
2071
2459
  DEFAULT = PCatalogEntryType.new
2072
2460
 
2073
- def instance?(o)
2074
- assignable?(TypeCalculator.infer(o))
2461
+ def instance?(o, guard = nil)
2462
+ assignable?(TypeCalculator.infer(o), guard)
2075
2463
  end
2076
2464
 
2077
2465
  protected
@@ -2087,17 +2475,23 @@ end
2087
2475
  class PHostClassType < PCatalogEntryType
2088
2476
  attr_reader :class_name
2089
2477
 
2478
+ NAME = 'Class'.freeze
2479
+
2090
2480
  def initialize(class_name)
2091
2481
  @class_name = class_name
2092
2482
  end
2093
2483
 
2094
2484
  def hash
2095
- 11 * @class_name.hash
2485
+ 11 ^ @class_name.hash
2096
2486
  end
2097
2487
  def eql?(o)
2098
2488
  self.class == o.class && @class_name == o.class_name
2099
2489
  end
2100
2490
 
2491
+ def simple_name
2492
+ NAME
2493
+ end
2494
+
2101
2495
  DEFAULT = PHostClassType.new(nil)
2102
2496
 
2103
2497
  protected
@@ -2116,19 +2510,20 @@ end
2116
2510
  # @api public
2117
2511
  #
2118
2512
  class PResourceType < PCatalogEntryType
2119
- attr_reader :type_name, :title
2513
+ attr_reader :type_name, :title, :downcased_name
2120
2514
 
2121
2515
  def initialize(type_name, title = nil)
2122
- @type_name = type_name
2123
- @title = title
2516
+ @type_name = type_name.freeze
2517
+ @title = title.freeze
2518
+ @downcased_name = type_name.nil? ? nil : @type_name.downcase.freeze
2124
2519
  end
2125
2520
 
2126
- def hash
2127
- @type_name.hash * 31 + @title.hash
2521
+ def eql?(o)
2522
+ self.class == o.class && @downcased_name == o.downcased_name && @title == o.title
2128
2523
  end
2129
2524
 
2130
- def eql?(o)
2131
- self.class == o.class && @type_name == o.type_name && @title == o.title
2525
+ def hash
2526
+ @downcased_name.hash ^ @title.hash
2132
2527
  end
2133
2528
 
2134
2529
  DEFAULT = PResourceType.new(nil)
@@ -2137,11 +2532,7 @@ class PResourceType < PCatalogEntryType
2137
2532
 
2138
2533
  # @api private
2139
2534
  def _assignable?(o, guard)
2140
- return false unless o.is_a?(PResourceType)
2141
- return true if @type_name.nil?
2142
- return false if @type_name != o.type_name
2143
- return true if @title.nil?
2144
- @title == o.title
2535
+ o.is_a?(PResourceType) && (@downcased_name.nil? || @downcased_name == o.downcased_name && (@title.nil? || @title == o.title))
2145
2536
  end
2146
2537
  end
2147
2538
 
@@ -2158,8 +2549,8 @@ class POptionalType < PTypeWithContainedType
2158
2549
  optional && !@type.nil? && @type.kind_of_callable?(optional, guard)
2159
2550
  end
2160
2551
 
2161
- def instance?(o)
2162
- PUndefType::DEFAULT.instance?(o) || (!@type.nil? && @type.instance?(o))
2552
+ def instance?(o, guard = nil)
2553
+ PUndefType::DEFAULT.instance?(o, guard) || (!@type.nil? && @type.instance?(o, guard))
2163
2554
  end
2164
2555
 
2165
2556
  def normalize(guard = nil)
@@ -2179,6 +2570,10 @@ class POptionalType < PTypeWithContainedType
2179
2570
  end
2180
2571
  end
2181
2572
 
2573
+ def new_function(loader)
2574
+ optional_type.new_function(loader)
2575
+ end
2576
+
2182
2577
  DEFAULT = POptionalType.new(nil)
2183
2578
 
2184
2579
  protected
@@ -2196,27 +2591,30 @@ class POptionalType < PTypeWithContainedType
2196
2591
  end
2197
2592
 
2198
2593
  class PTypeReferenceType < PAnyType
2199
- attr_reader :name, :parameters
2594
+ attr_reader :type_string
2200
2595
 
2201
- def initialize(name, parameters = nil)
2202
- @name = name
2203
- @parameters = parameters.nil? ? EMPTY_ARRAY : parameters
2596
+ def initialize(type_string)
2597
+ @type_string = type_string
2204
2598
  end
2205
2599
 
2206
2600
  def callable?(args)
2207
2601
  false
2208
2602
  end
2209
2603
 
2210
- def instance?(o)
2604
+ def instance?(o, guard = nil)
2211
2605
  false
2212
2606
  end
2213
2607
 
2214
2608
  def hash
2215
- @name.hash * 31 + @parameters.hash
2609
+ @type_string.hash
2216
2610
  end
2217
2611
 
2218
2612
  def eql?(o)
2219
- super && o.name == @name && o.parameters == @parameters
2613
+ super && o.type_string == @type_string
2614
+ end
2615
+
2616
+ def resolve(type_parser, loader)
2617
+ type_parser.parse(@type_string, loader)
2220
2618
  end
2221
2619
 
2222
2620
  protected
@@ -2235,6 +2633,7 @@ end
2235
2633
  # might contain self recursion. Whether or not that is the case is computed and remembered when the alias
2236
2634
  # is resolved since guarding against self recursive constructs is relatively expensive.
2237
2635
  #
2636
+ # @api public
2238
2637
  class PTypeAliasType < PAnyType
2239
2638
  attr_reader :name
2240
2639
 
@@ -2248,6 +2647,14 @@ class PTypeAliasType < PAnyType
2248
2647
  @self_recursion = false
2249
2648
  end
2250
2649
 
2650
+ def assignable?(o, guard = nil)
2651
+ if @self_recursion
2652
+ guard ||= RecursionGuard.new
2653
+ return true if guard.add_this(self) == RecursionGuard::SELF_RECURSION_IN_BOTH
2654
+ end
2655
+ super(o, guard)
2656
+ end
2657
+
2251
2658
  # Returns the resolved type. The type must have been resolved by a call prior to calls to this
2252
2659
  # method or an error will be raised.
2253
2660
  #
@@ -2262,13 +2669,16 @@ class PTypeAliasType < PAnyType
2262
2669
  guarded_recursion(guard, false) { |g| resolved_type.callable_args?(callable, g) }
2263
2670
  end
2264
2671
 
2672
+ def check_self_recursion(originator)
2673
+ resolved_type.check_self_recursion(originator) unless originator.equal?(self)
2674
+ end
2675
+
2265
2676
  def kind_of_callable?(optional=true, guard = nil)
2266
2677
  guarded_recursion(guard, false) { |g| resolved_type.kind_of_callable?(optional, g) }
2267
2678
  end
2268
2679
 
2269
- def instance?(o)
2270
- # No value can ever be recursive so no guard is needed here
2271
- resolved_type.instance?(o)
2680
+ def instance?(o, guard = nil)
2681
+ really_instance?(o, guard) == 1
2272
2682
  end
2273
2683
 
2274
2684
  def iterable?(guard = nil)
@@ -2283,6 +2693,44 @@ class PTypeAliasType < PAnyType
2283
2693
  @name.hash
2284
2694
  end
2285
2695
 
2696
+ # Acceptor used when checking for self recursion and that a type contains
2697
+ # something other than aliases or type references
2698
+ #
2699
+ # @api private
2700
+ class AssertOtherTypeAcceptor
2701
+ def initialize
2702
+ @other_type_detected = false
2703
+ end
2704
+
2705
+ def visit(type, _)
2706
+ unless type.is_a?(PTypeAliasType) || type.is_a?(PVariantType) || type.is_a?(PTypeReferenceType)
2707
+ @other_type_detected = true
2708
+ end
2709
+ end
2710
+
2711
+ def other_type_detected?
2712
+ @other_type_detected
2713
+ end
2714
+ end
2715
+
2716
+ # Acceptor used when re-checking for self recursion after a self recursion has been detected
2717
+ #
2718
+ # @api private
2719
+ class AssertSelfRecursionStatusAcceptor
2720
+ def visit(type, _)
2721
+ type.set_self_recursion_status if type.is_a?(PTypeAliasType)
2722
+ end
2723
+ end
2724
+
2725
+ def set_self_recursion_status
2726
+ return if @self_recursion || @resolved_type.is_a?(PTypeReferenceType)
2727
+ @self_recursion = true
2728
+ guard = RecursionGuard.new
2729
+ accept(NoopTypeAcceptor::INSTANCE, guard)
2730
+ @self_recursion = guard.recursive_this?(self)
2731
+ when_self_recursion_detected if @self_recursion # no difference
2732
+ end
2733
+
2286
2734
  # Called from the TypeParser once it has found a type using the Loader. The TypeParser will
2287
2735
  # interpret the contained expression and the resolved type is remembered. This method also
2288
2736
  # checks and remembers if the resolve type contains self recursion.
@@ -2303,12 +2751,25 @@ class PTypeAliasType < PAnyType
2303
2751
  # on several methods and this knowledge is used to avoid that for non-recursive
2304
2752
  # types.
2305
2753
  guard = RecursionGuard.new
2306
- accept(NoopTypeAcceptor::INSTANCE, guard)
2754
+ real_type_asserter = AssertOtherTypeAcceptor.new
2755
+ accept(real_type_asserter, guard)
2756
+ unless real_type_asserter.other_type_detected?
2757
+ raise ArgumentError, "Type alias '#{name}' cannot be resolved to a real type"
2758
+ end
2307
2759
  @self_recursion = guard.recursive_this?(self)
2760
+ # All aliases involved must re-check status since this alias is now resolved
2761
+ if @self_recursion
2762
+ accept(AssertSelfRecursionStatusAcceptor.new, RecursionGuard.new)
2763
+ when_self_recursion_detected
2764
+ end
2308
2765
  rescue
2309
2766
  @resolved_type = nil
2310
2767
  raise
2311
2768
  end
2769
+ else
2770
+ # An alias may appoint an Object type that isn't resolved yet. The default type
2771
+ # reference is used to prevent endless recursion and should not be resolved here.
2772
+ @resolved_type.resolve(type_parser, loader) unless @resolved_type.equal?(PTypeReferenceType::DEFAULT)
2312
2773
  end
2313
2774
  self
2314
2775
  end
@@ -2319,7 +2780,7 @@ class PTypeAliasType < PAnyType
2319
2780
 
2320
2781
  def accept(visitor, guard)
2321
2782
  guarded_recursion(guard, nil) do |g|
2322
- super
2783
+ super(visitor, g)
2323
2784
  resolved_type.accept(visitor, g)
2324
2785
  end
2325
2786
  end
@@ -2328,17 +2789,42 @@ class PTypeAliasType < PAnyType
2328
2789
  @self_recursion
2329
2790
  end
2330
2791
 
2792
+ # Returns the expanded string the form of the alias, e.g. <alias name> = <resolved type>
2793
+ #
2794
+ # @return [String] the expanded form of this alias
2795
+ # @api public
2796
+ def to_s
2797
+ TypeFormatter.singleton.alias_expanded_string(self)
2798
+ end
2799
+
2800
+ # Delegates to resolved type
2801
+ def respond_to_missing?(name, include_private)
2802
+ resolved_type.respond_to?(name, include_private)
2803
+ end
2804
+
2805
+ # Delegates to resolved type
2806
+ def method_missing(name, *arguments, &block)
2807
+ resolved_type.send(name, *arguments, &block)
2808
+ end
2809
+
2810
+ # @api private
2811
+ def really_instance?(o, guard = nil)
2812
+ if @self_recursion
2813
+ guard ||= RecursionGuard.new
2814
+ guard.add_that(o)
2815
+ return 0 if guard.add_this(self) == RecursionGuard::SELF_RECURSION_IN_BOTH
2816
+ end
2817
+ resolved_type.really_instance?(o, guard)
2818
+ end
2819
+
2331
2820
  protected
2332
2821
 
2333
2822
  def _assignable?(o, guard)
2334
- guard ||= RecursionGuard.new
2335
- if guard.add_this(self) == RecursionGuard::SELF_RECURSION_IN_BOTH
2336
- # Recursion detected both in self and other. This means that other is assignable
2337
- # to self. This point would not have been reached otherwise
2338
- true
2339
- else
2340
- resolved_type.assignable?(o, guard)
2341
- end
2823
+ resolved_type.assignable?(o, guard)
2824
+ end
2825
+
2826
+ def new_function(loader)
2827
+ resolved_type.new_function(loader)
2342
2828
  end
2343
2829
 
2344
2830
  private
@@ -2352,7 +2838,41 @@ class PTypeAliasType < PAnyType
2352
2838
  end
2353
2839
  end
2354
2840
 
2841
+ def when_self_recursion_detected
2842
+ if @resolved_type.is_a?(PVariantType)
2843
+ # Drop variants that are not real types
2844
+ resolved_types = @resolved_type.types
2845
+ real_types = resolved_types.select do |type|
2846
+ next false if type == self
2847
+ real_type_asserter = AssertOtherTypeAcceptor.new
2848
+ accept(real_type_asserter, RecursionGuard.new)
2849
+ real_type_asserter.other_type_detected?
2850
+ end
2851
+ if real_types.size != resolved_types.size
2852
+ if real_types.size == 1
2853
+ @resolved_type = real_types[0]
2854
+ else
2855
+ @resolved_type = PVariantType.maybe_create(real_types)
2856
+ end
2857
+ # Drop self recursion status in case it's not self recursive anymore
2858
+ guard = RecursionGuard.new
2859
+ accept(NoopTypeAcceptor::INSTANCE, guard)
2860
+ @self_recursion = guard.recursive_this?(self)
2861
+ end
2862
+ end
2863
+ @resolved_type.check_self_recursion(self) if @self_recursion
2864
+ end
2865
+
2355
2866
  DEFAULT = PTypeAliasType.new('UnresolvedAlias', nil, PTypeReferenceType::DEFAULT)
2356
2867
  end
2357
2868
  end
2358
2869
  end
2870
+
2871
+ require 'puppet/pops/pcore'
2872
+
2873
+ require_relative 'puppet_object'
2874
+ require_relative 'p_object_type'
2875
+ require_relative 'p_runtime_type'
2876
+ require_relative 'p_sem_ver_type'
2877
+ require_relative 'p_sem_ver_range_type'
2878
+ require_relative 'implementation_registry'