puppet-strings 2.1.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (120) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +78 -4
  3. data/CONTRIBUTING.md +32 -2
  4. data/README.md +81 -17
  5. data/lib/puppet-strings.rb +13 -4
  6. data/lib/puppet-strings/describe.rb +68 -0
  7. data/lib/puppet-strings/json.rb +2 -38
  8. data/lib/puppet-strings/markdown.rb +3 -1
  9. data/lib/puppet-strings/markdown/base.rb +37 -16
  10. data/lib/puppet-strings/markdown/data_type.rb +34 -0
  11. data/lib/puppet-strings/markdown/data_types.rb +41 -0
  12. data/lib/puppet-strings/markdown/function.rb +2 -2
  13. data/lib/puppet-strings/markdown/resource_type.rb +19 -2
  14. data/lib/puppet-strings/markdown/table_of_contents.rb +1 -0
  15. data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +12 -4
  16. data/lib/puppet-strings/markdown/templates/data_type.erb +93 -0
  17. data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
  18. data/lib/puppet-strings/markdown/templates/function.erb +36 -1
  19. data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
  20. data/lib/puppet-strings/markdown/templates/resource_type.erb +32 -12
  21. data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
  22. data/lib/puppet-strings/tasks/generate.rb +10 -3
  23. data/lib/puppet-strings/version.rb +1 -1
  24. data/lib/puppet-strings/yard.rb +16 -0
  25. data/lib/puppet-strings/yard/code_objects.rb +2 -0
  26. data/lib/puppet-strings/yard/code_objects/class.rb +2 -2
  27. data/lib/puppet-strings/yard/code_objects/data_type.rb +100 -0
  28. data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +58 -0
  29. data/lib/puppet-strings/yard/code_objects/defined_type.rb +2 -2
  30. data/lib/puppet-strings/yard/code_objects/function.rb +4 -4
  31. data/lib/puppet-strings/yard/code_objects/plan.rb +2 -2
  32. data/lib/puppet-strings/yard/code_objects/provider.rb +1 -1
  33. data/lib/puppet-strings/yard/code_objects/task.rb +1 -1
  34. data/lib/puppet-strings/yard/code_objects/type.rb +48 -6
  35. data/lib/puppet-strings/yard/handlers.rb +3 -0
  36. data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +24 -0
  37. data/lib/puppet-strings/yard/handlers/ruby/base.rb +12 -1
  38. data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +393 -0
  39. data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +2 -12
  40. data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +1 -9
  41. data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +3 -3
  42. data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +135 -0
  43. data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +56 -0
  44. data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +9 -115
  45. data/lib/puppet-strings/yard/parsers/json/parser.rb +4 -2
  46. data/lib/puppet-strings/yard/parsers/puppet/parser.rb +14 -7
  47. data/lib/puppet-strings/yard/parsers/puppet/statement.rb +25 -0
  48. data/lib/puppet-strings/yard/tags.rb +2 -0
  49. data/lib/puppet-strings/yard/tags/enum_tag.rb +12 -0
  50. data/lib/puppet-strings/yard/tags/factory.rb +16 -0
  51. data/lib/puppet-strings/yard/tags/overload_tag.rb +2 -2
  52. data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
  53. data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
  54. data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
  55. data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
  56. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
  57. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
  58. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
  59. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
  60. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
  61. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
  62. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
  63. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
  64. data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
  65. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
  66. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
  67. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
  68. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
  69. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
  70. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
  71. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
  72. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
  73. data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
  74. data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
  75. data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
  76. data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
  77. data/lib/puppet-strings/yard/util.rb +48 -0
  78. data/lib/puppet/face/strings.rb +68 -3
  79. metadata +36 -45
  80. data/Gemfile +0 -37
  81. data/HISTORY.md +0 -218
  82. data/JSON.md +0 -802
  83. data/Rakefile +0 -93
  84. data/codecov.yml +0 -3
  85. data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
  86. data/spec/acceptance/emit_json_options.rb +0 -71
  87. data/spec/acceptance/generate_markdown_spec.rb +0 -49
  88. data/spec/acceptance/lib/util.rb +0 -163
  89. data/spec/acceptance/running_strings_generate.rb +0 -54
  90. data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
  91. data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
  92. data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
  93. data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
  94. data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
  95. data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
  96. data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
  97. data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
  98. data/spec/fixtures/unit/json/output.json +0 -660
  99. data/spec/fixtures/unit/json/output_with_plan.json +0 -697
  100. data/spec/fixtures/unit/json/output_without_puppet_function.json +0 -480
  101. data/spec/fixtures/unit/markdown/output.md +0 -444
  102. data/spec/fixtures/unit/markdown/output_with_plan.md +0 -478
  103. data/spec/spec_helper.rb +0 -45
  104. data/spec/spec_helper_acceptance.rb +0 -28
  105. data/spec/unit/puppet-strings/json_spec.rb +0 -229
  106. data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
  107. data/spec/unit/puppet-strings/markdown_spec.rb +0 -283
  108. data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
  109. data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -124
  110. data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
  111. data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
  112. data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
  113. data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
  114. data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
  115. data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -214
  116. data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -269
  117. data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -70
  118. data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
  119. data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
  120. data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
