puppet-strings 0.4.0 → 0.99.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +122 -0
- data/COMMITTERS.md +185 -0
- data/CONTRIBUTING.md +89 -0
- data/Gemfile +38 -0
- data/JSON.md +511 -0
- data/LICENSE +13 -0
- data/README.md +416 -0
- data/Rakefile +49 -0
- data/lib/puppet-strings.rb +63 -0
- data/lib/puppet-strings/json.rb +49 -0
- data/lib/puppet-strings/tasks.rb +10 -0
- data/lib/puppet-strings/tasks/generate.rb +23 -0
- data/lib/puppet-strings/tasks/gh_pages.rb +43 -0
- data/lib/puppet-strings/yard.rb +96 -0
- data/lib/puppet-strings/yard/code_objects.rb +8 -0
- data/lib/puppet-strings/yard/code_objects/base.rb +14 -0
- data/lib/puppet-strings/yard/code_objects/class.rb +59 -0
- data/lib/puppet-strings/yard/code_objects/defined_type.rb +58 -0
- data/lib/puppet-strings/yard/code_objects/function.rb +93 -0
- data/lib/puppet-strings/yard/code_objects/group.rb +30 -0
- data/lib/puppet-strings/yard/code_objects/provider.rb +93 -0
- data/lib/puppet-strings/yard/code_objects/type.rb +146 -0
- data/lib/puppet-strings/yard/handlers.rb +16 -0
- data/lib/puppet-strings/yard/handlers/puppet/base.rb +44 -0
- data/lib/puppet-strings/yard/handlers/puppet/class_handler.rb +23 -0
- data/lib/puppet-strings/yard/handlers/puppet/defined_type_handler.rb +23 -0
- data/lib/puppet-strings/yard/handlers/puppet/function_handler.rb +42 -0
- data/lib/puppet-strings/yard/handlers/ruby/base.rb +38 -0
- data/lib/puppet-strings/yard/handlers/ruby/function_handler.rb +357 -0
- data/lib/puppet-strings/yard/handlers/ruby/provider_handler.rb +113 -0
- data/lib/puppet-strings/yard/handlers/ruby/type_handler.rb +194 -0
- data/lib/puppet-strings/yard/parsers.rb +7 -0
- data/lib/puppet-strings/yard/parsers/puppet/parser.rb +70 -0
- data/lib/puppet-strings/yard/parsers/puppet/statement.rb +146 -0
- data/lib/puppet-strings/yard/tags.rb +6 -0
- data/lib/puppet-strings/yard/tags/overload_tag.rb +109 -0
- data/lib/puppet-strings/yard/tags/parameter_directive.rb +24 -0
- data/lib/puppet-strings/yard/tags/property_directive.rb +24 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_class.erb +9 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_defined_type.erb +9 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_function.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +9 -0
- data/lib/puppet-strings/yard/templates/default/fulldoc/html/setup.rb +64 -0
- data/lib/puppet-strings/yard/templates/default/layout/html/objects.erb +35 -0
- data/lib/puppet-strings/yard/templates/default/layout/html/setup.rb +172 -0
- data/lib/puppet-strings/yard/templates/default/puppet_class/html/box_info.erb +26 -0
- data/lib/puppet-strings/yard/templates/default/puppet_class/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_class/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_class/html/setup.rb +14 -0
- data/lib/puppet-strings/yard/templates/default/puppet_class/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/box_info.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/setup.rb +5 -0
- data/lib/puppet-strings/yard/templates/default/puppet_defined_type/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_function/html/box_info.erb +14 -0
- data/lib/puppet-strings/yard/templates/default/puppet_function/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_function/html/overview.erb +18 -0
- data/lib/puppet-strings/yard/templates/default/puppet_function/html/setup.rb +5 -0
- data/lib/puppet-strings/yard/templates/default/puppet_function/html/source.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_provider/html/box_info.erb +14 -0
- data/lib/puppet-strings/yard/templates/default/puppet_provider/html/collection.erb +10 -0
- data/lib/puppet-strings/yard/templates/default/puppet_provider/html/features.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/puppet_provider/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_provider/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_provider/html/setup.rb +29 -0
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/box_info.erb +20 -0
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/features.erb +13 -0
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/header.erb +1 -0
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/overview.erb +6 -0
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/parameters.erb +35 -0
- data/lib/puppet-strings/yard/templates/default/puppet_type/html/setup.rb +32 -0
- data/lib/puppet-strings/yard/templates/default/tags/html/puppet_overload.erb +12 -0
- data/lib/puppet-strings/yard/templates/default/tags/setup.rb +15 -0
- data/lib/puppet/application/strings.rb +1 -0
- data/lib/puppet/face/strings.rb +80 -39
- data/spec/acceptance/emit_json_options.rb +41 -0
- data/spec/acceptance/lib/util.rb +15 -0
- data/spec/acceptance/running_strings_generate.rb +54 -0
- data/spec/fixtures/acceptance/modules/test/functions/add.pp +9 -0
- data/spec/fixtures/acceptance/modules/test/lib/puppet/functions/4x_function.rb +5 -0
- data/spec/fixtures/acceptance/modules/test/lib/puppet/parser/functions/function3x.rb +2 -0
- data/spec/fixtures/acceptance/modules/test/lib/puppet/provider/server/linux.rb +9 -0
- data/spec/fixtures/acceptance/modules/test/lib/puppet/type/database.rb +15 -0
- data/spec/fixtures/acceptance/modules/test/manifests/init.pp +27 -0
- data/spec/fixtures/acceptance/modules/test/manifests/triple_nested_classes.pp +27 -0
- data/spec/fixtures/acceptance/modules/test/metadata.json +6 -0
- data/spec/fixtures/unit/json/output.json +348 -0
- data/spec/fixtures/unit/json/output_without_puppet_function.json +301 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/spec_helper_acceptance.rb +27 -0
- data/spec/unit/puppet-strings/json_spec.rb +136 -0
- data/spec/unit/puppet-strings/yard/handlers/puppet/class_handler_spec.rb +155 -0
- data/spec/unit/puppet-strings/yard/handlers/puppet/defined_type_handler_spec.rb +155 -0
- data/spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb +169 -0
- data/spec/unit/puppet-strings/yard/handlers/ruby/function_handler_spec.rb +613 -0
- data/spec/unit/puppet-strings/yard/handlers/ruby/provider_handler_spec.rb +90 -0
- data/spec/unit/puppet-strings/yard/handlers/ruby/type_handler_spec.rb +214 -0
- data/spec/unit/puppet-strings/yard/parsers/puppet/parser_spec.rb +171 -0
- metadata +115 -92
- data/lib/puppet-strings/rake_tasks.rb +0 -18
- data/lib/puppet_x/puppetlabs/strings.rb +0 -64
- data/lib/puppet_x/puppetlabs/strings/actions.rb +0 -92
- data/lib/puppet_x/puppetlabs/strings/pops/yard_statement.rb +0 -79
- data/lib/puppet_x/puppetlabs/strings/pops/yard_transformer.rb +0 -47
- data/lib/puppet_x/puppetlabs/strings/util.rb +0 -65
- data/lib/puppet_x/puppetlabs/strings/yard/code_objects/defined_type_object.rb +0 -33
- data/lib/puppet_x/puppetlabs/strings/yard/code_objects/host_class_object.rb +0 -22
- data/lib/puppet_x/puppetlabs/strings/yard/code_objects/method_object.rb +0 -62
- data/lib/puppet_x/puppetlabs/strings/yard/code_objects/provider_object.rb +0 -24
- data/lib/puppet_x/puppetlabs/strings/yard/code_objects/puppet_namespace_object.rb +0 -48
- data/lib/puppet_x/puppetlabs/strings/yard/code_objects/type_object.rb +0 -42
- data/lib/puppet_x/puppetlabs/strings/yard/core_ext/yard.rb +0 -40
- data/lib/puppet_x/puppetlabs/strings/yard/handlers/base.rb +0 -13
- data/lib/puppet_x/puppetlabs/strings/yard/handlers/defined_type_handler.rb +0 -31
- data/lib/puppet_x/puppetlabs/strings/yard/handlers/heredoc_helper.rb +0 -80
- data/lib/puppet_x/puppetlabs/strings/yard/handlers/host_class_handler.rb +0 -42
- data/lib/puppet_x/puppetlabs/strings/yard/handlers/provider_handler.rb +0 -95
- data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_3x_function_handler.rb +0 -54
- data/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +0 -234
- data/lib/puppet_x/puppetlabs/strings/yard/handlers/type_handler.rb +0 -295
- data/lib/puppet_x/puppetlabs/strings/yard/json_registry_store.rb +0 -85
- data/lib/puppet_x/puppetlabs/strings/yard/monkey_patches.rb +0 -68
- data/lib/puppet_x/puppetlabs/strings/yard/parser.rb +0 -30
- data/lib/puppet_x/puppetlabs/strings/yard/tags/directives.rb +0 -9
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/docstring.erb +0 -34
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/header.erb +0 -5
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/parameter_details.erb +0 -6
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/html/setup.rb +0 -1
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/definedtype/setup.rb +0 -49
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_class.erb +0 -2
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_manifest.erb +0 -1
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_plugin.erb +0 -21
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_provider.erb +0 -1
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/full_list_puppet_type.erb +0 -1
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/fulldoc/html/setup.rb +0 -82
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/box_info.erb +0 -22
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/setup.rb +0 -1
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/html/subclasses.erb +0 -4
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/hostclass/setup.rb +0 -21
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/html_helper.rb +0 -139
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/layout/html/setup.rb +0 -18
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/html/header.erb +0 -17
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/setup.rb +0 -21
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/method_details/text/header.erb +0 -2
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/command_details.erb +0 -8
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/confine_details.erb +0 -10
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/default_details.erb +0 -10
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/docstring.erb +0 -34
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/feature_details.erb +0 -10
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/header.erb +0 -5
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/html/setup.rb +0 -1
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/provider/setup.rb +0 -50
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/box_info.erb +0 -11
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/header.erb +0 -5
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_details_list.erb +0 -53
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/method_summary.erb +0 -20
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/html/setup.rb +0 -1
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/puppetnamespace/setup.rb +0 -91
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb +0 -192
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/docstring.erb +0 -34
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/header.erb +0 -5
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/parameter_details.erb +0 -12
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/provider_details.erb +0 -10
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/html/setup.rb +0 -1
- data/lib/puppet_x/puppetlabs/strings/yard/templates/default/type/setup.rb +0 -55
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'puppet-strings/yard'
|
3
|
+
|
4
|
+
describe PuppetStrings::Yard::Handlers::Puppet::ClassHandler do
|
5
|
+
subject {
|
6
|
+
YARD::Parser::SourceParser.parse_string(source, :puppet)
|
7
|
+
YARD::Registry.all(:puppet_class)
|
8
|
+
}
|
9
|
+
|
10
|
+
describe 'parsing source without a class definition' do
|
11
|
+
let(:source) { 'notice hi' }
|
12
|
+
|
13
|
+
it 'no classes should be in the registry' do
|
14
|
+
expect(subject.empty?).to eq(true)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'parsing source with a syntax error' do
|
19
|
+
let(:source) { 'class foo{' }
|
20
|
+
|
21
|
+
it 'should log an error' do
|
22
|
+
expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of file/).to_stdout_from_any_process
|
23
|
+
expect(subject.empty?).to eq(true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'parsing a class with a missing docstring' do
|
28
|
+
let(:source) { 'class foo{}' }
|
29
|
+
|
30
|
+
it 'should log a warning' do
|
31
|
+
expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet class 'foo' at \(stdin\):1\./).to_stdout_from_any_process
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'parsing a class with a docstring' do
|
36
|
+
let(:source) { <<-SOURCE
|
37
|
+
# A simple foo class.
|
38
|
+
# @param param1 First param.
|
39
|
+
# @param param2 Second param.
|
40
|
+
# @param param3 Third param.
|
41
|
+
class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
|
42
|
+
file { '/tmp/foo':
|
43
|
+
ensure => present
|
44
|
+
}
|
45
|
+
}
|
46
|
+
SOURCE
|
47
|
+
}
|
48
|
+
|
49
|
+
it 'should register a class object' do
|
50
|
+
expect(subject.size).to eq(1)
|
51
|
+
object = subject.first
|
52
|
+
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Class)
|
53
|
+
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::Classes.instance)
|
54
|
+
expect(object.name).to eq(:foo)
|
55
|
+
expect(object.statement).not_to eq(nil)
|
56
|
+
expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']])
|
57
|
+
expect(object.docstring).to eq('A simple foo class.')
|
58
|
+
expect(object.docstring.tags.size).to eq(4)
|
59
|
+
tags = object.docstring.tags(:param)
|
60
|
+
expect(tags.size).to eq(3)
|
61
|
+
expect(tags[0].name).to eq('param1')
|
62
|
+
expect(tags[0].text).to eq('First param.')
|
63
|
+
expect(tags[0].types).to eq(['Integer'])
|
64
|
+
expect(tags[1].name).to eq('param2')
|
65
|
+
expect(tags[1].text).to eq('Second param.')
|
66
|
+
expect(tags[1].types).to eq(['Any'])
|
67
|
+
expect(tags[2].name).to eq('param3')
|
68
|
+
expect(tags[2].text).to eq('Third param.')
|
69
|
+
expect(tags[2].types).to eq(['String'])
|
70
|
+
tags = object.docstring.tags(:api)
|
71
|
+
expect(tags.size).to eq(1)
|
72
|
+
expect(tags[0].text).to eq('public')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'parsing a class with a missing parameter' do
|
77
|
+
let(:source) { <<-SOURCE
|
78
|
+
# A simple foo class.
|
79
|
+
# @param param1 First param.
|
80
|
+
# @param param2 Second param.
|
81
|
+
# @param param3 Third param.
|
82
|
+
# @param param4 missing!
|
83
|
+
class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
|
84
|
+
file { '/tmp/foo':
|
85
|
+
ensure => present
|
86
|
+
}
|
87
|
+
}
|
88
|
+
SOURCE
|
89
|
+
}
|
90
|
+
|
91
|
+
it 'should output a warning' do
|
92
|
+
expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\./).to_stdout_from_any_process
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'parsing a class with a missing @param tag' do
|
97
|
+
let(:source) { <<-SOURCE
|
98
|
+
# A simple foo class.
|
99
|
+
# @param param1 First param.
|
100
|
+
# @param param2 Second param.
|
101
|
+
class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
|
102
|
+
file { '/tmp/foo':
|
103
|
+
ensure => present
|
104
|
+
}
|
105
|
+
}
|
106
|
+
SOURCE
|
107
|
+
}
|
108
|
+
|
109
|
+
it 'should output a warning' do
|
110
|
+
expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\./).to_stdout_from_any_process
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'parsing a class with a typed parameter that also has a @param tag type' do
|
115
|
+
let(:source) { <<-SOURCE
|
116
|
+
# A simple foo class.
|
117
|
+
# @param [Boolean] param1 First param.
|
118
|
+
# @param param2 Second param.
|
119
|
+
# @param param3 Third param.
|
120
|
+
class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
|
121
|
+
file { '/tmp/foo':
|
122
|
+
ensure => present
|
123
|
+
}
|
124
|
+
}
|
125
|
+
SOURCE
|
126
|
+
}
|
127
|
+
|
128
|
+
it 'should output a warning' do
|
129
|
+
expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param1' should not contain a type specification near \(stdin\):5: ignoring in favor of parameter type information\./).to_stdout_from_any_process
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'parsing a class with a untyped parameter that also has a @param tag type' do
|
134
|
+
let(:source) { <<-SOURCE
|
135
|
+
# A simple foo class.
|
136
|
+
# @param param1 First param.
|
137
|
+
# @param [Boolean] param2 Second param.
|
138
|
+
# @param param3 Third param.
|
139
|
+
class foo(Integer $param1, $param2, String $param3 = hi) inherits foo::bar {
|
140
|
+
file { '/tmp/foo':
|
141
|
+
ensure => present
|
142
|
+
}
|
143
|
+
}
|
144
|
+
SOURCE
|
145
|
+
}
|
146
|
+
|
147
|
+
it 'should respect the type that was documented' do
|
148
|
+
expect{ subject }.to output('').to_stdout_from_any_process
|
149
|
+
expect(subject.size).to eq(1)
|
150
|
+
tags = subject.first.tags(:param)
|
151
|
+
expect(tags.size).to eq(3)
|
152
|
+
expect(tags[1].types).to eq(['Boolean'])
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'puppet-strings/yard'
|
3
|
+
|
4
|
+
describe PuppetStrings::Yard::Handlers::Puppet::DefinedTypeHandler do
|
5
|
+
subject {
|
6
|
+
YARD::Parser::SourceParser.parse_string(source, :puppet)
|
7
|
+
YARD::Registry.all(:puppet_defined_type)
|
8
|
+
}
|
9
|
+
|
10
|
+
describe 'parsing source without a defined type definition' do
|
11
|
+
let(:source) { 'notice hi' }
|
12
|
+
|
13
|
+
it 'no defined types should be in the registry' do
|
14
|
+
expect(subject.empty?).to eq(true)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'parsing source with a syntax error' do
|
19
|
+
let(:source) { 'define foo{' }
|
20
|
+
|
21
|
+
it 'should log an error' do
|
22
|
+
expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of file/).to_stdout_from_any_process
|
23
|
+
expect(subject.empty?).to eq(true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'parsing a defined type with a missing docstring' do
|
28
|
+
let(:source) { 'define foo{}' }
|
29
|
+
|
30
|
+
it 'should log a warning' do
|
31
|
+
expect{ subject }.to output(/\[warn\]: Missing documentation for Puppet defined type 'foo' at \(stdin\):1\./).to_stdout_from_any_process
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'parsing a defined type with a docstring' do
|
36
|
+
let(:source) { <<-SOURCE
|
37
|
+
# A simple foo defined type.
|
38
|
+
# @param param1 First param.
|
39
|
+
# @param param2 Second param.
|
40
|
+
# @param param3 Third param.
|
41
|
+
define foo(Integer $param1, $param2, String $param3 = hi) {
|
42
|
+
file { '/tmp/foo':
|
43
|
+
ensure => present
|
44
|
+
}
|
45
|
+
}
|
46
|
+
SOURCE
|
47
|
+
}
|
48
|
+
|
49
|
+
it 'should register a defined type object' do
|
50
|
+
expect(subject.size).to eq(1)
|
51
|
+
object = subject.first
|
52
|
+
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::DefinedType)
|
53
|
+
expect(object.namespace).to eq(PuppetStrings::Yard::CodeObjects::DefinedTypes.instance)
|
54
|
+
expect(object.name).to eq(:foo)
|
55
|
+
expect(object.statement).not_to eq(nil)
|
56
|
+
expect(object.parameters).to eq([['param1', nil], ['param2', nil], ['param3', 'hi']])
|
57
|
+
expect(object.docstring).to eq('A simple foo defined type.')
|
58
|
+
expect(object.docstring.tags.size).to eq(4)
|
59
|
+
tags = object.docstring.tags(:param)
|
60
|
+
expect(tags.size).to eq(3)
|
61
|
+
expect(tags[0].name).to eq('param1')
|
62
|
+
expect(tags[0].text).to eq('First param.')
|
63
|
+
expect(tags[0].types).to eq(['Integer'])
|
64
|
+
expect(tags[1].name).to eq('param2')
|
65
|
+
expect(tags[1].text).to eq('Second param.')
|
66
|
+
expect(tags[1].types).to eq(['Any'])
|
67
|
+
expect(tags[2].name).to eq('param3')
|
68
|
+
expect(tags[2].text).to eq('Third param.')
|
69
|
+
expect(tags[2].types).to eq(['String'])
|
70
|
+
tags = object.docstring.tags(:api)
|
71
|
+
expect(tags.size).to eq(1)
|
72
|
+
expect(tags[0].text).to eq('public')
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'parsing a defined type with a missing parameter' do
|
77
|
+
let(:source) { <<-SOURCE
|
78
|
+
# A simple foo defined type.
|
79
|
+
# @param param1 First param.
|
80
|
+
# @param param2 Second param.
|
81
|
+
# @param param3 Third param.
|
82
|
+
# @param param4 missing!
|
83
|
+
define foo(Integer $param1, $param2, String $param3 = hi) {
|
84
|
+
file { '/tmp/foo':
|
85
|
+
ensure => present
|
86
|
+
}
|
87
|
+
}
|
88
|
+
SOURCE
|
89
|
+
}
|
90
|
+
|
91
|
+
it 'should output a warning' do
|
92
|
+
expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):6\./).to_stdout_from_any_process
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'parsing a defined type with a missing @param tag' do
|
97
|
+
let(:source) { <<-SOURCE
|
98
|
+
# A simple foo defined type.
|
99
|
+
# @param param1 First param.
|
100
|
+
# @param param2 Second param.
|
101
|
+
define foo(Integer $param1, $param2, String $param3 = hi) {
|
102
|
+
file { '/tmp/foo':
|
103
|
+
ensure => present
|
104
|
+
}
|
105
|
+
}
|
106
|
+
SOURCE
|
107
|
+
}
|
108
|
+
|
109
|
+
it 'should output a warning' do
|
110
|
+
expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):4\./).to_stdout_from_any_process
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe 'parsing a defined type with a typed parameter that also has a @param tag type' do
|
115
|
+
let(:source) { <<-SOURCE
|
116
|
+
# A simple foo defined type.
|
117
|
+
# @param [Boolean] param1 First param.
|
118
|
+
# @param param2 Second param.
|
119
|
+
# @param param3 Third param.
|
120
|
+
define foo(Integer $param1, $param2, String $param3 = hi) {
|
121
|
+
file { '/tmp/foo':
|
122
|
+
ensure => present
|
123
|
+
}
|
124
|
+
}
|
125
|
+
SOURCE
|
126
|
+
}
|
127
|
+
|
128
|
+
it 'should output a warning' do
|
129
|
+
expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param1' should not contain a type specification near \(stdin\):5: ignoring in favor of parameter type information\./).to_stdout_from_any_process
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'parsing a defined type with a untyped parameter that also has a @param tag type' do
|
134
|
+
let(:source) { <<-SOURCE
|
135
|
+
# A simple foo defined type.
|
136
|
+
# @param param1 First param.
|
137
|
+
# @param [Boolean] param2 Second param.
|
138
|
+
# @param param3 Third param.
|
139
|
+
define foo(Integer $param1, $param2, String $param3 = hi) {
|
140
|
+
file { '/tmp/foo':
|
141
|
+
ensure => present
|
142
|
+
}
|
143
|
+
}
|
144
|
+
SOURCE
|
145
|
+
}
|
146
|
+
|
147
|
+
it 'should respect the type that was documented' do
|
148
|
+
expect{ subject }.to output('').to_stdout_from_any_process
|
149
|
+
expect(subject.size).to eq(1)
|
150
|
+
tags = subject.first.tags(:param)
|
151
|
+
expect(tags.size).to eq(3)
|
152
|
+
expect(tags[1].types).to eq(['Boolean'])
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
@@ -0,0 +1,169 @@
|
|
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 file/).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(:api)
|
72
|
+
expect(tags.size).to eq(1)
|
73
|
+
expect(tags[0].text).to eq('public')
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe 'parsing a function with a missing parameter' do
|
78
|
+
let(:source) { <<-SOURCE
|
79
|
+
# A simple foo function.
|
80
|
+
# @param param1 First param.
|
81
|
+
# @param param2 Second param.
|
82
|
+
# @param param3 Third param.
|
83
|
+
# @param param4 missing!
|
84
|
+
# @return [Undef] Returns nothing.
|
85
|
+
function foo(Integer $param1, $param2, String $param3 = hi) {
|
86
|
+
notice 'hello world'
|
87
|
+
}
|
88
|
+
SOURCE
|
89
|
+
}
|
90
|
+
|
91
|
+
it 'should output a warning' do
|
92
|
+
expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param4' has no matching parameter at \(stdin\):7\./).to_stdout_from_any_process
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'parsing a function with a missing @param tag' do
|
97
|
+
let(:source) { <<-SOURCE
|
98
|
+
# A simple foo function.
|
99
|
+
# @param param1 First param.
|
100
|
+
# @param param2 Second param.
|
101
|
+
# @return [Undef] Returns nothing.
|
102
|
+
function foo(Integer $param1, $param2, String $param3 = hi) {
|
103
|
+
notice 'hello world'
|
104
|
+
}
|
105
|
+
SOURCE
|
106
|
+
}
|
107
|
+
|
108
|
+
it 'should output a warning' do
|
109
|
+
expect{ subject }.to output(/\[warn\]: Missing @param tag for parameter 'param3' near \(stdin\):5\./).to_stdout_from_any_process
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'parsing a function with a typed parameter that also has a @param tag type' do
|
114
|
+
let(:source) { <<-SOURCE
|
115
|
+
# A simple foo function.
|
116
|
+
# @param [Boolean] param1 First param.
|
117
|
+
# @param param2 Second param.
|
118
|
+
# @param param3 Third param.
|
119
|
+
# @return [Undef] Returns nothing.
|
120
|
+
function foo(Integer $param1, $param2, String $param3 = hi) {
|
121
|
+
notice 'hello world'
|
122
|
+
}
|
123
|
+
SOURCE
|
124
|
+
}
|
125
|
+
|
126
|
+
it 'should output a warning' do
|
127
|
+
expect{ subject }.to output(/\[warn\]: The @param tag for parameter 'param1' should not contain a type specification near \(stdin\):6: ignoring in favor of parameter type information\./).to_stdout_from_any_process
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe 'parsing a function with a untyped parameter that also has a @param tag type' do
|
132
|
+
let(:source) { <<-SOURCE
|
133
|
+
# A simple foo function.
|
134
|
+
# @param param1 First param.
|
135
|
+
# @param [Boolean] param2 Second param.
|
136
|
+
# @param param3 Third param.
|
137
|
+
# @return [Undef] Returns nothing.
|
138
|
+
function foo(Integer $param1, $param2, String $param3 = hi) {
|
139
|
+
notice 'hello world'
|
140
|
+
}
|
141
|
+
SOURCE
|
142
|
+
}
|
143
|
+
|
144
|
+
it 'should respect the type that was documented' do
|
145
|
+
expect{ subject }.to output('').to_stdout_from_any_process
|
146
|
+
expect(subject.size).to eq(1)
|
147
|
+
tags = subject.first.tags(:param)
|
148
|
+
expect(tags.size).to eq(3)
|
149
|
+
expect(tags[1].types).to eq(['Boolean'])
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe 'parsing a function with a missing @return tag' do
|
154
|
+
let(:source) { <<-SOURCE
|
155
|
+
# A simple foo function.
|
156
|
+
# @param param1 First param.
|
157
|
+
# @param param2 Second param.
|
158
|
+
# @param param3 Third param.
|
159
|
+
function foo(Integer $param1, $param2, String $param3 = hi) {
|
160
|
+
notice 'hello world'
|
161
|
+
}
|
162
|
+
SOURCE
|
163
|
+
}
|
164
|
+
|
165
|
+
it 'should output a warning' do
|
166
|
+
expect{ subject }.to output(/\[warn\]: Missing @return tag near \(stdin\):5\./).to_stdout_from_any_process
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|