puppet-strings 0.4.0 → 0.99.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +122 -0
  3. data/COMMITTERS.md +185 -0
  4. data/CONTRIBUTING.md +89 -0
  5. data/Gemfile +38 -0
  6. data/JSON.md +511 -0
  7. data/LICENSE +13 -0
  8. data/README.md +416 -0
  9. data/Rakefile +49 -0
  10. data/lib/puppet-strings.rb +63 -0
  11. data/lib/puppet-strings/json.rb +49 -0
  12. data/lib/puppet-strings/tasks.rb +10 -0
  13. data/lib/puppet-strings/tasks/generate.rb +23 -0
  14. data/lib/puppet-strings/tasks/gh_pages.rb +43 -0
  15. data/lib/puppet-strings/yard.rb +96 -0
  16. data/lib/puppet-strings/yard/code_objects.rb +8 -0
  17. data/lib/puppet-strings/yard/code_objects/base.rb +14 -0
  18. data/lib/puppet-strings/yard/code_objects/class.rb +59 -0
  19. data/lib/puppet-strings/yard/code_objects/defined_type.rb +58 -0
  20. data/lib/puppet-strings/yard/code_objects/function.rb +93 -0
  21. data/lib/puppet-strings/yard/code_objects/group.rb +30 -0
  22. data/lib/puppet-strings/yard/code_objects/provider.rb +93 -0
  23. data/lib/puppet-strings/yard/code_objects/type.rb +146 -0
  24. data/lib/puppet-strings/yard/handlers.rb +16 -0
  25. data/lib/puppet-strings/yard/handlers/puppet/base.rb +44 -0
  26. data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +23 -0
  27. data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +23 -0
  28. data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +42 -0
  29. data/lib/puppet-strings/yard/handlers/ruby/base.rb +38 -0
  30. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +357 -0
  31. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +113 -0
  32. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +194 -0
  33. data/lib/puppet-strings/yard/parsers.rb +7 -0
  34. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +70 -0
  35. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +146 -0
  36. data/lib/puppet-strings/yard/tags.rb +6 -0
  37. data/lib/puppet-strings/yard/tags/overload_tag.rb +109 -0
  38. data/lib/puppet-strings/yard/tags/parameter_directive.rb +24 -0
  39. data/lib/puppet-strings/yard/tags/property_directive.rb +24 -0
  40. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
  41. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
  42. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
  43. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
  44. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
  45. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +64 -0
  46. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +35 -0
  47. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +172 -0
  48. data/lib/puppet-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
  49. data/lib/puppet-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
  50. data/lib/puppet-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
  51. data/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb +14 -0
  52. data/lib/puppet-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
  53. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
  54. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
  55. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
  56. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb +5 -0
  57. data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
  58. data/lib/puppet-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
  59. data/lib/puppet-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
  60. data/lib/puppet-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
  61. data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +5 -0
  62. data/lib/puppet-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
  63. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
  64. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/collection.erb +10 -0
  65. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
  66. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
  67. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
  68. data/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb +29 -0
  69. data/lib/puppet-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
  70. data/lib/puppet-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
  71. data/lib/puppet-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
  72. data/lib/puppet-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
  73. data/lib/puppet-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
  74. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +32 -0
  75. data/lib/puppet-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
  76. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +15 -0
  77. data/lib/puppet/application/strings.rb +1 -0
  78. data/lib/puppet/face/strings.rb +80 -39
  79. data/spec/acceptance/emit_json_options.rb +41 -0
  80. data/spec/acceptance/lib/util.rb +15 -0
  81. data/spec/acceptance/running_strings_generate.rb +54 -0
  82. data/spec/fixtures/acceptance/modules/test/functions/add.pp +9 -0
  83. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +5 -0
  84. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +2 -0
  85. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +9 -0
  86. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +15 -0
  87. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +27 -0
  88. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +27 -0
  89. data/spec/fixtures/acceptance/modules/test/metadata.json +6 -0
  90. data/spec/fixtures/unit/json/output.json +348 -0
  91. data/spec/fixtures/unit/json/output_without_puppet_function.json +301 -0
  92. data/spec/spec_helper.rb +21 -0
  93. data/spec/spec_helper_acceptance.rb +27 -0
  94. data/spec/unit/puppet-strings/json_spec.rb +136 -0
  95. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +155 -0
  96. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +155 -0
  97. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +169 -0
  98. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +613 -0
  99. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +90 -0
  100. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +214 -0
  101. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +171 -0
  102. metadata +115 -92
  103. data/lib/puppet-strings/rake_tasks.rb +0 -18
  104. data/lib/puppet_x/puppetlabs/strings.rb +0 -64
  105. data/lib/puppet_x/puppetlabs/strings/actions.rb +0 -92
  106. data/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb +0 -79
  107. data/lib/puppet_x/puppetlabs/strings/pops/yard_transformer.rb +0 -47
  108. data/lib/puppet_x/puppetlabs/strings/util.rb +0 -65
  109. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object.rb +0 -33
  110. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/host_class_object.rb +0 -22
  111. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/method_object.rb +0 -62
  112. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/provider_object.rb +0 -24
  113. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object.rb +0 -48
  114. data/lib/puppet_x/puppetlabs/strings/yard/code_objects/type_object.rb +0 -42
  115. data/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb +0 -40
  116. data/lib/puppet_x/puppetlabs/strings/yard/handlers/base.rb +0 -13
  117. data/lib/puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler.rb +0 -31
  118. data/lib/puppet_x/puppetlabs/strings/yard/handlers/heredoc_helper.rb +0 -80
  119. data/lib/puppet_x/puppetlabs/strings/yard/handlers/host_class_handler.rb +0 -42
  120. data/lib/puppet_x/puppetlabs/strings/yard/handlers/provider_handler.rb +0 -95
  121. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +0 -54
  122. data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +0 -234
  123. data/lib/puppet_x/puppetlabs/strings/yard/handlers/type_handler.rb +0 -295
  124. data/lib/puppet_x/puppetlabs/strings/yard/json_registry_store.rb +0 -85
  125. data/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb +0 -68
  126. data/lib/puppet_x/puppetlabs/strings/yard/parser.rb +0 -30
  127. data/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb +0 -9
  128. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb +0 -34
  129. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/header.erb +0 -5
  130. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb +0 -6
  131. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/setup.rb +0 -1
  132. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/setup.rb +0 -49
  133. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_class.erb +0 -2
  134. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_manifest.erb +0 -1
  135. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb +0 -21
  136. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +0 -1
  137. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +0 -1
  138. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/setup.rb +0 -82
  139. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/box_info.erb +0 -22
  140. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/setup.rb +0 -1
  141. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/subclasses.erb +0 -4
  142. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb +0 -21
  143. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/html_helper.rb +0 -139
  144. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/layout/html/setup.rb +0 -18
  145. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/html/header.erb +0 -17
  146. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/setup.rb +0 -21
  147. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/text/header.erb +0 -2
  148. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/command_details.erb +0 -8
  149. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/confine_details.erb +0 -10
  150. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/default_details.erb +0 -10
  151. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/docstring.erb +0 -34
  152. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/feature_details.erb +0 -10
  153. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/header.erb +0 -5
  154. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/setup.rb +0 -1
  155. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb +0 -50
  156. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/box_info.erb +0 -11
  157. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/header.erb +0 -5
  158. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_details_list.erb +0 -53
  159. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb +0 -20
  160. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/setup.rb +0 -1
  161. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb +0 -91
  162. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb +0 -192
  163. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/docstring.erb +0 -34
  164. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/header.erb +0 -5
  165. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/parameter_details.erb +0 -12
  166. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/provider_details.erb +0 -10
  167. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/setup.rb +0 -1
  168. data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/setup.rb +0 -55