@@ -1,217 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- describe PuppetStrings::Yard::Handlers::Puppet::ClassHandler do
5
- subject {
6
- YARD::Parser::SourceParser.parse_string(source, :puppet)
7
- YARD::Registry.all(:puppet_class)
8
- }
9
-
10
- describe 'parsing source without a class definition' do
11
- let(:source) { 'notice hi' }
12
-
13
- it 'no classes should be in the registry' do
14
- expect(subject.empty?).to eq(true)
15
- end
16
- end
17
-
18
- describe 'parsing source with a syntax error' do
19
- let(:source) { 'class foo{' }
20
-
21
- it 'should log an error' do
22
- expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)/).to_stdout_from_any_process
23
- expect(subject.empty?).to eq(true)
24
- end
25
- end
26
-
27
- describe 'parsing a class with a missing docstring' do
28
- let(:source) { 'class foo{}' }
29
-
30
- it 'should log a warning' do
31
- expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet class 'foo' at \(stdin\):1\./).to_stdout_from_any_process
32
- end
33
- end
34
-
35
- describe 'parsing a class with a docstring' do
36
- let(:source) { <<-SOURCE
37
- # A simple foo class.
38
- # @param param1 First param.
39
- # @param param2 Second param.
40
- # @param param3 Third param.
41
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
42
- file { '/tmp/foo':
43
- ensure => present
44
- }
45
- }
46
- SOURCE
47
- }
48
-
49
- it 'should register a class object' do
50
- expect(subject.size).to eq(1)
51
- object = subject.first
52
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Class)
53
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Classes.instance)
54
- expect(object.name).to eq(:foo)
55
- expect(object.statement).not_to eq(nil)
56
- expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']])
57
- expect(object.docstring).to eq('A simple foo class.')
58
- expect(object.docstring.tags.size).to eq(4)
59
- tags = object.docstring.tags(:param)
60
- expect(tags.size).to eq(3)
61
- expect(tags[0].name).to eq('param1')
62
- expect(tags[0].text).to eq('First param.')
63
- expect(tags[0].types).to eq(['Integer'])
64
- expect(tags[1].name).to eq('param2')
65
- expect(tags[1].text).to eq('Second param.')
66
- expect(tags[1].types).to eq(['Any'])
67
- expect(tags[2].name).to eq('param3')
68
- expect(tags[2].text).to eq('Third param.')
69
- expect(tags[2].types).to eq(['String'])
70
- tags = object.docstring.tags(:api)
71
- expect(tags.size).to eq(1)
72
- expect(tags[0].text).to eq('public')
73
- end
74
- end
75
-
76
- describe 'parsing a class with a missing parameter' do
77
- let(:source) { <<-SOURCE
78
- # A simple foo class.
79
- # @param param1 First param.
80
- # @param param2 Second param.
81
- # @param param3 Third param.
82
- # @param param4 missing!
83
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
84
- file { '/tmp/foo':
85
- ensure => present
86
- }
87
- }
88
- SOURCE
89
- }
90
-
91
- it 'should output a warning' do
92
- expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\./).to_stdout_from_any_process
93
- end
94
- end
95
-
96
- describe 'parsing a class with a missing @param tag' do
97
- let(:source) { <<-SOURCE
98
- # A simple foo class.
99
- # @param param1 First param.
100
- # @param param2 Second param.
101
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
102
- file { '/tmp/foo':
103
- ensure => present
104
- }
105
- }
106
- SOURCE
107
- }
108
-
109
- it 'should output a warning' do
110
- expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\./).to_stdout_from_any_process
111
- end
112
- end
113
-
114
- describe 'parsing a class with a typed parameter that also has a @param tag type which matches' do
115
- let(:source) { <<-SOURCE
116
- # A simple foo class.
117
- # @param [Integer] param1 First param.
118
- # @param param2 Second param.
119
- # @param param3 Third param.
120
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
121
- file { '/tmp/foo':
122
- ensure => present
123
- }
124
- }
125
- SOURCE
126
- }
127
-
128
- it 'should respect the type that was documented' do
129
- expect{ subject }.to output('').to_stdout_from_any_process
130
- expect(subject.size).to eq(1)
131
- tags = subject.first.tags(:param)
132
- expect(tags.size).to eq(3)
133
- expect(tags[0].types).to eq(['Integer'])
134
- end
135
- end
136
-
137
- describe 'parsing a class with a typed parameter that also has a @param tag type which does not match' do
138
- let(:source) { <<-SOURCE
139
- # A simple foo class.
140
- # @param [Boolean] param1 First param.
141
- # @param param2 Second param.
142
- # @param param3 Third param.
143
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
144
- file { '/tmp/foo':
145
- ensure => present
146
- }
147
- }
148
- SOURCE
149
- }
150
-
151
- it 'should output a warning' do
152
- expect{ subject }.to output(/\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):5: ignoring in favor of parameter type information./).to_stdout_from_any_process
153
- end
154
- end
155
-
156
- describe 'parsing a class with a untyped parameter that also has a @param tag type' do
157
- let(:source) { <<-SOURCE
158
- # A simple foo class.
159
- # @param param1 First param.
160
- # @param [Boolean] param2 Second param.
161
- # @param param3 Third param.
162
- class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
163
- file { '/tmp/foo':
164
- ensure => present
165
- }
166
- }
167
- SOURCE
168
- }
169
-
170
- it 'should respect the type that was documented' do
171
- expect{ subject }.to output('').to_stdout_from_any_process
172
- expect(subject.size).to eq(1)
173
- tags = subject.first.tags(:param)
174
- expect(tags.size).to eq(3)
175
- expect(tags[1].types).to eq(['Boolean'])
176
- end
177
- end
178
-
179
- describe 'parsing a class with a summary' do
180
- context 'when the summary has fewer than 140 characters' do
181
- let(:source) { <<-SOURCE
182
- # A simple foo class.
183
- # @summary A short summary.
184
- class foo() {
185
- file { '/tmp/foo':
186
- ensure => present
187
- }
188
- }
189
- SOURCE
190
- }
191
-
192
- it 'should parse the summary' do
193
- expect{ subject }.to output('').to_stdout_from_any_process
194
- expect(subject.size).to eq(1)
195
- summary = subject.first.tags(:summary)
196
- expect(summary.first.text).to eq('A short summary.')
197
- end
198
- end
199
-
200
- context 'when the summary has more than 140 characters' do
201
- let(:source) { <<-SOURCE
202
- # A simple foo class.
203
- # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!!
204
- class foo() {
205
- file { '/tmp/foo':
206
- ensure => present
207
- }
208
- }
209
- SOURCE
210
- }
211
-
212
- it 'should log a warning' do
213
- expect{ subject }.to output(/\[warn\]: The length of the summary for puppet_class 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process
214
- end
215
- end
216
- end
217
- end
@@ -1,231 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- describe PuppetStrings::Yard::Handlers::Puppet::DefinedTypeHandler do
5
- subject {
6
- YARD::Parser::SourceParser.parse_string(source, :puppet)
7
- YARD::Registry.all(:puppet_defined_type)
8
- }
9
-
10
- describe 'parsing source without a defined type definition' do
11
- let(:source) { 'notice hi' }
12
-
13
- it 'no defined types should be in the registry' do
14
- expect(subject.empty?).to eq(true)
15
- end
16
- end
17
-
18
- describe 'parsing source with a syntax error' do
19
- let(:source) { 'define foo{' }
20
-
21
- it 'should log an error' do
22
- expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of (file|input)/).to_stdout_from_any_process
23
- expect(subject.empty?).to eq(true)
24
- end
25
- end
26
-
27
- describe 'parsing a defined type with a missing docstring' do
28
- let(:source) { 'define foo{}' }
29
-
30
- it 'should log a warning' do
31
- expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet defined type 'foo' at \(stdin\):1\./).to_stdout_from_any_process
32
- end
33
- end
34
-
35
- describe 'parsing a defined type with a docstring' do
36
- let(:source) { <<-SOURCE
37
- # A simple foo defined type.
38
- # @param name The type name.
39
- # @param param1 First param.
40
- # @param param2 Second param.
41
- # @param param3 Third param.
42
- define foo(Integer $param1, $param2, String $param3 = hi) {
43
- file { '/tmp/foo':
44
- ensure => present
45
- }
46
- }
47
- SOURCE
48
- }
49
- it 'does not output a warning for title/name' do
50
- expect{ subject }.not_to output(/\[warn\].*(name|title).*/).to_stdout_from_any_process
51
- end
52
-
53
- it 'should register a defined type object' do
54
- expect(subject.size).to eq(1)
55
- object = subject.first
56
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::DefinedType)
57
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::DefinedTypes.instance)
58
- expect(object.name).to eq(:foo)
59
- expect(object.statement).not_to eq(nil)
60
- expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']])
61
- expect(object.docstring).to eq('A simple foo defined type.')
62
- expect(object.docstring.tags.size).to eq(5)
63
- tags = object.docstring.tags(:param)
64
- expect(tags.size).to eq(4)
65
- expect(tags[0].name).to eq('name')
66
- expect(tags[0].text).to eq('The type name.')
67
- expect(tags[0].types).to eq(nil)
68
- expect(tags[1].name).to eq('param1')
69
- expect(tags[1].text).to eq('First param.')
70
- expect(tags[1].types).to eq(['Integer'])
71
- expect(tags[2].name).to eq('param2')
72
- expect(tags[2].text).to eq('Second param.')
73
- expect(tags[2].types).to eq(['Any'])
74
- expect(tags[3].name).to eq('param3')
75
- expect(tags[3].text).to eq('Third param.')
76
- expect(tags[3].types).to eq(['String'])
77
- tags = object.docstring.tags(:api)
78
- expect(tags.size).to eq(1)
79
- expect(tags[0].text).to eq('public')
80
- end
81
- end
82
-
83
- describe 'parsing a defined type with a missing parameter' do
84
- let(:source) { <<-SOURCE
85
- # A simple foo defined type.
86
- # @param param1 First param.
87
- # @param param2 Second param.
88
- # @param param3 Third param.
89
- # @param param4 missing!
90
- define foo(Integer $param1, $param2, String $param3 = hi) {
91
- file { '/tmp/foo':
92
- ensure => present
93
- }
94
- }
95
- SOURCE
96
- }
97
-
98
- it 'should output a warning' do
99
- expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\./).to_stdout_from_any_process
100
- end
101
- end
102
-
103
- describe 'parsing a defined type with a missing @param tag' do
104
- let(:source) { <<-SOURCE
105
- # A simple foo defined type.
106
- # @param param1 First param.
107
- # @param param2 Second param.
108
- define foo(Integer $param1, $param2, String $param3 = hi) {
109
- file { '/tmp/foo':
110
- ensure => present
111
- }
112
- }
113
- SOURCE
114
- }
115
-
116
- it 'should output a warning' do
117
- expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\./).to_stdout_from_any_process
118
- end
119
- end
120
-
121
- describe 'parsing a defined type with a typed parameter that also has a @param tag type which matches' do
122
- let(:source) { <<-SOURCE
123
- # A simple foo defined type.
124
- # @param [Integer] param1 First param.
125
- # @param param2 Second param.
126
- # @param param3 Third param.
127
- define foo(Integer $param1, $param2, String $param3 = hi) {
128
- file { '/tmp/foo':
129
- ensure => present
130
- }
131
- }
132
- SOURCE
133
- }
134
-
135
- it 'should respect the type that was documented' do
136
- expect{ subject }.to output('').to_stdout_from_any_process
137
- expect(subject.size).to eq(1)
138
- tags = subject.first.tags(:param)
139
- expect(tags.size).to eq(3)
140
- expect(tags[0].types).to eq(['Integer'])
141
- end
142
- end
143
-
144
- describe 'parsing a defined type with a typed parameter that also has a @param tag type which does not match' do
145
- let(:source) { <<-SOURCE
146
- # A simple foo defined type.
147
- # @param [Boolean] param1 First param.
148
- # @param param2 Second param.
149
- # @param param3 Third param.
150
- define foo(Integer $param1, $param2, String $param3 = hi) {
151
- file { '/tmp/foo':
152
- ensure => present
153
- }
154
- }
155
- SOURCE
156
- }
157
-
158
- it 'should output a warning' do
159
- expect{ subject }.to output(/\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):5: ignoring in favor of parameter type information./).to_stdout_from_any_process
160
- end
161
- end
162
-
163
- describe 'parsing a defined type with a untyped parameter that also has a @param tag type' do
164
- let(:source) { <<-SOURCE
165
- # A simple foo defined type.
166
- # @param param1 First param.
167
- # @param [Boolean] param2 Second param.
168
- # @param param3 Third param.
169
- define foo(Integer $param1, $param2, String $param3 = hi) {
170
- file { '/tmp/foo':
171
- ensure => present
172
- }
173
- }
174
- SOURCE
175
- }
176
-
177
- it 'should respect the type that was documented' do
178
- expect{ subject }.to output('').to_stdout_from_any_process
179
- expect(subject.size).to eq(1)
180
- tags = subject.first.tags(:param)
181
- expect(tags.size).to eq(3)
182
- expect(tags[1].types).to eq(['Boolean'])
183
- end
184
- end
185
-
186
- describe 'parsing a defined type with a summary' do
187
-
188
- context 'when the summary has fewer than 140 characters' do
189
- let(:source) { <<-SOURCE
190
- # A simple foo defined type.
191
- # @summary A short summary.
192
- # @param param1 First param.
193
- # @param [Boolean] param2 Second param.
194
- # @param param3 Third param.
195
- define foo(Integer $param1, $param2, String $param3 = hi) {
196
- file { '/tmp/foo':
197
- ensure => present
198
- }
199
- }
200
- SOURCE
201
- }
202
-
203
- it 'should parse the summary' do
204
- expect{ subject }.to output('').to_stdout_from_any_process
205
- expect(subject.size).to eq(1)
206
- summary = subject.first.tags(:summary)
207
- expect(summary.first.text).to eq('A short summary.')
208
- end
209
- end
210
-
211
- context 'when the summary has more than 140 characters' do
212
- let(:source) { <<-SOURCE
213
- # A simple foo defined type.
214
- # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!!
215
- # @param param1 First param.
216
- # @param [Boolean] param2 Second param.
217
- # @param param3 Third param.
218
- define foo(Integer $param1, $param2, String $param3 = hi) {
219
- file { '/tmp/foo':
220
- ensure => present
221
- }
222
- }
223
- SOURCE
224
- }
225
-
226
- it 'should log a warning' do
227
- expect{ subject }.to output(/\[warn\]: The length of the summary for puppet_defined_type 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process
228
- end
229
- end
230
- end
231
- end
@@ -1,315 +0,0 @@
1
- require 'spec_helper'
2
- require 'puppet-strings/yard'
3
-
4
- # Limit this spec to Puppet 4.1+ (when functions in Puppet were implemented)
5
- describe PuppetStrings::Yard::Handlers::Puppet::FunctionHandler, if: TEST_PUPPET_FUNCTIONS do
6
- subject {
7
- YARD::Parser::SourceParser.parse_string(source, :puppet)
8
- YARD::Registry.all(:puppet_function)
9
- }
10
-
11
- describe 'parsing source without a function definition' do
12
- let(:source) { 'notice hi' }
13
-
14
- it 'no functions should be in the registry' do
15
- expect(subject.empty?).to eq(true)
16
- end
17
- end
18
-
19
- describe 'parsing source with a syntax error' do
20
- let(:source) { 'function foo{' }
21
-
22
- it 'should log an error' do
23
- expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of/).to_stdout_from_any_process
24
- expect(subject.empty?).to eq(true)
25
- end
26
- end
27
-
28
- describe 'parsing a function with a missing docstring' do
29
- let(:source) { 'function foo{}' }
30
-
31
- it 'should log a warning' do
32
- expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\./).to_stdout_from_any_process
33
- end
34
- end
35
-
36
- describe 'parsing a function with a docstring' do
37
- let(:source) { <<-SOURCE
38
- # A simple foo function.
39
- # @param param1 First param.
40
- # @param param2 Second param.
41
- # @param param3 Third param.
42
- # @return [Undef] Returns nothing.
43
- function foo(Integer $param1, $param2, String $param3 = hi) {
44
- notice 'hello world'
45
- undef
46
- }
47
- SOURCE
48
- }
49
-
50
- it 'should register a function object' do
51
- expect(subject.size).to eq(1)
52
- object = subject.first
53
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
54
- expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::PUPPET))
55
- expect(object.name).to eq(:foo)
56
- expect(object.signature).to eq('foo(Integer $param1, Any $param2, String $param3 = hi)')
57
- expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']])
58
- expect(object.docstring).to eq('A simple foo function.')
59
- expect(object.docstring.tags.size).to eq(5)
60
- tags = object.docstring.tags(:param)
61
- expect(tags.size).to eq(3)
62
- expect(tags[0].name).to eq('param1')
63
- expect(tags[0].text).to eq('First param.')
64
- expect(tags[0].types).to eq(['Integer'])
65
- expect(tags[1].name).to eq('param2')
66
- expect(tags[1].text).to eq('Second param.')
67
- expect(tags[1].types).to eq(['Any'])
68
- expect(tags[2].name).to eq('param3')
69
- expect(tags[2].text).to eq('Third param.')
70
- expect(tags[2].types).to eq(['String'])
71
- tags = object.docstring.tags(:return)
72
- expect(tags.size).to eq(1)
73
- expect(tags[0].tag_name).to eq('return')
74
- expect(tags[0].text).to eq('Returns nothing.')
75
- expect(tags[0].types).to eq(['Undef'])
76
- tags = object.docstring.tags(:api)
77
- expect(tags.size).to eq(1)
78
- expect(tags[0].text).to eq('public')
79
- end
80
- end
81
-
82
- describe 'parsing a function with a missing parameter' do
83
- let(:source) { <<-SOURCE
84
- # A simple foo function.
85
- # @param param1 First param.
86
- # @param param2 Second param.
87
- # @param param3 Third param.
88
- # @param param4 missing!
89
- # @return [Undef] Returns nothing.
90
- function foo(Integer $param1, $param2, String $param3 = hi) {
91
- notice 'hello world'
92
- }
93
- SOURCE
94
- }
95
-
96
- it 'should output a warning' do
97
- expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):7\./).to_stdout_from_any_process
98
- end
99
- end
100
-
101
- describe 'parsing a function with a missing @param tag' do
102
- let(:source) { <<-SOURCE
103
- # A simple foo function.
104
- # @param param1 First param.
105
- # @param param2 Second param.
106
- # @return [Undef] Returns nothing.
107
- function foo(Integer $param1, $param2, String $param3 = hi) {
108
- notice 'hello world'
109
- }
110
- SOURCE
111
- }
112
-
113
- it 'should output a warning' do
114
- expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):5\./).to_stdout_from_any_process
115
- end
116
- end
117
-
118
- describe 'parsing a function with a typed parameter that also has a @param tag type which matches' do
119
- let(:source) { <<-SOURCE
120
- # A simple foo function.
121
- # @param [Integer] param1 First param.
122
- # @param param2 Second param.
123
- # @param param3 Third param.
124
- # @return [Undef] Returns nothing.
125
- function foo(Integer $param1, $param2, String $param3 = hi) {
126
- notice 'hello world'
127
- }
128
- SOURCE
129
- }
130
-
131
- it 'should respect the type that was documented' do
132
- expect{ subject }.to output('').to_stdout_from_any_process
133
- expect(subject.size).to eq(1)
134
- tags = subject.first.tags(:param)
135
- expect(tags.size).to eq(3)
136
- expect(tags[0].types).to eq(['Integer'])
137
- end
138
- end
139
-
140
- describe 'parsing a function with a typed parameter that also has a @param tag type which does not match' do
141
- let(:source) { <<-SOURCE
142
- # A simple foo function.
143
- # @param [Boolean] param1 First param.
144
- # @param param2 Second param.
145
- # @param param3 Third param.
146
- # @return [Undef] Returns nothing.
147
- function foo(Integer $param1, $param2, String $param3 = hi) {
148
- notice 'hello world'
149
- }
150
- SOURCE
151
- }
152
-
153
- it 'should output a warning' do
154
- expect{ subject }.to output(/\[warn\]: The type of the @param tag for parameter 'param1' does not match the parameter type specification near \(stdin\):6: ignoring in favor of parameter type information./).to_stdout_from_any_process
155
- end
156
- end
157
-
158
- describe 'parsing a function with a untyped parameter that also has a @param tag type' do
159
- let(:source) { <<-SOURCE
160
- # A simple foo function.
161
- # @param param1 First param.
162
- # @param [Boolean] param2 Second param.
163
- # @param param3 Third param.
164
- # @return [Undef] Returns nothing.
165
- function foo(Integer $param1, $param2, String $param3 = hi) {
166
- notice 'hello world'
167
- }
168
- SOURCE
169
- }
170
-
171
- it 'should respect the type that was documented' do
172
- expect{ subject }.to output('').to_stdout_from_any_process
173
- expect(subject.size).to eq(1)
174
- tags = subject.first.tags(:param)
175
- expect(tags.size).to eq(3)
176
- expect(tags[1].types).to eq(['Boolean'])
177
- end
178
- end
179
-
180
- describe 'parsing a function with a missing @return tag' do
181
- let(:source) { <<-SOURCE
182
- # A simple foo function.
183
- # @param param1 First param.
184
- # @param param2 Second param.
185
- # @param param3 Third param.
186
- function foo(Integer $param1, $param2, String $param3 = hi) {
187
- notice 'hello world'
188
- }
189
- SOURCE
190
- }
191
-
192
- it 'should output a warning' do
193
- expect{ subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):5\./).to_stdout_from_any_process
194
- end
195
- end
196
-
197
- describe 'parsing a function with a missing @return tag and return type specified in the function definition', if: TEST_FUNCTION_RETURN_TYPE do
198
- let(:source) { <<-SOURCE
199
- # A simple foo function.
200
- function foo() >> String {
201
- notice 'hello world'
202
- }
203
- SOURCE
204
- }
205
-
206
- it 'should register a function object with the correct return type' do
207
- expect{ subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):2\./).to_stdout_from_any_process
208
- expect(subject.size).to eq(1)
209
- object = subject.first
210
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
211
- tags = object.docstring.tags(:return)
212
- expect(tags.size).to eq(1)
213
- expect(tags[0].tag_name).to eq('return')
214
- expect(tags[0].text).to eq('')
215
- expect(tags[0].types).to eq(['String'])
216
- end
217
- end
218
-
219
- describe 'parsing a function with a non-conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do
220
- let(:source) { <<-SOURCE
221
- # A simple foo function
222
- # @return [String] Hi there
223
- function foo() >> String {
224
- notice 'hi there'
225
- }
226
- SOURCE
227
- }
228
-
229
- it 'should not output a warning if return types match' do
230
- expect{ subject }.not_to output(/Documented return type does not match return type in function definition/).to_stdout_from_any_process
231
- end
232
- end
233
-
234
- describe 'parsing a function with a conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do
235
- let(:source) { <<-SOURCE
236
- # A simple foo function.
237
- # @return [Integer] this is a lie.
238
- function foo() >> Struct[{'a' => Integer[1, 10]}] {
239
- notice 'hello world'
240
- }
241
- SOURCE
242
- }
243
-
244
- it 'should prefer the return type from the function definition' do
245
- expect{ subject }.to output(/\[warn\]: Documented return type does not match return type in function definition near \(stdin\):3\./).to_stdout_from_any_process
246
- expect(subject.size).to eq(1)
247
- object = subject.first
248
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
249
- tags = object.docstring.tags(:return)
250
- expect(tags.size).to eq(1)
251
- expect(tags[0].tag_name).to eq('return')
252
- expect(tags[0].text).to eq('this is a lie.')
253
- expect(tags[0].types).to eq(["Struct[{'a' => Integer[1, 10]}]"])
254
- end
255
- end
256
-
257
- describe 'parsing a function without a return tag or return type in the function definition' do
258
- let(:source) { <<-SOURCE
259
- # A simple foo function.
260
- function foo() {
261
- notice 'hello world'
262
- }
263
- SOURCE
264
- }
265
-
266
- it 'should add a return tag with a default type value of Any' do
267
- expect{ subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):2\./).to_stdout_from_any_process
268
- expect(subject.size).to eq(1)
269
- object = subject.first
270
- expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
271
- tags = object.docstring.tags(:return)
272
- expect(tags.size).to eq(1)
273
- expect(tags[0].tag_name).to eq('return')
274
- expect(tags[0].text).to eq('')
275
- expect(tags[0].types).to eq(['Any'])
276
- end
277
- end
278
-
279
- describe 'parsing a function with a summary' do
280
- context 'when the summary has fewer than 140 characters' do
281
- let(:source) { <<-SOURCE
282
- # A simple foo function.
283
- # @summary A short summary.
284
- # @return [String] foo
285
- function foo() {
286
- notice 'hello world'
287
- }
288
- SOURCE
289
- }
290
-
291
- it 'should parse the summary' do
292
- expect{ subject }.to output('').to_stdout_from_any_process
293
- expect(subject.size).to eq(1)
294
- summary = subject.first.tags(:summary)
295
- expect(summary.first.text).to eq('A short summary.')
296
- end
297
- end
298
-
299
- context 'when the summary has more than 140 characters' do
300
- let(:source) { <<-SOURCE
301
- # A simple foo function.
302
- # @summary A short summary that is WAY TOO LONG. AHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH this is not what a summary is for! It should be fewer than 140 characters!!
303
- function foo() {
304
- notice 'hello world'
305
- }
306
-
307
- SOURCE
308
- }
309
-
310
- it 'should log a warning' do
311
- expect{ subject }.to output(/\[warn\]: The length of the summary for puppet_function 'foo' exceeds the recommended limit of 140 characters./).to_stdout_from_any_process
312
- end
313
- end
314
- end
315
- end