puppet-strings 2.2.0 → 2.6.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 +5 -5
- data/CHANGELOG.md +87 -1
- data/CONTRIBUTING.md +32 -2
- data/README.md +81 -17
- data/lib/puppet-strings.rb +5 -3
- data/lib/puppet-strings/describe.rb +2 -0
- data/lib/puppet-strings/json.rb +4 -0
- data/lib/puppet-strings/markdown.rb +13 -9
- data/lib/puppet-strings/markdown/base.rb +30 -3
- data/lib/puppet-strings/markdown/data_type.rb +36 -0
- data/lib/puppet-strings/markdown/data_types.rb +43 -0
- data/lib/puppet-strings/markdown/defined_type.rb +2 -0
- data/lib/puppet-strings/markdown/defined_types.rb +3 -1
- data/lib/puppet-strings/markdown/function.rb +9 -7
- data/lib/puppet-strings/markdown/functions.rb +3 -1
- data/lib/puppet-strings/markdown/puppet_class.rb +2 -0
- data/lib/puppet-strings/markdown/puppet_classes.rb +3 -1
- data/lib/puppet-strings/markdown/puppet_plan.rb +2 -0
- data/lib/puppet-strings/markdown/puppet_plans.rb +3 -1
- data/lib/puppet-strings/markdown/puppet_task.rb +2 -0
- data/lib/puppet-strings/markdown/puppet_tasks.rb +3 -1
- data/lib/puppet-strings/markdown/resource_type.rb +21 -2
- data/lib/puppet-strings/markdown/resource_types.rb +3 -1
- data/lib/puppet-strings/markdown/table_of_contents.rb +4 -1
- data/lib/puppet-strings/markdown/templates/classes_and_defines.erb +18 -6
- data/lib/puppet-strings/markdown/templates/data_type.erb +101 -0
- data/lib/puppet-strings/markdown/templates/data_type_function.erb +67 -0
- data/lib/puppet-strings/markdown/templates/function.erb +10 -1
- data/lib/puppet-strings/markdown/templates/puppet_task.erb +1 -1
- data/lib/puppet-strings/markdown/templates/resource_type.erb +35 -13
- data/lib/puppet-strings/markdown/templates/table_of_contents.erb +6 -6
- data/lib/puppet-strings/monkey_patches/display_object_command.rb +2 -0
- data/lib/puppet-strings/tasks.rb +2 -0
- data/lib/puppet-strings/tasks/generate.rb +5 -2
- data/lib/puppet-strings/tasks/gh_pages.rb +3 -0
- data/lib/puppet-strings/version.rb +3 -1
- data/lib/puppet-strings/yard.rb +19 -0
- data/lib/puppet-strings/yard/code_objects.rb +4 -0
- data/lib/puppet-strings/yard/code_objects/base.rb +2 -0
- data/lib/puppet-strings/yard/code_objects/class.rb +5 -3
- data/lib/puppet-strings/yard/code_objects/data_type.rb +102 -0
- data/lib/puppet-strings/yard/code_objects/data_type_alias.rb +60 -0
- data/lib/puppet-strings/yard/code_objects/defined_type.rb +5 -3
- data/lib/puppet-strings/yard/code_objects/function.rb +9 -6
- data/lib/puppet-strings/yard/code_objects/group.rb +3 -0
- data/lib/puppet-strings/yard/code_objects/plan.rb +5 -3
- data/lib/puppet-strings/yard/code_objects/provider.rb +6 -0
- data/lib/puppet-strings/yard/code_objects/task.rb +3 -1
- data/lib/puppet-strings/yard/code_objects/type.rb +49 -5
- data/lib/puppet-strings/yard/handlers.rb +4 -0
- data/lib/puppet-strings/yard/handlers/helpers.rb +2 -0
- data/lib/puppet-strings/yard/handlers/json/base.rb +2 -0
- data/lib/puppet-strings/yard/handlers/json/task_handler.rb +2 -0
- data/lib/puppet-strings/yard/handlers/puppet/base.rb +3 -0
- data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +2 -0
- data/lib/puppet-strings/yard/handlers/puppet/data_type_alias_handler.rb +26 -0
- data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +2 -0
- data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +3 -1
- data/lib/puppet-strings/yard/handlers/puppet/plan_handler.rb +2 -0
- data/lib/puppet-strings/yard/handlers/ruby/base.rb +7 -2
- data/lib/puppet-strings/yard/handlers/ruby/data_type_handler.rb +409 -0
- data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +9 -9
- data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +13 -0
- data/lib/puppet-strings/yard/handlers/ruby/rsapi_handler.rb +6 -3
- data/lib/puppet-strings/yard/handlers/ruby/type_base.rb +25 -12
- data/lib/puppet-strings/yard/handlers/ruby/type_extras_handler.rb +6 -3
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +18 -1
- data/lib/puppet-strings/yard/parsers.rb +2 -0
- data/lib/puppet-strings/yard/parsers/json/parser.rb +3 -1
- data/lib/puppet-strings/yard/parsers/json/task_statement.rb +2 -0
- data/lib/puppet-strings/yard/parsers/puppet/parser.rb +11 -2
- data/lib/puppet-strings/yard/parsers/puppet/statement.rb +29 -0
- data/lib/puppet-strings/yard/tags.rb +4 -0
- data/lib/puppet-strings/yard/tags/enum_tag.rb +14 -0
- data/lib/puppet-strings/yard/tags/factory.rb +18 -0
- data/lib/puppet-strings/yard/tags/overload_tag.rb +5 -2
- data/lib/puppet-strings/yard/tags/parameter_directive.rb +5 -4
- data/lib/puppet-strings/yard/tags/property_directive.rb +5 -4
- data/lib/puppet-strings/yard/tags/summary_tag.rb +2 -0
- 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_function/html/setup.rb +1 -1
- 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 +7 -4
- data/lib/puppet/application/strings.rb +2 -0
- data/lib/puppet/face/strings.rb +7 -4
- data/lib/puppet/feature/rgen.rb +2 -0
- data/lib/puppet/feature/yard.rb +2 -0
- metadata +35 -45
- data/Gemfile +0 -38
- data/HISTORY.md +0 -218
- data/JSON.md +0 -802
- data/Rakefile +0 -98
- 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/markdown/output.md +0 -508
- data/spec/fixtures/unit/markdown/output_with_plan.md +0 -542
- data/spec/spec_helper.rb +0 -46
- data/spec/spec_helper_acceptance.rb +0 -28
- data/spec/unit/puppet-strings/describe_spec.rb +0 -141
- data/spec/unit/puppet-strings/json_spec.rb +0 -283
- data/spec/unit/puppet-strings/markdown/base_spec.rb +0 -146
- data/spec/unit/puppet-strings/markdown_spec.rb +0 -296
- 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 -116
- 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 -235
- data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +0 -295
- data/spec/unit/puppet-strings/yard/parsers/json/parser_spec.rb +0 -72
- 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,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
|
|
@@ -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
|
|
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
|