puppet-strings 2.1.0 → 2.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +78 -4
- data/CONTRIBUTING.md +32 -2
- data/README.md +81 -17
- data/lib/puppet-strings.rb +13 -4
- data/lib/puppet-strings/describe.rb +68 -0
- data/lib/puppet-strings/json.rb +2 -38
- data/lib/puppet-strings/markdown.rb +3 -1
- data/lib/puppet-strings/markdown/base.rb +37 -16
- data/lib/puppet-strings/markdown/data_type.rb +34 -0
- data/lib/puppet-strings/markdown/data_types.rb +41 -0
- data/lib/puppet-strings/markdown/function.rb +2 -2
- data/lib/puppet-strings/markdown/resource_type.rb +19 -2
- data/lib/puppet-strings/markdown/table_of_contents.rb +1 -0
- data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +12 -4
- data/lib/puppet-strings/markdown/templates/data_type.erb +93 -0
- data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
- data/lib/puppet-strings/markdown/templates/function.erb +36 -1
- data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
- data/lib/puppet-strings/markdown/templates/resource_type.erb +32 -12
- data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
- data/lib/puppet-strings/tasks/generate.rb +10 -3
- data/lib/puppet-strings/version.rb +1 -1
- data/lib/puppet-strings/yard.rb +16 -0
- data/lib/puppet-strings/yard/code_objects.rb +2 -0
- data/lib/puppet-strings/yard/code_objects/class.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/data_type.rb +100 -0
- data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +58 -0
- data/lib/puppet-strings/yard/code_objects/defined_type.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/function.rb +4 -4
- data/lib/puppet-strings/yard/code_objects/plan.rb +2 -2
- data/lib/puppet-strings/yard/code_objects/provider.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/task.rb +1 -1
- data/lib/puppet-strings/yard/code_objects/type.rb +48 -6
- data/lib/puppet-strings/yard/handlers.rb +3 -0
- data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +24 -0
- data/lib/puppet-strings/yard/handlers/ruby/base.rb +12 -1
- data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +393 -0
- data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +2 -12
- data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +1 -9
- data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +3 -3
- data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +135 -0
- data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +56 -0
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +9 -115
- data/lib/puppet-strings/yard/parsers/json/parser.rb +4 -2
- data/lib/puppet-strings/yard/parsers/puppet/parser.rb +14 -7
- data/lib/puppet-strings/yard/parsers/puppet/statement.rb +25 -0
- data/lib/puppet-strings/yard/tags.rb +2 -0
- data/lib/puppet-strings/yard/tags/enum_tag.rb +12 -0
- data/lib/puppet-strings/yard/tags/factory.rb +16 -0
- data/lib/puppet-strings/yard/tags/overload_tag.rb +2 -2
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_data_type.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +9 -0
- data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +2 -0
- data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +18 -1
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/box_info.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/method_details_list.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/note.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/setup.rb +13 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/summary.erb +4 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type/html/todo.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/alias_of.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/box_info.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/note.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/setup.rb +17 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/summary.erb +4 -0
- data/lib/puppet-strings/yard/templates/default/puppet_data_type_alias/html/todo.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +3 -1
- data/lib/puppet-strings/yard/templates/default/tags/html/enum.erb +17 -0
- data/lib/puppet-strings/yard/templates/default/tags/setup.rb +7 -0
- data/lib/puppet-strings/yard/util.rb +48 -0
- data/lib/puppet/face/strings.rb +68 -3
- metadata +36 -45
- data/Gemfile +0 -37
- data/HISTORY.md +0 -218
- data/JSON.md +0 -802
- data/Rakefile +0 -93
- data/codecov.yml +0 -3
- data/misc/ANNOUNCEMENT_TEMPLATE.md +0 -40
- data/spec/acceptance/emit_json_options.rb +0 -71
- data/spec/acceptance/generate_markdown_spec.rb +0 -49
- data/spec/acceptance/lib/util.rb +0 -163
- data/spec/acceptance/running_strings_generate.rb +0 -54
- data/spec/fixtures/acceptance/modules/test/functions/add.pp +0 -9
- data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +0 -5
- data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +0 -2
- data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +0 -9
- data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +0 -15
- data/spec/fixtures/acceptance/modules/test/manifests/init.pp +0 -27
- data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +0 -27
- data/spec/fixtures/acceptance/modules/test/metadata.json +0 -6
- data/spec/fixtures/unit/json/output.json +0 -660
- data/spec/fixtures/unit/json/output_with_plan.json +0 -697
- data/spec/fixtures/unit/json/output_without_puppet_function.json +0 -480
- data/spec/fixtures/unit/markdown/output.md +0 -444
- data/spec/fixtures/unit/markdown/output_with_plan.md +0 -478
- data/spec/spec_helper.rb +0 -45
- data/spec/spec_helper_acceptance.rb +0 -28
- data/spec/unit/puppet-strings/json_spec.rb +0 -229
- data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
- data/spec/unit/puppet-strings/markdown_spec.rb +0 -283
- data/spec/unit/puppet-strings/yard/code_objects/task_spec.rb +0 -92
- data/spec/unit/puppet-strings/yard/handlers/json/task_handler_spec.rb +0 -124
- data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +0 -217
- data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +0 -231
- data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +0 -315
- data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +0 -729
- data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +0 -139
- data/spec/unit/puppet-strings/yard/handlers/ruby/rsapi_handler_spec.rb +0 -214
- data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -269
- data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -70
- data/spec/unit/puppet-strings/yard/parsers/json/task_statement_spec.rb +0 -56
- data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +0 -209
- data/spec/unit/puppet-strings/yard/util_spec.rb +0 -48
|
@@ -1,729 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
require 'puppet-strings/yard'
|
|
3
|
-
|
|
4
|
-
describe PuppetStrings::Yard::Handlers::Ruby::FunctionHandler do
|
|
5
|
-
subject {
|
|
6
|
-
YARD::Parser::SourceParser.parse_string(source, :ruby)
|
|
7
|
-
YARD::Registry.all(:puppet_function)
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
describe 'parsing source without a function definition' do
|
|
11
|
-
let(:source) { 'puts "hi"' }
|
|
12
|
-
|
|
13
|
-
it 'no functions should be in the registry' do
|
|
14
|
-
expect(subject.empty?).to eq(true)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe 'parsing 3.x API functions' do
|
|
19
|
-
describe 'parsing a function with a missing docstring' do
|
|
20
|
-
let(:source) { <<-SOURCE
|
|
21
|
-
Puppet::Parser::Functions.newfunction(:foo) do |*args|
|
|
22
|
-
end
|
|
23
|
-
SOURCE
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
it 'should log a warning' do
|
|
27
|
-
expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\./).to_stdout_from_any_process
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
describe 'parsing a function with a doc parameter' do
|
|
32
|
-
let(:source) { <<-SOURCE
|
|
33
|
-
Puppet::Parser::Functions.newfunction(:foo, doc: <<-DOC
|
|
34
|
-
An example 3.x function.
|
|
35
|
-
@param [String] first The first parameter.
|
|
36
|
-
@param second The second parameter.
|
|
37
|
-
@return [Undef] Returns nothing.
|
|
38
|
-
DOC
|
|
39
|
-
) do |*args|
|
|
40
|
-
end
|
|
41
|
-
SOURCE
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
it 'should register a function object' do
|
|
45
|
-
expect(subject.size).to eq(1)
|
|
46
|
-
object = subject.first
|
|
47
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
48
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_3X))
|
|
49
|
-
expect(object.name).to eq(:foo)
|
|
50
|
-
expect(object.signature).to eq('foo(String $first, Any $second)')
|
|
51
|
-
expect(object.parameters).to eq([['first', nil], ['second', nil]])
|
|
52
|
-
expect(object.docstring).to eq('An example 3.x function.')
|
|
53
|
-
expect(object.docstring.tags.size).to eq(4)
|
|
54
|
-
tags = object.docstring.tags(:param)
|
|
55
|
-
expect(tags.size).to eq(2)
|
|
56
|
-
expect(tags[0].name).to eq('first')
|
|
57
|
-
expect(tags[0].text).to eq('The first parameter.')
|
|
58
|
-
expect(tags[0].types).to eq(['String'])
|
|
59
|
-
expect(tags[1].name).to eq('second')
|
|
60
|
-
expect(tags[1].text).to eq('The second parameter.')
|
|
61
|
-
expect(tags[1].types).to eq(['Any'])
|
|
62
|
-
tags = object.docstring.tags(:return)
|
|
63
|
-
expect(tags.size).to eq(1)
|
|
64
|
-
expect(tags[0].name).to be_nil
|
|
65
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
66
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
67
|
-
tags = object.docstring.tags(:api)
|
|
68
|
-
expect(tags.size).to eq(1)
|
|
69
|
-
expect(tags[0].text).to eq('public')
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
describe 'parsing a function with a doc parameter which has a newline between the namespace and the newfunction call' do
|
|
74
|
-
let(:source) { <<-SOURCE
|
|
75
|
-
module Puppet::Parser::Functions
|
|
76
|
-
newfunction(:foo, doc: <<-DOC
|
|
77
|
-
An example 3.x function.
|
|
78
|
-
@param [String] first The first parameter.
|
|
79
|
-
@param second The second parameter.
|
|
80
|
-
@return [Undef] Returns nothing.
|
|
81
|
-
DOC
|
|
82
|
-
) do |*args|
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
SOURCE
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
it 'should register a function object' do
|
|
89
|
-
expect(subject.size).to eq(1)
|
|
90
|
-
object = subject.first
|
|
91
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
92
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_3X))
|
|
93
|
-
expect(object.name).to eq(:foo)
|
|
94
|
-
expect(object.signature).to eq('foo(String $first, Any $second)')
|
|
95
|
-
expect(object.parameters).to eq([['first', nil], ['second', nil]])
|
|
96
|
-
expect(object.docstring).to eq('An example 3.x function.')
|
|
97
|
-
expect(object.docstring.tags.size).to eq(4)
|
|
98
|
-
tags = object.docstring.tags(:param)
|
|
99
|
-
expect(tags.size).to eq(2)
|
|
100
|
-
expect(tags[0].name).to eq('first')
|
|
101
|
-
expect(tags[0].text).to eq('The first parameter.')
|
|
102
|
-
expect(tags[0].types).to eq(['String'])
|
|
103
|
-
expect(tags[1].name).to eq('second')
|
|
104
|
-
expect(tags[1].text).to eq('The second parameter.')
|
|
105
|
-
expect(tags[1].types).to eq(['Any'])
|
|
106
|
-
tags = object.docstring.tags(:return)
|
|
107
|
-
expect(tags.size).to eq(1)
|
|
108
|
-
expect(tags[0].name).to be_nil
|
|
109
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
110
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
111
|
-
tags = object.docstring.tags(:api)
|
|
112
|
-
expect(tags.size).to eq(1)
|
|
113
|
-
expect(tags[0].text).to eq('public')
|
|
114
|
-
end
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
describe 'parsing a function with a missing @return tag' do
|
|
118
|
-
let(:source) { <<-SOURCE
|
|
119
|
-
Puppet::Parser::Functions.newfunction(:foo, doc: <<-DOC) do |*args|
|
|
120
|
-
An example 3.x function.
|
|
121
|
-
@param [String] first The first parameter.
|
|
122
|
-
@param second The second parameter.
|
|
123
|
-
DOC
|
|
124
|
-
end
|
|
125
|
-
SOURCE
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
it 'should log a warning' do
|
|
129
|
-
expect{ subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):1/).to_stdout_from_any_process
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
describe 'parsing 4.x API functions' do
|
|
135
|
-
describe 'parsing a function with a missing docstring' do
|
|
136
|
-
let(:source) { <<-SOURCE
|
|
137
|
-
Puppet::Functions.create_function(:foo) do
|
|
138
|
-
end
|
|
139
|
-
SOURCE
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
it 'should log a warning' do
|
|
143
|
-
expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet function 'foo' at \(stdin\):1\./).to_stdout_from_any_process
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
describe 'parsing a function with a simple docstring' do
|
|
148
|
-
let(:source) { <<-SOURCE
|
|
149
|
-
# An example 4.x function.
|
|
150
|
-
Puppet::Functions.create_function(:foo) do
|
|
151
|
-
end
|
|
152
|
-
SOURCE
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
it 'should register a function object' do
|
|
156
|
-
expect(subject.size).to eq(1)
|
|
157
|
-
object = subject.first
|
|
158
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
159
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
|
|
160
|
-
expect(object.name).to eq(:foo)
|
|
161
|
-
expect(object.signature).to eq('foo()')
|
|
162
|
-
expect(object.parameters).to eq([])
|
|
163
|
-
expect(object.docstring).to eq('An example 4.x function.')
|
|
164
|
-
expect(object.docstring.tags.size).to eq(1)
|
|
165
|
-
tags = object.docstring.tags(:api)
|
|
166
|
-
expect(tags.size).to eq(1)
|
|
167
|
-
expect(tags[0].text).to eq('public')
|
|
168
|
-
end
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
describe 'parsing a function without any dispatches' do
|
|
172
|
-
let(:source) { <<-SOURCE
|
|
173
|
-
# An example 4.x function.
|
|
174
|
-
Puppet::Functions.create_function(:foo) do
|
|
175
|
-
# @param [Integer] param1 The first parameter.
|
|
176
|
-
# @param param2 The second parameter.
|
|
177
|
-
# @param [String] param3 The third parameter.
|
|
178
|
-
# @return [Undef] Returns nothing.
|
|
179
|
-
def foo(param1, param2, param3 = nil)
|
|
180
|
-
end
|
|
181
|
-
end
|
|
182
|
-
SOURCE
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
it 'should register a function object' do
|
|
186
|
-
expect(subject.size).to eq(1)
|
|
187
|
-
object = subject.first
|
|
188
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
189
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
|
|
190
|
-
expect(object.name).to eq(:foo)
|
|
191
|
-
expect(object.signature).to eq('foo(Integer $param1, Any $param2, Optional[String] $param3 = undef)')
|
|
192
|
-
expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'undef']])
|
|
193
|
-
expect(object.docstring).to eq('An example 4.x function.')
|
|
194
|
-
expect(object.docstring.tags.size).to eq(5)
|
|
195
|
-
tags = object.docstring.tags(:param)
|
|
196
|
-
expect(tags.size).to eq(3)
|
|
197
|
-
expect(tags[0].name).to eq('param1')
|
|
198
|
-
expect(tags[0].text).to eq('The first parameter.')
|
|
199
|
-
expect(tags[0].types).to eq(['Integer'])
|
|
200
|
-
expect(tags[1].name).to eq('param2')
|
|
201
|
-
expect(tags[1].text).to eq('The second parameter.')
|
|
202
|
-
expect(tags[1].types).to eq(['Any'])
|
|
203
|
-
expect(tags[2].name).to eq('param3')
|
|
204
|
-
expect(tags[2].text).to eq('The third parameter.')
|
|
205
|
-
expect(tags[2].types).to eq(['Optional[String]'])
|
|
206
|
-
tags = object.docstring.tags(:return)
|
|
207
|
-
expect(tags.size).to eq(1)
|
|
208
|
-
expect(tags[0].name).to be_nil
|
|
209
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
210
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
211
|
-
tags = object.docstring.tags(:api)
|
|
212
|
-
expect(tags.size).to eq(1)
|
|
213
|
-
expect(tags[0].text).to eq('public')
|
|
214
|
-
end
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
describe 'parsing a function with a single dispatch' do
|
|
218
|
-
let(:source) { <<-SOURCE
|
|
219
|
-
# An example 4.x function.
|
|
220
|
-
Puppet::Functions.create_function(:foo) do
|
|
221
|
-
# @param param1 The first parameter.
|
|
222
|
-
# @param param2 The second parameter.
|
|
223
|
-
# @param param3 The third parameter.
|
|
224
|
-
# @return [Undef] Returns nothing.
|
|
225
|
-
dispatch :foo do
|
|
226
|
-
param 'Integer', :param1
|
|
227
|
-
param 'Any', :param2
|
|
228
|
-
optional_param 'Array[String]', :param3
|
|
229
|
-
end
|
|
230
|
-
|
|
231
|
-
def foo(param1, param2, param3 = nil)
|
|
232
|
-
end
|
|
233
|
-
end
|
|
234
|
-
SOURCE
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
it 'should register a function object without any overload tags' do
|
|
238
|
-
expect(subject.size).to eq(1)
|
|
239
|
-
object = subject.first
|
|
240
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
241
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
|
|
242
|
-
expect(object.name).to eq(:foo)
|
|
243
|
-
expect(object.signature).to eq('foo(Integer $param1, Any $param2, Optional[Array[String]] $param3)')
|
|
244
|
-
expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', nil]])
|
|
245
|
-
expect(object.docstring).to eq('An example 4.x function.')
|
|
246
|
-
expect(object.docstring.tags(:overload).empty?).to be_truthy
|
|
247
|
-
expect(object.docstring.tags.size).to eq(5)
|
|
248
|
-
tags = object.docstring.tags(:param)
|
|
249
|
-
expect(tags.size).to eq(3)
|
|
250
|
-
expect(tags[0].name).to eq('param1')
|
|
251
|
-
expect(tags[0].text).to eq('The first parameter.')
|
|
252
|
-
expect(tags[0].types).to eq(['Integer'])
|
|
253
|
-
expect(tags[1].name).to eq('param2')
|
|
254
|
-
expect(tags[1].text).to eq('The second parameter.')
|
|
255
|
-
expect(tags[1].types).to eq(['Any'])
|
|
256
|
-
expect(tags[2].name).to eq('param3')
|
|
257
|
-
expect(tags[2].text).to eq('The third parameter.')
|
|
258
|
-
expect(tags[2].types).to eq(['Optional[Array[String]]'])
|
|
259
|
-
tags = object.docstring.tags(:return)
|
|
260
|
-
expect(tags.size).to eq(1)
|
|
261
|
-
expect(tags[0].name).to be_nil
|
|
262
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
263
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
264
|
-
tags = object.docstring.tags(:api)
|
|
265
|
-
expect(tags.size).to eq(1)
|
|
266
|
-
expect(tags[0].text).to eq('public')
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
describe 'parsing a function using only return_type' do
|
|
271
|
-
let(:source) { <<-SOURCE
|
|
272
|
-
# An example 4.x function.
|
|
273
|
-
Puppet::Functions.create_function(:foo) do
|
|
274
|
-
# @param param1 The first parameter.
|
|
275
|
-
# @param param2 The second parameter.
|
|
276
|
-
# @param param3 The third parameter.
|
|
277
|
-
dispatch :foo do
|
|
278
|
-
param 'Integer', :param1
|
|
279
|
-
param 'Any', :param2
|
|
280
|
-
optional_param 'Array[String]', :param3
|
|
281
|
-
return_type 'String'
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
def foo(param1, param2, param3 = nil)
|
|
285
|
-
"Bar"
|
|
286
|
-
end
|
|
287
|
-
end
|
|
288
|
-
SOURCE
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
it 'does not throw an error with no @return' do
|
|
292
|
-
expect { subject }.not_to raise_error NoMethodError
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
it 'contains a return data type' do
|
|
296
|
-
tags = subject.first.docstring.tags(:return)
|
|
297
|
-
expect(tags.size).to eq(1)
|
|
298
|
-
expect(tags[0].name).to be_nil
|
|
299
|
-
expect(tags[0].types).to eq(['String'])
|
|
300
|
-
end
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
describe 'parsing a function with various dispatch parameters.' do
|
|
304
|
-
let(:source) { <<-SOURCE
|
|
305
|
-
# An example 4.x function.
|
|
306
|
-
Puppet::Functions.create_function(:foo) do
|
|
307
|
-
# @param param1 The first parameter.
|
|
308
|
-
# @param param2 The second parameter.
|
|
309
|
-
# @param param3 The third parameter.
|
|
310
|
-
# @param param4 The fourth parameter.
|
|
311
|
-
# @return [Undef] Returns nothing.
|
|
312
|
-
dispatch :foo do
|
|
313
|
-
param 'String', :param1
|
|
314
|
-
required_param 'Integer', :param2
|
|
315
|
-
optional_param 'Array', :param3
|
|
316
|
-
repeated_param 'String', :param4
|
|
317
|
-
end
|
|
318
|
-
end
|
|
319
|
-
SOURCE
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
it 'should register a function object with the expected parameters' do
|
|
323
|
-
expect(subject.size).to eq(1)
|
|
324
|
-
object = subject.first
|
|
325
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
326
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
|
|
327
|
-
expect(object.name).to eq(:foo)
|
|
328
|
-
expect(object.signature).to eq('foo(String $param1, Integer $param2, Optional[Array] $param3, String *$param4)')
|
|
329
|
-
expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', nil], ['*param4', nil]])
|
|
330
|
-
expect(object.docstring).to eq('An example 4.x function.')
|
|
331
|
-
expect(object.docstring.tags(:overload).empty?).to be_truthy
|
|
332
|
-
expect(object.docstring.tags.size).to eq(6)
|
|
333
|
-
tags = object.docstring.tags(:param)
|
|
334
|
-
expect(tags.size).to eq(4)
|
|
335
|
-
expect(tags[0].name).to eq('param1')
|
|
336
|
-
expect(tags[0].text).to eq('The first parameter.')
|
|
337
|
-
expect(tags[0].types).to eq(['String'])
|
|
338
|
-
expect(tags[1].name).to eq('param2')
|
|
339
|
-
expect(tags[1].text).to eq('The second parameter.')
|
|
340
|
-
expect(tags[1].types).to eq(['Integer'])
|
|
341
|
-
expect(tags[2].name).to eq('param3')
|
|
342
|
-
expect(tags[2].text).to eq('The third parameter.')
|
|
343
|
-
expect(tags[2].types).to eq(['Optional[Array]'])
|
|
344
|
-
expect(tags[3].name).to eq('*param4')
|
|
345
|
-
expect(tags[3].text).to eq('The fourth parameter.')
|
|
346
|
-
expect(tags[3].types).to eq(['String'])
|
|
347
|
-
tags = object.docstring.tags(:return)
|
|
348
|
-
expect(tags.size).to eq(1)
|
|
349
|
-
expect(tags[0].name).to be_nil
|
|
350
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
351
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
352
|
-
tags = object.docstring.tags(:api)
|
|
353
|
-
expect(tags.size).to eq(1)
|
|
354
|
-
expect(tags[0].text).to eq('public')
|
|
355
|
-
end
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
describe 'parsing a function with an optional repeated param.' do
|
|
359
|
-
let(:source) { <<-SOURCE
|
|
360
|
-
# An example 4.x function.
|
|
361
|
-
Puppet::Functions.create_function(:foo) do
|
|
362
|
-
# @param param The first parameter.
|
|
363
|
-
# @return [Undef] Returns nothing.
|
|
364
|
-
dispatch :foo do
|
|
365
|
-
optional_repeated_param 'String', :param
|
|
366
|
-
end
|
|
367
|
-
end
|
|
368
|
-
SOURCE
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
it 'should register a function object with the expected parameters' do
|
|
372
|
-
expect(subject.size).to eq(1)
|
|
373
|
-
object = subject.first
|
|
374
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
375
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
|
|
376
|
-
expect(object.name).to eq(:foo)
|
|
377
|
-
expect(object.signature).to eq('foo(Optional[String] *$param)')
|
|
378
|
-
expect(object.parameters).to eq([['*param', nil]])
|
|
379
|
-
expect(object.docstring).to eq('An example 4.x function.')
|
|
380
|
-
expect(object.docstring.tags(:overload).empty?).to be_truthy
|
|
381
|
-
expect(object.docstring.tags.size).to eq(3)
|
|
382
|
-
tags = object.docstring.tags(:param)
|
|
383
|
-
expect(tags.size).to eq(1)
|
|
384
|
-
expect(tags[0].name).to eq('*param')
|
|
385
|
-
expect(tags[0].text).to eq('The first parameter.')
|
|
386
|
-
expect(tags[0].types).to eq(['Optional[String]'])
|
|
387
|
-
tags = object.docstring.tags(:return)
|
|
388
|
-
expect(tags.size).to eq(1)
|
|
389
|
-
expect(tags[0].name).to be_nil
|
|
390
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
391
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
392
|
-
tags = object.docstring.tags(:api)
|
|
393
|
-
expect(tags.size).to eq(1)
|
|
394
|
-
expect(tags[0].text).to eq('public')
|
|
395
|
-
end
|
|
396
|
-
end
|
|
397
|
-
|
|
398
|
-
describe 'parsing a function with a block param with one parameter' do
|
|
399
|
-
let(:source) { <<-SOURCE
|
|
400
|
-
# An example 4.x function.
|
|
401
|
-
Puppet::Functions.create_function(:foo) do
|
|
402
|
-
# @param a_block The block parameter.
|
|
403
|
-
# @return [Undef] Returns nothing.
|
|
404
|
-
dispatch :foo do
|
|
405
|
-
block_param :a_block
|
|
406
|
-
end
|
|
407
|
-
end
|
|
408
|
-
SOURCE
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
it 'should register a function object with the expected parameters' do
|
|
412
|
-
expect(subject.size).to eq(1)
|
|
413
|
-
object = subject.first
|
|
414
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
415
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
|
|
416
|
-
expect(object.name).to eq(:foo)
|
|
417
|
-
expect(object.signature).to eq('foo(Callable &$a_block)')
|
|
418
|
-
expect(object.parameters).to eq([['&a_block', nil]])
|
|
419
|
-
expect(object.docstring).to eq('An example 4.x function.')
|
|
420
|
-
expect(object.docstring.tags(:overload).empty?).to be_truthy
|
|
421
|
-
expect(object.docstring.tags.size).to eq(3)
|
|
422
|
-
tags = object.docstring.tags(:param)
|
|
423
|
-
expect(tags.size).to eq(1)
|
|
424
|
-
expect(tags[0].name).to eq('&a_block')
|
|
425
|
-
expect(tags[0].text).to eq('The block parameter.')
|
|
426
|
-
expect(tags[0].types).to eq(['Callable'])
|
|
427
|
-
tags = object.docstring.tags(:return)
|
|
428
|
-
expect(tags.size).to eq(1)
|
|
429
|
-
expect(tags[0].name).to be_nil
|
|
430
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
431
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
432
|
-
tags = object.docstring.tags(:api)
|
|
433
|
-
expect(tags.size).to eq(1)
|
|
434
|
-
expect(tags[0].text).to eq('public')
|
|
435
|
-
end
|
|
436
|
-
end
|
|
437
|
-
|
|
438
|
-
describe 'parsing a function with a block param with two parameter' do
|
|
439
|
-
let(:source) { <<-SOURCE
|
|
440
|
-
# An example 4.x function.
|
|
441
|
-
Puppet::Functions.create_function(:foo) do
|
|
442
|
-
# @param a_block The block parameter.
|
|
443
|
-
# @return [Undef] Returns nothing.
|
|
444
|
-
dispatch :foo do
|
|
445
|
-
optional_block_param 'Callable[String]', :a_block
|
|
446
|
-
end
|
|
447
|
-
end
|
|
448
|
-
SOURCE
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
it 'should register a function object with the expected parameters' do
|
|
452
|
-
expect(subject.size).to eq(1)
|
|
453
|
-
object = subject.first
|
|
454
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
455
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
|
|
456
|
-
expect(object.name).to eq(:foo)
|
|
457
|
-
expect(object.signature).to eq('foo(Optional[Callable[String]] &$a_block)')
|
|
458
|
-
expect(object.parameters).to eq([['&a_block', nil]])
|
|
459
|
-
expect(object.docstring).to eq('An example 4.x function.')
|
|
460
|
-
expect(object.docstring.tags(:overload).empty?).to be_truthy
|
|
461
|
-
expect(object.docstring.tags.size).to eq(3)
|
|
462
|
-
tags = object.docstring.tags(:param)
|
|
463
|
-
expect(tags.size).to eq(1)
|
|
464
|
-
expect(tags[0].name).to eq('&a_block')
|
|
465
|
-
expect(tags[0].text).to eq('The block parameter.')
|
|
466
|
-
expect(tags[0].types).to eq(['Optional[Callable[String]]'])
|
|
467
|
-
tags = object.docstring.tags(:return)
|
|
468
|
-
expect(tags.size).to eq(1)
|
|
469
|
-
expect(tags[0].name).to be_nil
|
|
470
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
471
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
472
|
-
tags = object.docstring.tags(:api)
|
|
473
|
-
expect(tags.size).to eq(1)
|
|
474
|
-
expect(tags[0].text).to eq('public')
|
|
475
|
-
end
|
|
476
|
-
end
|
|
477
|
-
end
|
|
478
|
-
|
|
479
|
-
describe 'parsing a function with a multiple dispatches' do
|
|
480
|
-
let(:source) { <<-SOURCE
|
|
481
|
-
# An example 4.x function.
|
|
482
|
-
Puppet::Functions.create_function(:foo) do
|
|
483
|
-
# The first overload.
|
|
484
|
-
# @param param1 The first parameter.
|
|
485
|
-
# @param param2 The second parameter.
|
|
486
|
-
# @param param3 The third parameter.
|
|
487
|
-
# @return [Undef] Returns nothing.
|
|
488
|
-
dispatch :foo do
|
|
489
|
-
param 'Integer', :param1
|
|
490
|
-
param 'Any', :param2
|
|
491
|
-
optional_param 'Array[String]', :param3
|
|
492
|
-
end
|
|
493
|
-
|
|
494
|
-
# The second overload.
|
|
495
|
-
# @param param The first parameter.
|
|
496
|
-
# @param block The block parameter.
|
|
497
|
-
# @return [String] Returns a string.
|
|
498
|
-
dispatch :other do
|
|
499
|
-
param 'Boolean', :param
|
|
500
|
-
block_param
|
|
501
|
-
end
|
|
502
|
-
|
|
503
|
-
def foo(param1, param2, param3 = nil)
|
|
504
|
-
end
|
|
505
|
-
|
|
506
|
-
def other(b)
|
|
507
|
-
'lol'
|
|
508
|
-
end
|
|
509
|
-
end
|
|
510
|
-
SOURCE
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
it 'should register a function object with overload tags' do
|
|
514
|
-
expect(subject.size).to eq(1)
|
|
515
|
-
object = subject.first
|
|
516
|
-
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
|
|
517
|
-
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Functions.instance(PuppetStrings::Yard::CodeObjects::Function::RUBY_4X))
|
|
518
|
-
expect(object.name).to eq(:foo)
|
|
519
|
-
expect(object.signature).to eq('')
|
|
520
|
-
expect(object.parameters).to eq([])
|
|
521
|
-
expect(object.docstring).to eq('An example 4.x function.')
|
|
522
|
-
expect(object.docstring.tags(:param).empty?).to be_truthy
|
|
523
|
-
expect(object.docstring.tags(:return).empty?).to be_truthy
|
|
524
|
-
expect(object.docstring.tags.size).to eq(3)
|
|
525
|
-
overloads = object.docstring.tags(:overload)
|
|
526
|
-
expect(overloads.size).to eq(2)
|
|
527
|
-
expect(overloads[0]).to be_a(PuppetStrings::Yard::Tags::OverloadTag)
|
|
528
|
-
expect(overloads[0].docstring).to eq('The first overload.')
|
|
529
|
-
expect(overloads[0].signature).to eq('foo(Integer $param1, Any $param2, Optional[Array[String]] $param3)')
|
|
530
|
-
expect(overloads[0].tags.size).to eq(4)
|
|
531
|
-
tags = overloads[0].tags(:param)
|
|
532
|
-
expect(tags.size).to eq(3)
|
|
533
|
-
expect(tags[0].name).to eq('param1')
|
|
534
|
-
expect(tags[0].text).to eq('The first parameter.')
|
|
535
|
-
expect(tags[0].types).to eq(['Integer'])
|
|
536
|
-
expect(tags[1].name).to eq('param2')
|
|
537
|
-
expect(tags[1].text).to eq('The second parameter.')
|
|
538
|
-
expect(tags[1].types).to eq(['Any'])
|
|
539
|
-
expect(tags[2].name).to eq('param3')
|
|
540
|
-
expect(tags[2].text).to eq('The third parameter.')
|
|
541
|
-
expect(tags[2].types).to eq(['Optional[Array[String]]'])
|
|
542
|
-
tags = overloads[0].tags(:return)
|
|
543
|
-
expect(tags.size).to eq(1)
|
|
544
|
-
expect(tags[0].name).to be_nil
|
|
545
|
-
expect(tags[0].text).to eq('Returns nothing.')
|
|
546
|
-
expect(tags[0].types).to eq(['Undef'])
|
|
547
|
-
expect(overloads[1]).to be_a(PuppetStrings::Yard::Tags::OverloadTag)
|
|
548
|
-
expect(overloads[1].docstring).to eq('The second overload.')
|
|
549
|
-
expect(overloads[1].signature).to eq('foo(Boolean $param, Callable &$block)')
|
|
550
|
-
expect(overloads[1].tags.size).to eq(3)
|
|
551
|
-
tags = overloads[1].tags(:param)
|
|
552
|
-
expect(tags.size).to eq(2)
|
|
553
|
-
expect(tags[0].name).to eq('param')
|
|
554
|
-
expect(tags[0].text).to eq('The first parameter.')
|
|
555
|
-
expect(tags[0].types).to eq(['Boolean'])
|
|
556
|
-
expect(tags[1].name).to eq('&block')
|
|
557
|
-
expect(tags[1].text).to eq('The block parameter.')
|
|
558
|
-
expect(tags[1].types).to eq(['Callable'])
|
|
559
|
-
tags = overloads[1].tags(:return)
|
|
560
|
-
expect(tags.size).to eq(1)
|
|
561
|
-
expect(tags[0].name).to be_nil
|
|
562
|
-
expect(tags[0].text).to eq('Returns a string.')
|
|
563
|
-
expect(tags[0].types).to eq(['String'])
|
|
564
|
-
tags = object.docstring.tags(:api)
|
|
565
|
-
expect(tags.size).to eq(1)
|
|
566
|
-
expect(tags[0].text).to eq('public')
|
|
567
|
-
end
|
|
568
|
-
end
|
|
569
|
-
|
|
570
|
-
describe 'parsing a function with a missing parameter' do
|
|
571
|
-
let(:source) { <<-SOURCE
|
|
572
|
-
# An example 4.x function.
|
|
573
|
-
Puppet::Functions.create_function(:foo) do
|
|
574
|
-
# @param missing A missing parameter.
|
|
575
|
-
# @return [Undef] Returns nothing.
|
|
576
|
-
dispatch :foo do
|
|
577
|
-
end
|
|
578
|
-
end
|
|
579
|
-
SOURCE
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
it 'should output a warning' do
|
|
583
|
-
expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'missing' has no matching parameter at \(stdin\):5/).to_stdout_from_any_process
|
|
584
|
-
end
|
|
585
|
-
end
|
|
586
|
-
|
|
587
|
-
describe 'parsing a function with a missing @param tag' do
|
|
588
|
-
let(:source) { <<-SOURCE
|
|
589
|
-
# An example 4.x function.
|
|
590
|
-
Puppet::Functions.create_function(:foo) do
|
|
591
|
-
# @return [Undef] Returns nothing.
|
|
592
|
-
dispatch :foo do
|
|
593
|
-
param 'String', :param1
|
|
594
|
-
end
|
|
595
|
-
end
|
|
596
|
-
SOURCE
|
|
597
|
-
}
|
|
598
|
-
|
|
599
|
-
it 'should output a warning' do
|
|
600
|
-
expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param1' near \(stdin\):5/).to_stdout_from_any_process
|
|
601
|
-
end
|
|
602
|
-
end
|
|
603
|
-
|
|
604
|
-
describe 'parsing a function with a typed @param tag' do
|
|
605
|
-
let(:source) { <<-SOURCE
|
|
606
|
-
# An example 4.x function.
|
|
607
|
-
Puppet::Functions.create_function(:foo) do
|
|
608
|
-
# @param [Integer] param1 The first parameter.
|
|
609
|
-
# @return [Undef] Returns nothing.
|
|
610
|
-
dispatch :foo do
|
|
611
|
-
param 'String', :param1
|
|
612
|
-
end
|
|
613
|
-
end
|
|
614
|
-
SOURCE
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
it 'should output a warning' do
|
|
618
|
-
expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param1' should not contain a type specification near \(stdin\):6: ignoring in favor of dispatch type information\./).to_stdout_from_any_process
|
|
619
|
-
end
|
|
620
|
-
end
|
|
621
|
-
|
|
622
|
-
describe 'parsing a function with a typed @param tag' do
|
|
623
|
-
let(:source) { <<-SOURCE
|
|
624
|
-
# An example 4.x function.
|
|
625
|
-
Puppet::Functions.create_function(:foo) do
|
|
626
|
-
# @param param1 The first parameter.
|
|
627
|
-
dispatch :foo do
|
|
628
|
-
param 'String', :param1
|
|
629
|
-
end
|
|
630
|
-
end
|
|
631
|
-
SOURCE
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
it 'should output a warning' do
|
|
635
|
-
expect{ subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):4/).to_stdout_from_any_process
|
|
636
|
-
end
|
|
637
|
-
end
|
|
638
|
-
|
|
639
|
-
describe 'parsing a function with a root @param tag' do
|
|
640
|
-
let(:source) { <<-SOURCE
|
|
641
|
-
# An example 4.x function.
|
|
642
|
-
# @param param Nope.
|
|
643
|
-
Puppet::Functions.create_function(:foo) do
|
|
644
|
-
# @return [Undef]
|
|
645
|
-
dispatch :foo do
|
|
646
|
-
end
|
|
647
|
-
end
|
|
648
|
-
SOURCE
|
|
649
|
-
}
|
|
650
|
-
|
|
651
|
-
it 'should output a warning' do
|
|
652
|
-
expect{ subject }.to output(/\[warn\]: The docstring for Puppet 4.x function 'foo' contains @param tags near \(stdin\):3: parameter documentation should be made on the dispatch call\./).to_stdout_from_any_process
|
|
653
|
-
end
|
|
654
|
-
end
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
describe 'parsing a function with a root @overload tag' do
|
|
658
|
-
let(:source) { <<-SOURCE
|
|
659
|
-
# An example 4.x function.
|
|
660
|
-
# @overload foo
|
|
661
|
-
Puppet::Functions.create_function(:foo) do
|
|
662
|
-
# @return [Undef]
|
|
663
|
-
dispatch :foo do
|
|
664
|
-
end
|
|
665
|
-
end
|
|
666
|
-
SOURCE
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
it 'should output a warning' do
|
|
670
|
-
expect{ subject }.to output(/\[warn\]: The docstring for Puppet 4.x function 'foo' contains @overload tags near \(stdin\):3: overload tags are automatically generated from the dispatch calls\./).to_stdout_from_any_process
|
|
671
|
-
end
|
|
672
|
-
end
|
|
673
|
-
|
|
674
|
-
describe 'parsing a function with a root @return tag' do
|
|
675
|
-
let(:source) { <<-SOURCE
|
|
676
|
-
# An example 4.x function.
|
|
677
|
-
# @return [Undef] foo
|
|
678
|
-
Puppet::Functions.create_function(:foo) do
|
|
679
|
-
# @return [Undef]
|
|
680
|
-
dispatch :foo do
|
|
681
|
-
end
|
|
682
|
-
end
|
|
683
|
-
SOURCE
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
it 'should output a warning' do
|
|
687
|
-
expect{ subject }.to output(/\[warn\]: The docstring for Puppet 4.x function 'foo' contains @return tags near \(stdin\):3: return value documentation should be made on the dispatch call\./).to_stdout_from_any_process
|
|
688
|
-
end
|
|
689
|
-
end
|
|
690
|
-
|
|
691
|
-
describe 'parsing a function with a summary' do
|
|
692
|
-
context 'when the summary has fewer than 140 characters' do
|
|
693
|
-
let(:source) { <<-SOURCE
|
|
694
|
-
# An example 4.x function.
|
|
695
|
-
# @summary A short summary.
|
|
696
|
-
Puppet::Functions.create_function(:foo) do
|
|
697
|
-
# @return [Undef]
|
|
698
|
-
dispatch :foo do
|
|
699
|
-
end
|
|
700
|
-
end
|
|
701
|
-
SOURCE
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
it 'should parse the summary' do
|
|
705
|
-
expect{ subject }.to output('').to_stdout_from_any_process
|
|
706
|
-
expect(subject.size).to eq(1)
|
|
707
|
-
summary = subject.first.tags(:summary)
|
|
708
|
-
expect(summary.first.text).to eq('A short summary.')
|
|
709
|
-
end
|
|
710
|
-
end
|
|
711
|
-
|
|
712
|
-
context 'when the summary has more than 140 characters' do
|
|
713
|
-
let(:source) { <<-SOURCE
|
|
714
|
-
# An example 4.x function.
|
|
715
|
-
# @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!!
|
|
716
|
-
Puppet::Functions.create_function(:foo) do
|
|
717
|
-
# @return [Undef]
|
|
718
|
-
dispatch :foo do
|
|
719
|
-
end
|
|
720
|
-
end
|
|
721
|
-
SOURCE
|
|
722
|
-
}
|
|
723
|
-
|
|
724
|
-
it 'should log a warning' do
|
|
725
|
-
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
|
|
726
|
-
end
|
|
727
|
-
end
|
|
728
|
-
end
|
|
729
|
-
end
|