@@ -0,0 +1,301 @@
1
+ {
2
+ "puppet_classes": [
3
+ {
4
+ "name": "klass",
5
+ "file": "(stdin)",
6
+ "line": 5,
7
+ "inherits": "foo::bar",
8
+ "docstring": {
9
+ "text": "A simple class.",
10
+ "tags": [
11
+ {
12
+ "tag_name": "param",
13
+ "text": "First param.",
14
+ "types": [
15
+ "Integer"
16
+ ],
17
+ "name": "param1"
18
+ },
19
+ {
20
+ "tag_name": "param",
21
+ "text": "Second param.",
22
+ "types": [
23
+ "Any"
24
+ ],
25
+ "name": "param2"
26
+ },
27
+ {
28
+ "tag_name": "param",
29
+ "text": "Third param.",
30
+ "types": [
31
+ "String"
32
+ ],
33
+ "name": "param3"
34
+ }
35
+ ]
36
+ },
37
+ "defaults": {
38
+ "param3": "hi"
39
+ },
40
+ "source": "class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {\n}"
41
+ }
42
+ ],
43
+ "defined_types": [
44
+ {
45
+ "name": "dt",
46
+ "file": "(stdin)",
47
+ "line": 12,
48
+ "docstring": {
49
+ "text": "A simple defined type.",
50
+ "tags": [
51
+ {
52
+ "tag_name": "param",
53
+ "text": "First param.",
54
+ "types": [
55
+ "Integer"
56
+ ],
57
+ "name": "param1"
58
+ },
59
+ {
60
+ "tag_name": "param",
61
+ "text": "Second param.",
62
+ "types": [
63
+ "Any"
64
+ ],
65
+ "name": "param2"
66
+ },
67
+ {
68
+ "tag_name": "param",
69
+ "text": "Third param.",
70
+ "types": [
71
+ "String"
72
+ ],
73
+ "name": "param3"
74
+ }
75
+ ]
76
+ },
77
+ "defaults": {
78
+ "param3": "hi"
79
+ },
80
+ "source": "define dt(Integer $param1, $param2, String $param3 = hi) {\n}"
81
+ }
82
+ ],
83
+ "resource_types": [
84
+ {
85
+ "name": "database",
86
+ "file": "(stdin)",
87
+ "line": 43,
88
+ "docstring": {
89
+ "text": "An example database server resource type."
90
+ },
91
+ "properties": [
92
+ {
93
+ "name": "ensure",
94
+ "description": "What state the database should be in.",
95
+ "values": [
96
+ "present",
97
+ "absent",
98
+ "up",
99
+ "down"
100
+ ],
101
+ "aliases": {
102
+ "up": "present",
103
+ "down": "absent"
104
+ },
105
+ "default": "up"
106
+ },
107
+ {
108
+ "name": "file",
109
+ "description": "The database file to use."
110
+ },
111
+ {
112
+ "name": "log_level",
113
+ "description": "The log level to use.",
114
+ "values": [
115
+ "debug",
116
+ "warn",
117
+ "error"
118
+ ],
119
+ "default": "warn"
120
+ }
121
+ ],
122
+ "parameters": [
123
+ {
124
+ "name": "address",
125
+ "description": "The database server name.",
126
+ "isnamevar": true
127
+ },
128
+ {
129
+ "name": "encryption_key",
130
+ "description": "The encryption key to use."
131
+ },
132
+ {
133
+ "name": "encrypt",
134
+ "description": "Whether or not to encrypt the database.",
135
+ "values": [
136
+ "true",
137
+ "false",
138
+ "yes",
139
+ "no"
140
+ ],
141
+ "default": "false"
142
+ }
143
+ ],
144
+ "features": [
145
+ {
146
+ "name": "encryption",
147
+ "description": "The provider supports encryption."
148
+ }
149
+ ]
150
+ }
151
+ ],
152
+ "providers": [
153
+ {
154
+ "name": "linux",
155
+ "type_name": "database",
156
+ "file": "(stdin)",
157
+ "line": 33,
158
+ "docstring": {
159
+ "text": "An example provider on Linux."
160
+ },
161
+ "confines": {
162
+ "kernel": "Linux",
163
+ "osfamily": "RedHat"
164
+ },
165
+ "features": [
166
+ "implements_some_feature",
167
+ "some_other_feature"
168
+ ],
169
+ "defaults": {
170
+ "kernel": "Linux"
171
+ },
172
+ "commands": {
173
+ "foo": "/usr/bin/foo"
174
+ }
175
+ }
176
+ ],
177
+ "puppet_functions": [
178
+ {
179
+ "name": "func3x",
180
+ "file": "(stdin)",
181
+ "line": 1,
182
+ "type": "ruby3x",
183
+ "signature": "func3x(String $first, Any $second)",
184
+ "docstring": {
185
+ "text": "An example 3.x function.",
186
+ "tags": [
187
+ {
188
+ "tag_name": "param",
189
+ "text": "The first parameter.",
190
+ "types": [
191
+ "String"
192
+ ],
193
+ "name": "first"
194
+ },
195
+ {
196
+ "tag_name": "param",
197
+ "text": "The second parameter.",
198
+ "types": [
199
+ "Any"
200
+ ],
201
+ "name": "second"
202
+ },
203
+ {
204
+ "tag_name": "return",
205
+ "text": "Returns nothing.",
206
+ "types": [
207
+ "Undef"
208
+ ]
209
+ }
210
+ ]
211
+ },
212
+ "source": "Puppet::Parser::Functions.newfunction(:func3x, doc: <<-DOC\nAn example 3.x function.\n@param [String] first The first parameter.\n@param second The second parameter.\n@return [Undef] Returns nothing.\nDOC\n) do |*args|\nend"
213
+ },
214
+ {
215
+ "name": "func4x",
216
+ "file": "(stdin)",
217
+ "line": 11,
218
+ "type": "ruby4x",
219
+ "docstring": {
220
+ "text": "An example 4.x function.",
221
+ "tags": [
222
+ {
223
+ "tag_name": "overload",
224
+ "signature": "func4x(Integer $param1, Any $param2, Optional[Array[String]] $param3)",
225
+ "docstring": {
226
+ "text": "The first overload.",
227
+ "tags": [
228
+ {
229
+ "tag_name": "param",
230
+ "text": "The first parameter.",
231
+ "types": [
232
+ "Integer"
233
+ ],
234
+ "name": "param1"
235
+ },
236
+ {
237
+ "tag_name": "param",
238
+ "text": "The second parameter.",
239
+ "types": [
240
+ "Any"
241
+ ],
242
+ "name": "param2"
243
+ },
244
+ {
245
+ "tag_name": "param",
246
+ "text": "The third parameter.",
247
+ "types": [
248
+ "Optional[Array[String]]"
249
+ ],
250
+ "name": "param3"
251
+ },
252
+ {
253
+ "tag_name": "return",
254
+ "text": "Returns nothing.",
255
+ "types": [
256
+ "Undef"
257
+ ]
258
+ }
259
+ ]
260
+ },
261
+ "name": "func4x"
262
+ },
263
+ {
264
+ "tag_name": "overload",
265
+ "signature": "func4x(Boolean $param, Callable &$block)",
266
+ "docstring": {
267
+ "text": "The second overload.",
268
+ "tags": [
269
+ {
270
+ "tag_name": "param",
271
+ "text": "The first parameter.",
272
+ "types": [
273
+ "Boolean"
274
+ ],
275
+ "name": "param"
276
+ },
277
+ {
278
+ "tag_name": "param",
279
+ "text": "The block parameter.",
280
+ "types": [
281
+ "Callable"
282
+ ],
283
+ "name": "&block"
284
+ },
285
+ {
286
+ "tag_name": "return",
287
+ "text": "Returns a string.",
288
+ "types": [
289
+ "String"
290
+ ]
291
+ }
292
+ ]
293
+ },
294
+ "name": "func4x"
295
+ }
296
+ ]
297
+ },
298
+ "source": "Puppet::Functions.create_function(:func4x) do\n # The first overload.\n # @param param1 The first parameter.\n # @param param2 The second parameter.\n # @param param3 The third parameter.\n # @return [Undef] Returns nothing.\n dispatch :foo do\n param 'Integer', :param1\n param 'Any', :param2\n optional_param 'Array[String]', :param3\n end\n\n # The second overload.\n # @param param The first parameter.\n # @param block The block parameter.\n # @return [String] Returns a string.\n dispatch :other do\n param 'Boolean', :param\n block_param\n end\nend"
299
+ }
300
+ ]
301
+ }
@@ -0,0 +1,21 @@
1
+ require 'mocha'
2
+ require 'rspec'
3
+ require 'puppet/version'
4
+ require 'puppet-strings'
5
+ require 'puppet-strings/yard'
6
+
7
+ # Explicitly set up YARD once
8
+ PuppetStrings::Yard.setup!
9
+
10
+ # Enable testing of Puppet functions if running against 4.1+
11
+ TEST_PUPPET_FUNCTIONS = Gem::Dependency.new('', '>= 4.1.0').match?('', Puppet::PUPPETVERSION)
12
+
13
+ RSpec.configure do |config|
14
+ config.mock_with :mocha
15
+
16
+ config.before(:each) do
17
+ # Always clear the YARD registry before each example
18
+ YARD::Registry.clear
19
+ end
20
+ end
21
+
@@ -0,0 +1,27 @@
1
+ require 'beaker-rspec/spec_helper'
2
+ require 'beaker-rspec/helpers/serverspec'
3
+
4
+ $LOAD_PATH << File.expand_path(File.join(File.dirname(__FILE__), 'acceptance/lib'))
5
+
6
+ unless ENV['RS_PROVISION'] == 'no'
7
+ install_puppet
8
+ end
9
+
10
+ RSpec.configure do |c|
11
+ # Readable test descriptions
12
+ c.formatter = :documentation
13
+
14
+ # Configure all nodes in nodeset
15
+ c.before :suite do
16
+ hosts.each do |host|
17
+ scp_to(host, Dir.glob('puppet-strings*.gem').first, 'puppet-strings.gem')
18
+ on host, 'gem install puppet-strings.gem'
19
+
20
+ scp_to(host, Dir.glob('spec/fixtures/acceptance/modules/test/pkg/username-test*.gz').first, 'test.tar.gz')
21
+ on host, puppet('module', 'install', 'test.tar.gz')
22
+
23
+ on host, 'gem install yard'
24
+ on host, 'gem install rgen'
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,136 @@
1
+ require 'spec_helper'
2
+ require 'puppet-strings/json'
3
+ require 'tempfile'
4
+
5
+ describe PuppetStrings::Json do
6
+ before :each do
7
+ # Populate the YARD registry with both Puppet and Ruby source
8
+ YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet)
9
+ # A simple class.
10
+ # @param param1 First param.
11
+ # @param param2 Second param.
12
+ # @param param3 Third param.
13
+ class klass(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
14
+ }
15
+
16
+ # A simple defined type.
17
+ # @param param1 First param.
18
+ # @param param2 Second param.
19
+ # @param param3 Third param.
20
+ define dt(Integer $param1, $param2, String $param3 = hi) {
21
+ }
22
+ SOURCE
23
+
24
+ # Only include Puppet functions for 4.1+
25
+ YARD::Parser::SourceParser.parse_string(<<-SOURCE, :puppet) if TEST_PUPPET_FUNCTIONS
26
+ # A simple function.
27
+ # @param param1 First param.
28
+ # @param param2 Second param.
29
+ # @param param3 Third param.
30
+ # @return [Undef] Returns nothing.
31
+ function func(Integer $param1, $param2, String $param3 = hi) {
32
+ }
33
+ SOURCE
34
+
35
+ YARD::Parser::SourceParser.parse_string(<<-SOURCE, :ruby)
36
+ Puppet::Parser::Functions.newfunction(:func3x, doc: <<-DOC
37
+ An example 3.x function.
38
+ @param [String] first The first parameter.
39
+ @param second The second parameter.
40
+ @return [Undef] Returns nothing.
41
+ DOC
42
+ ) do |*args|
43
+ end
44
+
45
+ # An example 4.x function.
46
+ Puppet::Functions.create_function(:func4x) do
47
+ # The first overload.
48
+ # @param param1 The first parameter.
49
+ # @param param2 The second parameter.
50
+ # @param param3 The third parameter.
51
+ # @return [Undef] Returns nothing.
52
+ dispatch :foo do
53
+ param 'Integer', :param1
54
+ param 'Any', :param2
55
+ optional_param 'Array[String]', :param3
56
+ end
57
+
58
+ # The second overload.
59
+ # @param param The first parameter.
60
+ # @param block The block parameter.
61
+ # @return [String] Returns a string.
62
+ dispatch :other do
63
+ param 'Boolean', :param
64
+ block_param
65
+ end
66
+ end
67
+
68
+ Puppet::Type.type(:database).provide :linux do
69
+ desc 'An example provider on Linux.'
70
+ confine kernel: 'Linux'
71
+ confine osfamily: 'RedHat'
72
+ defaultfor kernel: 'Linux'
73
+ has_feature :implements_some_feature
74
+ has_feature :some_other_feature
75
+ commands foo: /usr/bin/foo
76
+ end
77
+
78
+ Puppet::Type.newtype(:database) do
79
+ desc 'An example database server resource type.'
80
+ feature :encryption, 'The provider supports encryption.', methods: [:encrypt]
81
+ ensurable do
82
+ desc 'What state the database should be in.'
83
+ defaultvalues
84
+ aliasvalue(:up, :present)
85
+ aliasvalue(:down, :absent)
86
+ defaultto :up
87
+ end
88
+
89
+ newparam(:address) do
90
+ isnamevar
91
+ desc 'The database server name.'
92
+ end
93
+
94
+ newparam(:encryption_key, required_features: :encryption) do
95
+ desc 'The encryption key to use.'
96
+ end
97
+
98
+ newparam(:encrypt, :parent => Puppet::Parameter::Boolean) do
99
+ desc 'Whether or not to encrypt the database.'
100
+ defaultto false
101
+ end
102
+
103
+ newproperty(:file) do
104
+ desc 'The database file to use.'
105
+ end
106
+
107
+ newproperty(:log_level) do
108
+ desc 'The log level to use.'
109
+ newvalue(:debug)
110
+ newvalue(:warn)
111
+ newvalue(:error)
112
+ defaultto 'warn'
113
+ end
114
+ end
115
+ SOURCE
116
+ end
117
+
118
+ let(:filename) { TEST_PUPPET_FUNCTIONS ? 'output.json' : 'output_without_puppet_function.json' }
119
+ let(:baseline_path) { File.join(File.dirname(__FILE__), "../../fixtures/unit/json/#{filename}") }
120
+ let(:baseline) { File.read(baseline_path) }
121
+
122
+ describe 'rendering JSON to a file' do
123
+ it 'should output the expected JSON content' do
124
+ Tempfile.open('json') do |file|
125
+ PuppetStrings::Json.render(file.path)
126
+ expect(File.read(file.path)).to eq(baseline)
127
+ end
128
+ end
129
+ end
130
+
131
+ describe 'rendering JSON to stdout' do
132
+ it 'should output the expected JSON content' do
133
+ expect{ PuppetStrings::Json.render(nil) }.to output(baseline).to_stdout
134
+ end
135
+ end
136
+ end