puppet-lint-halyard 1.1.0.1
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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +10 -0
- data/Gemfile +3 -0
- data/LICENSE +20 -0
- data/README.md +210 -0
- data/Rakefile +14 -0
- data/bin/puppet-lint +7 -0
- data/lib/puppet-lint.rb +214 -0
- data/lib/puppet-lint/bin.rb +79 -0
- data/lib/puppet-lint/checkplugin.rb +176 -0
- data/lib/puppet-lint/checks.rb +91 -0
- data/lib/puppet-lint/configuration.rb +153 -0
- data/lib/puppet-lint/data.rb +521 -0
- data/lib/puppet-lint/lexer.rb +373 -0
- data/lib/puppet-lint/lexer/token.rb +101 -0
- data/lib/puppet-lint/monkeypatches.rb +2 -0
- data/lib/puppet-lint/monkeypatches/string_percent.rb +52 -0
- data/lib/puppet-lint/monkeypatches/string_prepend.rb +13 -0
- data/lib/puppet-lint/optparser.rb +118 -0
- data/lib/puppet-lint/plugins.rb +74 -0
- data/lib/puppet-lint/plugins/check_classes.rb +285 -0
- data/lib/puppet-lint/plugins/check_comments.rb +55 -0
- data/lib/puppet-lint/plugins/check_conditionals.rb +65 -0
- data/lib/puppet-lint/plugins/check_documentation.rb +31 -0
- data/lib/puppet-lint/plugins/check_nodes.rb +29 -0
- data/lib/puppet-lint/plugins/check_resources.rb +194 -0
- data/lib/puppet-lint/plugins/check_strings.rb +174 -0
- data/lib/puppet-lint/plugins/check_variables.rb +19 -0
- data/lib/puppet-lint/plugins/check_whitespace.rb +170 -0
- data/lib/puppet-lint/tasks/puppet-lint.rb +91 -0
- data/lib/puppet-lint/version.rb +3 -0
- data/puppet-lint.gemspec +24 -0
- data/spec/fixtures/test/manifests/fail.pp +2 -0
- data/spec/fixtures/test/manifests/ignore.pp +1 -0
- data/spec/fixtures/test/manifests/ignore_multiple_block.pp +6 -0
- data/spec/fixtures/test/manifests/ignore_multiple_line.pp +2 -0
- data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
- data/spec/fixtures/test/manifests/init.pp +3 -0
- data/spec/fixtures/test/manifests/malformed.pp +1 -0
- data/spec/fixtures/test/manifests/url_interpolation.pp +12 -0
- data/spec/fixtures/test/manifests/warning.pp +2 -0
- data/spec/puppet-lint/bin_spec.rb +326 -0
- data/spec/puppet-lint/configuration_spec.rb +56 -0
- data/spec/puppet-lint/ignore_overrides_spec.rb +109 -0
- data/spec/puppet-lint/lexer/token_spec.rb +18 -0
- data/spec/puppet-lint/lexer_spec.rb +783 -0
- data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +105 -0
- data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +35 -0
- data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +33 -0
- data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +45 -0
- data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +76 -0
- data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +73 -0
- data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +25 -0
- data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +196 -0
- data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +45 -0
- data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +84 -0
- data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +98 -0
- data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +36 -0
- data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +52 -0
- data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +146 -0
- data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +100 -0
- data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +55 -0
- data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +89 -0
- data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +113 -0
- data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +45 -0
- data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +216 -0
- data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +199 -0
- data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +114 -0
- data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +62 -0
- data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +129 -0
- data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +17 -0
- data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +73 -0
- data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +37 -0
- data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +21 -0
- data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +54 -0
- data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +524 -0
- data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +45 -0
- data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +101 -0
- data/spec/puppet-lint_spec.rb +20 -0
- data/spec/spec_helper.rb +129 -0
- metadata +229 -0
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'autoloader_layout' do
|
4
|
+
context 'foo::bar in foo/manifests/bar.pp' do
|
5
|
+
let(:code) { "class foo::bar { }" }
|
6
|
+
let(:path) { 'foo/manifests/bar.pp' }
|
7
|
+
|
8
|
+
it 'should not detect any problems' do
|
9
|
+
expect(problems).to have(0).problems
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'foo::bar::baz in foo/manifests/bar/baz.pp' do
|
14
|
+
let(:code) { 'define foo::bar::baz() { }' }
|
15
|
+
let(:path) { 'foo/manifests/bar/baz.pp' }
|
16
|
+
|
17
|
+
it 'should not detect any problems' do
|
18
|
+
expect(problems).to have(0).problems
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'foo in foo/manifests/init.pp' do
|
23
|
+
let(:code) { 'class foo { }' }
|
24
|
+
let(:path) { 'foo/manifests/init.pp' }
|
25
|
+
|
26
|
+
it 'should not detect any problems' do
|
27
|
+
expect(problems).to have(0).problems
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'foo::bar in foo/manifests/init.pp' do
|
32
|
+
let(:code) { 'class foo::bar { }' }
|
33
|
+
let(:path) { 'foo/manifests/init.pp' }
|
34
|
+
let(:msg) { 'foo::bar not in autoload module layout' }
|
35
|
+
|
36
|
+
it 'should only detect a single problem' do
|
37
|
+
expect(problems).to have(1).problem
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should create an error' do
|
41
|
+
expect(problems).to contain_error(msg).on_line(1).in_column(7)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'foo included in bar/manifests/init.pp' do
|
46
|
+
let(:code) { "
|
47
|
+
class bar {
|
48
|
+
class {'foo':
|
49
|
+
someparam => 'somevalue',
|
50
|
+
}
|
51
|
+
}
|
52
|
+
"
|
53
|
+
}
|
54
|
+
let(:path) { 'bar/manifests/init.pp' }
|
55
|
+
|
56
|
+
it 'should not detect any problems' do
|
57
|
+
expect(problems).to have(0).problems
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'foo in puppet-foo/manifests/init.pp' do
|
62
|
+
let(:code) { 'class foo { }' }
|
63
|
+
let(:path) { 'puppet-foo/manifests/init.pp' }
|
64
|
+
|
65
|
+
it 'should detect a single problem' do
|
66
|
+
expect(problems).to have(1).problems
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'foo in puppet-foo/manifests/bar.pp with relative option' do
|
71
|
+
before do
|
72
|
+
PuppetLint.configuration.relative = true
|
73
|
+
end
|
74
|
+
|
75
|
+
after do
|
76
|
+
PuppetLint.configuration.relative = false
|
77
|
+
end
|
78
|
+
|
79
|
+
let(:code) { 'class foo { }' }
|
80
|
+
let(:path) { 'puppet-foo/manifests/bar.pp' }
|
81
|
+
|
82
|
+
it 'should detect a single problem' do
|
83
|
+
expect(problems).to have(1).problems
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'foo in puppet-foo/manifests/init.pp with relative option' do
|
88
|
+
before do
|
89
|
+
PuppetLint.configuration.relative = true
|
90
|
+
end
|
91
|
+
|
92
|
+
after do
|
93
|
+
PuppetLint.configuration.relative = false
|
94
|
+
end
|
95
|
+
|
96
|
+
let(:code) { 'class foo { }' }
|
97
|
+
let(:path) { 'puppet-foo/manifests/init.pp' }
|
98
|
+
|
99
|
+
it 'should not detect any problems' do
|
100
|
+
expect(problems).to have(0).problems
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'class_inherits_from_params_class' do
|
4
|
+
let(:msg) { 'class inheriting from params class' }
|
5
|
+
|
6
|
+
context 'parameterised class that inherits from a params class' do
|
7
|
+
let(:code) { "
|
8
|
+
# commented
|
9
|
+
class foo($bar = $name) inherits foo::params { }"
|
10
|
+
}
|
11
|
+
|
12
|
+
it 'should only detect a single problem' do
|
13
|
+
expect(problems).to have(1).problem
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should create a warning' do
|
17
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(40)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'class without parameters' do
|
22
|
+
let(:code) {"
|
23
|
+
class myclass {
|
24
|
+
|
25
|
+
if ( $::lsbdistcodename == 'squeeze' ) {
|
26
|
+
#TODO
|
27
|
+
}
|
28
|
+
}
|
29
|
+
"}
|
30
|
+
|
31
|
+
it 'should not detect any problems' do
|
32
|
+
expect(problems).to have(0).problems
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'inherits_across_namespaces' do
|
4
|
+
let(:msg) { 'class inherits across module namespaces' }
|
5
|
+
|
6
|
+
context 'class inheriting from parent in same module namespace' do
|
7
|
+
let(:code) { "class foo::bar inherits foo { }" }
|
8
|
+
|
9
|
+
it 'should not detect any problems' do
|
10
|
+
expect(problems).to have(0).problems
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'class inheriting from sister in same module namespace' do
|
15
|
+
let(:code) { "class foo::bar inherits foo::baz { }" }
|
16
|
+
|
17
|
+
it 'should not detect any problems' do
|
18
|
+
expect(problems).to have(0).problems
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'class inheriting from another module namespace' do
|
23
|
+
let(:code) { "class foo::bar inherits baz { }" }
|
24
|
+
|
25
|
+
it 'should only detect a single problem' do
|
26
|
+
expect(problems).to have(1).problem
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should create a warning' do
|
30
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(25)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'names_containing_dash' do
|
4
|
+
let(:class_msg) { 'class name containing a dash' }
|
5
|
+
let(:define_msg) { 'defined type name containing a dash' }
|
6
|
+
|
7
|
+
context 'module named foo-bar' do
|
8
|
+
let(:code) { 'class foo-bar { }' }
|
9
|
+
let(:path) { 'foo-bar/manifests/init.pp' }
|
10
|
+
|
11
|
+
it 'should only detect a single problem' do
|
12
|
+
expect(problems).to have(1).problem
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should create an error' do
|
16
|
+
expect(problems).to contain_error(class_msg).on_line(1).in_column(7)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'define named foo-bar' do
|
21
|
+
let(:code) { 'define foo::foo-bar { }' }
|
22
|
+
let(:path) { 'foo/manifests/foo-bar.pp' }
|
23
|
+
|
24
|
+
it 'should only detect a single problem' do
|
25
|
+
expect(problems).to have(1).problem
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should create an error' do
|
29
|
+
expect(problems).to contain_error(define_msg).on_line(1).in_column(8)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'class named bar-foo' do
|
34
|
+
let(:code) { 'class foo::bar-foo { }' }
|
35
|
+
let(:path) { 'foo/manifests/bar-foo.pp' }
|
36
|
+
|
37
|
+
it 'should only detect a single problem' do
|
38
|
+
expect(problems).to have(1).problem
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should create an error' do
|
42
|
+
expect(problems).to contain_error(class_msg).on_line(1).in_column(7)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'nested_classes_or_defines' do
|
4
|
+
let(:class_msg) { 'class defined inside a class' }
|
5
|
+
let(:define_msg) { 'defined type defined inside a class' }
|
6
|
+
|
7
|
+
context 'class on its own' do
|
8
|
+
let(:code) { "class foo { }" }
|
9
|
+
|
10
|
+
it 'should not detect any problems' do
|
11
|
+
expect(problems).to have(0).problems
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'class inside a class' do
|
16
|
+
let(:code) { "
|
17
|
+
class foo {
|
18
|
+
class bar {
|
19
|
+
}
|
20
|
+
}"
|
21
|
+
}
|
22
|
+
|
23
|
+
it 'should only detect a single problem' do
|
24
|
+
expect(problems).to have(1).problem
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should create a warning' do
|
28
|
+
expect(problems).to contain_warning(class_msg).on_line(3).in_column(9)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'instantiating a parametised class inside a class' do
|
33
|
+
let(:code) { "
|
34
|
+
class bar {
|
35
|
+
class { 'foo':
|
36
|
+
bar => 'foobar'
|
37
|
+
}
|
38
|
+
}"
|
39
|
+
}
|
40
|
+
|
41
|
+
it 'should not detect any problems' do
|
42
|
+
expect(problems).to have(0).problems
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'instantiating a parametised class inside a define' do
|
47
|
+
let(:code) { "
|
48
|
+
define bar() {
|
49
|
+
class { 'foo':
|
50
|
+
bar => 'foobar'
|
51
|
+
}
|
52
|
+
}"
|
53
|
+
}
|
54
|
+
|
55
|
+
it 'should not detect any problems' do
|
56
|
+
expect(problems).to have(0).problems
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'define inside a class' do
|
61
|
+
let(:code) { "
|
62
|
+
class foo {
|
63
|
+
define bar() {
|
64
|
+
}
|
65
|
+
}"
|
66
|
+
}
|
67
|
+
|
68
|
+
it 'should only detect a single problem' do
|
69
|
+
expect(problems).to have(1).problems
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'should create a warning' do
|
73
|
+
expect(problems).to contain_warning(define_msg).on_line(3).in_column(9)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'parameter_order' do
|
4
|
+
let(:msg) { 'optional parameter listed before required parameter' }
|
5
|
+
|
6
|
+
context 'define with attrs in order' do
|
7
|
+
let(:code) { "define foo($bar, $baz='gronk') { }" }
|
8
|
+
|
9
|
+
it 'should not detect any problems' do
|
10
|
+
expect(problems).to have(0).problems
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'define with parameter that calls a function' do
|
15
|
+
let(:code) { "define foo($bar=extlookup($name)) {}" }
|
16
|
+
|
17
|
+
it 'should not detect any problems' do
|
18
|
+
expect(problems).to have(0).problems
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'define with attrs out of order' do
|
23
|
+
let(:code) { "define foo($bar='baz', $gronk) { }" }
|
24
|
+
|
25
|
+
it 'should only detect a single problem' do
|
26
|
+
expect(problems).to have(1).problem
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should create a warning' do
|
30
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(24)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'class/define parameter set to another variable' do
|
35
|
+
let(:code) { "
|
36
|
+
define foo($bar, $baz = $name, $gronk=$::fqdn) {
|
37
|
+
}"
|
38
|
+
}
|
39
|
+
|
40
|
+
it 'should not detect any problems' do
|
41
|
+
expect(problems).to have(0).problems
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context 'class/define parameter set to another variable with incorrect order' do
|
46
|
+
let(:code) { "
|
47
|
+
define foo($baz = $name, $bar, $gronk=$::fqdn) {
|
48
|
+
}"
|
49
|
+
}
|
50
|
+
|
51
|
+
it 'should only detect a single problem' do
|
52
|
+
expect(problems).to have(1).problem
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should create a warning' do
|
56
|
+
expect(problems).to contain_warning(msg).on_line(2).in_column(32)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'issue-101' do
|
61
|
+
let(:code) { "
|
62
|
+
define b (
|
63
|
+
$foo,
|
64
|
+
$bar='',
|
65
|
+
$baz={}
|
66
|
+
) { }
|
67
|
+
" }
|
68
|
+
|
69
|
+
it 'should not detect any problems' do
|
70
|
+
expect(problems).to have(0).problems
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'right_to_left_relationship' do
|
4
|
+
let(:msg) { 'right-to-left (<-) relationship' }
|
5
|
+
|
6
|
+
context 'chain 2 resources left to right' do
|
7
|
+
let(:code) { "Class[foo] -> Class[bar]" }
|
8
|
+
|
9
|
+
it 'should not detect any problems' do
|
10
|
+
expect(problems).to have(0).problems
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'chain 2 resources right to left' do
|
15
|
+
let(:code) { "Class[foo] <- Class[bar]" }
|
16
|
+
|
17
|
+
it 'should only detect a single problem' do
|
18
|
+
expect(problems).to have(1).problem
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should create a warning' do
|
22
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(12)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,196 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'variable_scope' do
|
4
|
+
let(:msg) { 'top-scope variable being used without an explicit namespace' }
|
5
|
+
|
6
|
+
context 'class with no variables declared accessing top scope' do
|
7
|
+
let(:code) { "
|
8
|
+
class foo {
|
9
|
+
$bar = $baz
|
10
|
+
}"
|
11
|
+
}
|
12
|
+
|
13
|
+
it 'should only detect a single problem' do
|
14
|
+
expect(problems).to have(1).problem
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should create a warning' do
|
18
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(16)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context 'class with no variables declared accessing top scope explicitly' do
|
23
|
+
let(:code) { "
|
24
|
+
class foo {
|
25
|
+
$bar = $::baz
|
26
|
+
}"
|
27
|
+
}
|
28
|
+
|
29
|
+
it 'should not detect any problems' do
|
30
|
+
expect(problems).to have(0).problems
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'class with no variables declared accessing local array index' do
|
35
|
+
let(:code) { "
|
36
|
+
class foo {
|
37
|
+
$bar = ['one', 'two', 'three']
|
38
|
+
$baz = $bar[1]
|
39
|
+
}"
|
40
|
+
}
|
41
|
+
|
42
|
+
it 'should not detect any problems' do
|
43
|
+
expect(problems).to have(0).problems
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'class with no variables declared accessing local hash key' do
|
48
|
+
let(:code) { "
|
49
|
+
class foo {
|
50
|
+
$bar = {
|
51
|
+
'one' => 1,
|
52
|
+
'two' => 2,
|
53
|
+
'three' => 3,
|
54
|
+
}
|
55
|
+
$baz = $bar['two']
|
56
|
+
}"
|
57
|
+
}
|
58
|
+
|
59
|
+
it 'should not detect any problems' do
|
60
|
+
expect(problems).to have(0).problems
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
context 'class with variables declared accessing local scope' do
|
66
|
+
let(:code) { "
|
67
|
+
class foo {
|
68
|
+
$bar = 1
|
69
|
+
$baz = $bar
|
70
|
+
}"
|
71
|
+
}
|
72
|
+
|
73
|
+
it 'should not detect any problems' do
|
74
|
+
expect(problems).to have(0).problems
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'class with parameters accessing local scope' do
|
79
|
+
let(:code) { "
|
80
|
+
class foo($bar='UNSET') {
|
81
|
+
$baz = $bar
|
82
|
+
}"
|
83
|
+
}
|
84
|
+
|
85
|
+
it 'should not detect any problems' do
|
86
|
+
expect(problems).to have(0).problems
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'defined type with no variables declared accessing top scope' do
|
91
|
+
let(:code) { "
|
92
|
+
define foo() {
|
93
|
+
$bar = $fqdn
|
94
|
+
}"
|
95
|
+
}
|
96
|
+
|
97
|
+
it 'should only detect a single problem' do
|
98
|
+
expect(problems).to have(1).problem
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should create a warning' do
|
102
|
+
expect(problems).to contain_warning(msg).on_line(3).in_column(16)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'defined type with no variables declared accessing top scope explicitly' do
|
107
|
+
let(:code) { "
|
108
|
+
define foo() {
|
109
|
+
$bar = $::fqdn
|
110
|
+
}"
|
111
|
+
}
|
112
|
+
|
113
|
+
it 'should not detect any problems' do
|
114
|
+
expect(problems).to have(0).problems
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context '$name should be auto defined' do
|
119
|
+
let(:code) { "
|
120
|
+
define foo() {
|
121
|
+
$bar = $name
|
122
|
+
$baz = $title
|
123
|
+
$gronk = $module_name
|
124
|
+
$meep = $1
|
125
|
+
}"
|
126
|
+
}
|
127
|
+
|
128
|
+
it 'should not detect any problems' do
|
129
|
+
expect(problems).to have(0).problems
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
context 'define with required parameter' do
|
134
|
+
let(:code) { "
|
135
|
+
define tomcat::base (
|
136
|
+
$max_perm_gen,
|
137
|
+
$owner = hiera('app_user'),
|
138
|
+
$system_properties = {},
|
139
|
+
) { }"
|
140
|
+
}
|
141
|
+
|
142
|
+
it 'should not detect any problems' do
|
143
|
+
expect(problems).to have(0).problems
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'future parser blocks' do
|
148
|
+
let(:code) { "
|
149
|
+
class foo() {
|
150
|
+
$foo = [1,2]
|
151
|
+
$foo.each |$a, $b| {
|
152
|
+
$a
|
153
|
+
$c
|
154
|
+
}
|
155
|
+
$b
|
156
|
+
}
|
157
|
+
" }
|
158
|
+
|
159
|
+
it 'should only detect a single problem' do
|
160
|
+
expect(problems).to have(2).problem
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'should create two warnings' do
|
164
|
+
expect(problems).to contain_warning(msg).on_line(8).in_column(9)
|
165
|
+
expect(problems).to contain_warning(msg).on_line(6).in_column(11)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
%w{alias audit before loglevel noop notify require schedule stage subscribe tag}.each do |metaparam|
|
170
|
+
context "referencing #{metaparam} metaparam value as a variable" do
|
171
|
+
let(:code) { "
|
172
|
+
class foo() {
|
173
|
+
$#{metaparam}
|
174
|
+
}
|
175
|
+
" }
|
176
|
+
|
177
|
+
it 'should not detect any problems' do
|
178
|
+
expect(problems).to have(0).problems
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
183
|
+
context 'support the use of facts and trusted facts for Puppet 3.5 onwards' do
|
184
|
+
let(:code) { "
|
185
|
+
class foo() {
|
186
|
+
if $facts['osfamily'] == 'redhat' or $trusted['osfamily'] == 'redhat' {
|
187
|
+
$redhat = true
|
188
|
+
}
|
189
|
+
}
|
190
|
+
" }
|
191
|
+
|
192
|
+
it 'should not detect any problems' do
|
193
|
+
expect(problems).to have(0).problems
|
194
|
+
end
|
195
|
+
end
|
196
|
+
end
|