puppet-lint 0.4.0.pre1 → 1.0.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.
Files changed (70) hide show
  1. data/.travis.yml +3 -4
  2. data/Gemfile +2 -5
  3. data/README.md +2 -149
  4. data/Rakefile +0 -5
  5. data/lib/puppet-lint.rb +74 -20
  6. data/lib/puppet-lint/bin.rb +20 -85
  7. data/lib/puppet-lint/checkplugin.rb +158 -12
  8. data/lib/puppet-lint/checks.rb +39 -222
  9. data/lib/puppet-lint/configuration.rb +12 -31
  10. data/lib/puppet-lint/data.rb +329 -0
  11. data/lib/puppet-lint/lexer.rb +37 -30
  12. data/lib/puppet-lint/lexer/token.rb +14 -16
  13. data/lib/puppet-lint/monkeypatches/string_prepend.rb +6 -0
  14. data/lib/puppet-lint/optparser.rb +105 -0
  15. data/lib/puppet-lint/plugins.rb +28 -9
  16. data/lib/puppet-lint/plugins/check_classes.rb +162 -238
  17. data/lib/puppet-lint/plugins/check_comments.rb +40 -25
  18. data/lib/puppet-lint/plugins/check_conditionals.rb +16 -20
  19. data/lib/puppet-lint/plugins/check_documentation.rb +14 -20
  20. data/lib/puppet-lint/plugins/check_nodes.rb +23 -0
  21. data/lib/puppet-lint/plugins/check_resources.rb +127 -141
  22. data/lib/puppet-lint/plugins/check_strings.rb +133 -107
  23. data/lib/puppet-lint/plugins/check_variables.rb +11 -11
  24. data/lib/puppet-lint/plugins/check_whitespace.rb +86 -92
  25. data/lib/puppet-lint/tasks/puppet-lint.rb +17 -1
  26. data/lib/puppet-lint/version.rb +1 -1
  27. data/puppet-lint.gemspec +4 -2
  28. data/spec/fixtures/test/manifests/ignore.pp +1 -0
  29. data/spec/fixtures/test/manifests/ignore_reason.pp +1 -0
  30. data/spec/puppet-lint/bin_spec.rb +104 -84
  31. data/spec/puppet-lint/configuration_spec.rb +19 -19
  32. data/spec/puppet-lint/ignore_overrides_spec.rb +97 -0
  33. data/spec/puppet-lint/lexer/token_spec.rb +9 -9
  34. data/spec/puppet-lint/lexer_spec.rb +352 -325
  35. data/spec/puppet-lint/plugins/check_classes/autoloader_layout_spec.rb +77 -23
  36. data/spec/puppet-lint/plugins/check_classes/class_inherits_from_params_class_spec.rb +14 -12
  37. data/spec/puppet-lint/plugins/check_classes/inherits_across_namespaces_spec.rb +18 -14
  38. data/spec/puppet-lint/plugins/check_classes/names_containing_dash_spec.rb +30 -30
  39. data/spec/puppet-lint/plugins/check_classes/nested_classes_or_defines_spec.rb +31 -26
  40. data/spec/puppet-lint/plugins/check_classes/parameter_order_spec.rb +34 -28
  41. data/spec/puppet-lint/plugins/check_classes/right_to_left_relationship_spec.rb +14 -12
  42. data/spec/puppet-lint/plugins/check_classes/variable_scope_spec.rb +74 -30
  43. data/spec/puppet-lint/plugins/check_comments/slash_comments_spec.rb +27 -20
  44. data/spec/puppet-lint/plugins/check_comments/star_comments_spec.rb +78 -13
  45. data/spec/puppet-lint/plugins/check_conditionals/case_without_default_spec.rb +17 -12
  46. data/spec/puppet-lint/plugins/check_conditionals/selector_inside_resource_spec.rb +13 -10
  47. data/spec/puppet-lint/plugins/check_documentation/documentation_spec.rb +21 -16
  48. data/spec/puppet-lint/plugins/check_nodes/unquoted_node_name_spec.rb +69 -0
  49. data/spec/puppet-lint/plugins/check_resources/duplicate_params_spec.rb +42 -38
  50. data/spec/puppet-lint/plugins/check_resources/ensure_first_param_spec.rb +22 -10
  51. data/spec/puppet-lint/plugins/check_resources/ensure_not_symlink_target_spec.rb +81 -18
  52. data/spec/puppet-lint/plugins/check_resources/file_mode_spec.rb +69 -112
  53. data/spec/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb +27 -20
  54. data/spec/puppet-lint/plugins/check_resources/unquoted_resource_title_spec.rb +177 -171
  55. data/spec/puppet-lint/plugins/check_strings/double_quoted_strings_spec.rb +165 -88
  56. data/spec/puppet-lint/plugins/check_strings/only_variable_string_spec.rb +97 -22
  57. data/spec/puppet-lint/plugins/check_strings/puppet_url_without_modules_spec.rb +25 -0
  58. data/spec/puppet-lint/plugins/check_strings/quoted_booleans_spec.rb +97 -111
  59. data/spec/puppet-lint/plugins/check_strings/single_quote_string_with_variables_spec.rb +10 -9
  60. data/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +53 -53
  61. data/spec/puppet-lint/plugins/check_variables/variable_contains_dash_spec.rb +26 -14
  62. data/spec/puppet-lint/plugins/check_whitespace/2sp_soft_tabs_spec.rb +10 -9
  63. data/spec/puppet-lint/plugins/check_whitespace/80chars_spec.rb +31 -15
  64. data/spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb +340 -322
  65. data/spec/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb +30 -23
  66. data/spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb +42 -41
  67. data/spec/puppet-lint_spec.rb +3 -3
  68. data/spec/spec_helper.rb +109 -116
  69. metadata +109 -50
  70. data/spec/puppet-lint/plugins/check_classes/class_parameter_defaults_spec.rb +0 -60
@@ -1,20 +1,23 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'unquoted_file_mode' do
4
- describe '4 digit unquoted file mode' do
5
- let(:code) { "file { 'foo': mode => 0777 }" }
6
-
7
- its(:problems) do
8
- should only_have_problem(
9
- :kind => :warning,
10
- :message => "unquoted file mode",
11
- :linenumber => 1,
12
- :column => 23,
13
- )
4
+ let(:msg) { 'unquoted file mode' }
5
+
6
+ context 'with fix disabled' do
7
+ context '4 digit unquoted file mode' do
8
+ let(:code) { "file { 'foo': mode => 0777 }" }
9
+
10
+ it 'should only detect a single problem' do
11
+ expect(problems).to have(1).problem
12
+ end
13
+
14
+ it 'should create a warning' do
15
+ expect(problems).to contain_warning(msg).on_line(1).in_column(23)
16
+ end
14
17
  end
15
18
  end
16
19
 
17
- describe '4 digit unquoted file mode w/fix' do
20
+ context 'with fix enabled' do
18
21
  before do
19
22
  PuppetLint.configuration.fix = true
20
23
  end
@@ -23,16 +26,20 @@ describe 'unquoted_file_mode' do
23
26
  PuppetLint.configuration.fix = false
24
27
  end
25
28
 
26
- let(:code) { "file { 'foo': mode => 0777 }" }
29
+ context '4 digit unquoted file mode w/fix' do
30
+ let(:code) { "file { 'foo': mode => 0777 }" }
31
+
32
+ it 'should only detect a single problem' do
33
+ expect(problems).to have(1).problem
34
+ end
35
+
36
+ it 'should fix the manifest' do
37
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(23)
38
+ end
27
39
 
28
- its(:problems) do
29
- should only_have_problem(
30
- :kind => :fixed,
31
- :message => "unquoted file mode",
32
- :linenumber => 1,
33
- :column => 23,
34
- )
40
+ it 'should single quote the file mode' do
41
+ expect(manifest).to eq("file { 'foo': mode => '0777' }")
42
+ end
35
43
  end
36
- its(:manifest) { should == "file { 'foo': mode => '0777' }" }
37
44
  end
38
45
  end
@@ -1,132 +1,144 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'unquoted_resource_title' do
4
- describe 'quoted resource title on single line resource' do
5
- let(:code) { "file { 'foo': }" }
4
+ let(:msg) { 'unquoted resource title' }
6
5
 
7
- its(:problems) { should be_empty }
8
- end
9
-
10
- describe 'unquoted resource title on single line resource' do
11
- let(:code) { "file { foo: }" }
12
-
13
- its(:problems) {
14
- should only_have_problem(
15
- :kind => :warning,
16
- :message => "unquoted resource title",
17
- :linenumber => 1,
18
- :column => 8,
19
- )
20
- }
21
- end
6
+ context 'with fix disabled' do
7
+ context 'quoted resource title on single line resource' do
8
+ let(:code) { "file { 'foo': }" }
22
9
 
23
- describe 'unquoted resource title on single line resource w/fix' do
24
- before do
25
- PuppetLint.configuration.fix = true
10
+ it 'should not detect any problems' do
11
+ expect(problems).to have(0).problems
12
+ end
26
13
  end
27
14
 
28
- after do
29
- PuppetLint.configuration.fix = false
15
+ context 'unquoted resource title on single line resource' do
16
+ let(:code) { "file { foo: }" }
17
+
18
+ it 'should only detect a single problem' do
19
+ expect(problems).to have(1).problem
20
+ end
21
+
22
+ it 'should create a warning' do
23
+ expect(problems).to contain_warning(msg).on_line(1).in_column(8)
24
+ end
30
25
  end
31
26
 
32
- let(:code) { "file { foo: }" }
27
+ context 'quoted resource title on multi line resource' do
28
+ let(:code) { "
29
+ file { 'foo':
30
+ }"
31
+ }
33
32
 
34
- its(:problems) {
35
- should only_have_problem(
36
- :kind => :fixed,
37
- :message => "unquoted resource title",
38
- :linenumber => 1,
39
- :column => 8,
40
- )
41
- }
33
+ it 'should not detect any problems' do
34
+ expect(problems).to have(0).problems
35
+ end
36
+ end
42
37
 
43
- its(:manifest) { should == "file { 'foo': }" }
44
- end
38
+ context 'unquoted resource title on multi line resource' do
39
+ let(:code) { "
40
+ file { foo:
41
+ }"
42
+ }
45
43
 
46
- describe 'quoted resource title on multi line resource' do
47
- let(:code) { "
48
- file { 'foo':
49
- }"
50
- }
44
+ it 'should only detect a single problem' do
45
+ expect(problems).to have(1).problem
46
+ end
51
47
 
52
- its(:problems) { should be_empty }
53
- end
48
+ it 'should create a warning' do
49
+ expect(problems).to contain_warning(msg).on_line(2).in_column(16)
50
+ end
51
+ end
54
52
 
55
- describe 'unquoted resource title on multi line resource' do
56
- let(:code) { "
57
- file { foo:
58
- }"
59
- }
60
-
61
- its(:problems) {
62
- should only_have_problem(
63
- :kind => :warning,
64
- :message => "unquoted resource title",
65
- :linenumber => 2,
66
- :column => 14,
67
- )
68
- }
69
- end
53
+ context 'condensed resources with quoted titles' do
54
+ let(:code) { "
55
+ file {
56
+ 'foo': ;
57
+ 'bar': ;
58
+ }"
59
+ }
60
+
61
+ it 'should not detect any problems' do
62
+ expect(problems).to have(0).problems
63
+ end
64
+ end
70
65
 
71
- describe 'unquoted resource title on multi line resource w/fix' do
72
- before do
73
- PuppetLint.configuration.fix = true
66
+ context 'condensed resources with an unquoted title' do
67
+ let(:code) { "
68
+ file {
69
+ 'foo': ;
70
+ bar: ;
71
+ }"
72
+ }
73
+
74
+ it 'should only detect a single problem' do
75
+ expect(problems).to have(1).problem
76
+ end
77
+
78
+ it 'should create a warning' do
79
+ expect(problems).to contain_warning(msg).on_line(4).in_column(11)
80
+ end
74
81
  end
75
82
 
76
- after do
77
- PuppetLint.configuration.fix = false
83
+ context 'single line resource with an array of titles (all quoted)' do
84
+ let(:code) { "file { ['foo', 'bar']: }" }
85
+
86
+ it 'should not detect any problems' do
87
+ expect(problems).to have(0).problems
88
+ end
78
89
  end
79
90
 
80
- let(:code) { "
81
- file { foo:
82
- }"
83
- }
84
-
85
- its(:problems) {
86
- should only_have_problem(
87
- :kind => :fixed,
88
- :message => "unquoted resource title",
89
- :linenumber => 2,
90
- :column => 14,
91
- )
92
- }
93
-
94
- its(:manifest) { should == "
95
- file { 'foo':
96
- }"
97
- }
98
- end
91
+ context 'resource inside a case statement' do
92
+ let(:code) { "
93
+ case $ensure {
94
+ 'absent': {
95
+ file { \"some_file_${name}\":
96
+ ensure => absent,
97
+ }
98
+ }
99
+ }"
100
+ }
99
101
 
100
- describe 'condensed resources with quoted titles' do
101
- let(:code) { "
102
- file {
103
- 'foo': ;
104
- 'bar': ;
105
- }"
106
- }
102
+ it 'should not detect any problems' do
103
+ expect(problems).to have(0).problems
104
+ end
105
+ end
107
106
 
108
- its(:problems) { should be_empty }
109
- end
107
+ context 'issue #116' do
108
+ let(:code) { "
109
+ $config_file_init = $::operatingsystem ? {
110
+ /(?i:Debian|Ubuntu|Mint)/ => '/etc/default/foo',
111
+ default => '/etc/sysconfig/foo',
112
+ }"
113
+ }
114
+
115
+ it 'should not detect any problems' do
116
+ expect(problems).to have(0).problems
117
+ end
118
+ end
110
119
 
111
- describe 'condensed resources with an unquoted title' do
112
- let(:code) { "
113
- file {
114
- 'foo': ;
115
- bar: ;
116
- }"
117
- }
118
-
119
- its(:problems) {
120
- should only_have_problem(
121
- :kind => :warning,
122
- :message => "unquoted resource title",
123
- :linenumber => 4,
124
- :column => 9,
125
- )
126
- }
120
+ context 'case statement' do
121
+ let(:code) { %{
122
+ case $operatingsystem {
123
+ centos: {
124
+ $version = '1.2.3'
125
+ }
126
+ solaris: {
127
+ $version = '3.2.1'
128
+ }
129
+ default: {
130
+ fail("Module ${module_name} is not supported on ${operatingsystem}")
131
+ }
132
+ }}
133
+ }
134
+
135
+ it 'should not detect any problems' do
136
+ expect(problems).to have(0).problems
137
+ end
138
+ end
127
139
  end
128
140
 
129
- describe 'condensed resources with an unquoted title w/fix' do
141
+ context 'with fix enabled' do
130
142
  before do
131
143
  PuppetLint.configuration.fix = true
132
144
  end
@@ -135,76 +147,70 @@ describe 'unquoted_resource_title' do
135
147
  PuppetLint.configuration.fix = false
136
148
  end
137
149
 
138
- let(:code) { "
139
- file {
140
- 'foo': ;
141
- bar: ;
142
- }"
143
- }
144
-
145
- its(:problems) {
146
- should only_have_problem(
147
- :kind => :fixed,
148
- :message => "unquoted resource title",
149
- :linenumber => 4,
150
- :column => 9,
151
- )
152
- }
153
-
154
- its(:manifest) { should == "
155
- file {
156
- 'foo': ;
157
- 'bar': ;
158
- }"
159
- }
160
- end
161
-
162
- describe 'single line resource with an array of titles (all quoted)' do
163
- let(:code) { "file { ['foo', 'bar']: }" }
150
+ context 'unquoted resource title on single line resource' do
151
+ let(:code) { "file { foo: }" }
164
152
 
165
- its(:problems) { should be_empty }
166
- end
167
-
168
- describe 'resource inside a case statement' do
169
- let(:code) { "
170
- case $ensure {
171
- 'absent': {
172
- file { \"some_file_${name}\":
173
- ensure => absent,
174
- }
175
- }
176
- }"
177
- }
153
+ it 'should only detect a single problem' do
154
+ expect(problems).to have(1).problem
155
+ end
178
156
 
179
- its(:problems) { should == [] }
180
- end
157
+ it 'should fix the manifest' do
158
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(8)
159
+ end
181
160
 
182
- describe 'issue #116' do
183
- let(:code) { "
184
- $config_file_init = $::operatingsystem ? {
185
- /(?i:Debian|Ubuntu|Mint)/ => '/etc/default/foo',
186
- default => '/etc/sysconfig/foo',
187
- }"
188
- }
161
+ it 'should single quote the resource title' do
162
+ expect(manifest).to eq("file { 'foo': }")
163
+ end
164
+ end
189
165
 
190
- its(:problems) { should == [] }
191
- end
166
+ context 'unquoted resource title on multi line resource' do
167
+ let(:code) { "
168
+ file { foo:
169
+ }"
170
+ }
171
+ let(:fixed) { "
172
+ file { 'foo':
173
+ }"
174
+ }
175
+
176
+ it 'should only detect a single problem' do
177
+ expect(problems).to have(1).problem
178
+ end
179
+
180
+ it 'should fix the manifest' do
181
+ expect(problems).to contain_fixed(msg).on_line(2).in_column(16)
182
+ end
183
+
184
+ it 'should single quote the resource title' do
185
+ expect(manifest).to eq(fixed)
186
+ end
187
+ end
192
188
 
193
- describe 'case statement' do
194
- let(:code) { %{
195
- case $operatingsystem {
196
- centos: {
197
- $version = '1.2.3'
198
- }
199
- solaris: {
200
- $version = '3.2.1'
201
- }
202
- default: {
203
- fail("Module ${module_name} is not supported on ${operatingsystem}")
204
- }
205
- }}
206
- }
207
-
208
- its(:problems) { should == [] }
189
+ context 'condensed resources with an unquoted title' do
190
+ let(:code) { "
191
+ file {
192
+ 'foo': ;
193
+ bar: ;
194
+ }"
195
+ }
196
+ let(:fixed) { "
197
+ file {
198
+ 'foo': ;
199
+ 'bar': ;
200
+ }"
201
+ }
202
+
203
+ it 'should only detect a single problem' do
204
+ expect(problems).to have(1).problem
205
+ end
206
+
207
+ it 'should fix the manifest' do
208
+ expect(problems).to contain_fixed(msg).on_line(4).in_column(11)
209
+ end
210
+
211
+ it 'should single quote the resource title' do
212
+ expect(manifest).to eq(fixed)
213
+ end
214
+ end
209
215
  end
210
216
  end
@@ -1,43 +1,141 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'double_quoted_strings' do
4
- describe 'double quoted string containing a variable inside single quotes' do
5
- let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
4
+ let(:msg) { 'double quoted string containing no variables' }
6
5
 
7
- its(:problems) { should be_empty }
8
- end
6
+ context 'with fix disabled' do
7
+ context 'double quoted string containing a variable inside single quotes' do
8
+ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
9
9
 
10
- describe 'double quoted string containing a variable inside single quotes w/fix' do
11
- before do
12
- PuppetLint.configuration.fix = true
10
+ it 'should not detect any problems' do
11
+ expect(problems).to have(0).problems
12
+ end
13
13
  end
14
14
 
15
- after do
16
- PuppetLint.configuration.fix = false
15
+ context 'multiple strings in a line' do
16
+ let(:code) { "\"aoeu\" '${foo}'" }
17
+
18
+ it 'should only detect a single problem' do
19
+ expect(problems).to have(1).problem
20
+ end
21
+
22
+ it 'should create a warning' do
23
+ expect(problems).to contain_warning(msg).on_line(1).in_column(1)
24
+ end
17
25
  end
18
26
 
19
- let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
27
+ context 'double quoted string nested in a single quoted string' do
28
+ let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
20
29
 
21
- its(:problems) { should be_empty }
22
- its(:manifest) {
23
- should == "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }"
24
- }
25
- end
30
+ it 'should not detect any problems' do
31
+ expect(problems).to have(0).problems
32
+ end
33
+ end
34
+
35
+ context 'double quoted string after a comment' do
36
+ let(:code) { "service { 'foo': } # \"bar\"" }
37
+
38
+ it 'should not detect any problems' do
39
+ expect(problems).to have(0).problems
40
+ end
41
+ end
42
+
43
+ context 'double quoted string containing newline but no variables' do
44
+ let(:code) { %{"foo\n"} }
45
+
46
+ it 'should not detect any problems' do
47
+ expect(problems).to have(0).problems
48
+ end
49
+ end
50
+
51
+ context 'double quoted string with backslash for continuation' do
52
+ let(:code) { %{
53
+ class puppet::master::maintenance (
54
+ ) {
55
+ cron { 'puppet_master_reports_cleanup':
56
+ command => "/usr/bin/find /var/lib/puppet/reports -type f -mtime +15 \
57
+ -delete && /usr/bin/find /var/lib/puppet/reports -mindepth 1 \
58
+ -empty -type d -delete",
59
+ minute => '15',
60
+ hour => '5',
61
+ }
62
+ }
63
+ } }
64
+
65
+ it 'should not detect any problems' do
66
+ expect(problems).to have(0).problems
67
+ end
68
+ end
69
+
70
+ context 'double quoted true' do
71
+ let(:code) { "class { 'foo': boolFlag => \"true\" }" }
72
+
73
+ it 'should only detect a single problem' do
74
+ expect(problems).to have(1).problem
75
+ end
76
+
77
+ it 'should create a warning' do
78
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
79
+ end
80
+ end
81
+
82
+ context 'double quoted false' do
83
+ let(:code) { "class { 'foo': boolFlag => \"false\" }" }
84
+
85
+ it 'should only detect a single problem' do
86
+ expect(problems).to have(1).problem
87
+ end
26
88
 
27
- describe 'multiple strings in a line' do
28
- let(:code) { "\"aoeu\" '${foo}'" }
29
-
30
- its(:problems) {
31
- should have_problem({
32
- :kind => :warning,
33
- :message => 'double quoted string containing no variables',
34
- :linenumber => 1,
35
- :column => 1,
36
- })
37
- }
89
+ it 'should create a warning' do
90
+ expect(problems).to contain_warning(msg).on_line(1).in_column(28)
91
+ end
92
+ end
93
+
94
+ context 'double quoted stings containing supported escape patterns' do
95
+ let(:code) {%{
96
+ $string1 = "this string contins \n newline"
97
+ $string2 = "this string contains \ttab"
98
+ $string3 = "this string contains \${escaped} var"
99
+ $string4 = "this string contains \\"escaped \\" double quotes"
100
+ $string5 = "this string contains \\'escaped \\' single quotes"
101
+ $string6 = "this string contains \r line return"
102
+ }}
103
+
104
+ it 'should not detect any problems' do
105
+ expect(problems).to have(0).problems
106
+ end
107
+ end
108
+
109
+ context 'double quoted string with random escape should be rejected' do
110
+ let(:code) {%{ $ztring = "this string contains \l random esape" } }
111
+
112
+ it 'should only detect a single problem' do
113
+ expect(problems).to have(1).problem
114
+ end
115
+
116
+ it 'should create a warning' do
117
+ expect(problems).to contain_warning(msg).on_line(1).in_column(12)
118
+ end
119
+ end
120
+
121
+ context 'single quotes in a double quoted string' do
122
+ let(:code) { "\"this 'string' 'has' lots of 'quotes'\"" }
123
+
124
+ it 'should not detect any problems' do
125
+ expect(problems).to have(0).problems
126
+ end
127
+ end
128
+
129
+ context 'double quoted string containing single quoted string' do
130
+ let(:code) { %[notify { "'foo'": }] }
131
+
132
+ it 'should not detect any problems' do
133
+ expect(problems).to have(0).problems
134
+ end
135
+ end
38
136
  end
39
137
 
40
- describe 'multiple strings in a line w/fix' do
138
+ context 'with fix enabled' do
41
139
  before do
42
140
  PuppetLint.configuration.fix = true
43
141
  end
@@ -46,77 +144,56 @@ describe 'double_quoted_strings' do
46
144
  PuppetLint.configuration.fix = false
47
145
  end
48
146
 
49
- let(:code) { "\"aoeu\" '${foo}'" }
147
+ context 'double quoted string containing a variable inside single quotes' do
148
+ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
50
149
 
51
- its(:problems) {
52
- should have_problem({
53
- :kind => :fixed,
54
- :message => 'double quoted string containing no variables',
55
- :linenumber => 1,
56
- :column => 1,
57
- })
58
- }
59
- its(:manifest) { should == "'aoeu' '${foo}'" }
60
- end
150
+ it 'should not detect any problems' do
151
+ expect(problems).to have(0).problems
152
+ end
61
153
 
62
- describe 'double quoted string nested in a single quoted string' do
63
- let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
154
+ it 'should not modify the manifest' do
155
+ expect(manifest).to eq(code)
156
+ end
157
+ end
64
158
 
65
- its(:problems) { should be_empty }
66
- end
159
+ context 'double quoted string containing a lone dollar' do
160
+ let(:code) {"\"sed -i 's/^;*[[:space:]]*${name}[[:space:]]*=.*$/${name} = ${value}/g' file\"" }
67
161
 
68
- describe 'double quoted string after a comment' do
69
- let(:code) { "service { 'foo': } # \"bar\"" }
162
+ it 'should not detect any problems' do
163
+ expect(problems).to have(0).problems
164
+ end
70
165
 
71
- its(:problems) { should be_empty }
72
- end
166
+ it 'should not modify the manifest' do
167
+ expect(manifest).to eq(code)
168
+ end
169
+ end
73
170
 
74
- describe 'double quoted string containing newline but no variables' do
75
- let(:code) { %{"foo\n"} }
171
+ context 'multiple strings in a line' do
172
+ let(:code) { "\"aoeu\" '${foo}'" }
76
173
 
77
- its(:problems) { should be_empty }
78
- end
174
+ it 'should only detect a single problem' do
175
+ expect(problems).to have(1).problem
176
+ end
79
177
 
80
- describe 'double quoted string with backslash for continuation' do
81
- let(:code) { %{
82
- class puppet::master::maintenance (
83
- ) {
84
- cron { 'puppet_master_reports_cleanup':
85
- command => "/usr/bin/find /var/lib/puppet/reports -type f -mtime +15 \
86
- -delete && /usr/bin/find /var/lib/puppet/reports -mindepth 1 \
87
- -empty -type d -delete",
88
- minute => '15',
89
- hour => '5',
90
- }
91
- }
92
- } }
178
+ it 'should fix the manifest' do
179
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
180
+ end
93
181
 
94
- its(:problems) { should == [] }
95
- end
182
+ it 'should convert the double quoted string into single quotes' do
183
+ expect(manifest).to eq("'aoeu' '${foo}'")
184
+ end
185
+ end
96
186
 
97
- describe 'double quoted true' do
98
- let(:code) { "class { 'foo': boolFlag => \"true\" }" }
99
-
100
- its(:problems) {
101
- should have_problem({
102
- :kind => :warning,
103
- :message => 'double quoted string containing no variables',
104
- :linenumber => 1,
105
- :column => 28,
106
- })
107
- }
108
- end
187
+ context 'single quotes in a double quoted string' do
188
+ let(:code) { "\"this 'string' 'has' lots of 'quotes'\"" }
189
+
190
+ it 'should not detect any problems' do
191
+ expect(problems).to have(0).problems
192
+ end
109
193
 
110
- describe 'double quoted false' do
111
- let(:code) { "class { 'foo': boolFlag => \"false\" }" }
112
-
113
- its(:problems) {
114
- should have_problem({
115
- :kind => :warning,
116
- :message => 'double quoted string containing no variables',
117
- :linenumber => 1,
118
- :column => 28,
119
- })
120
- }
194
+ it 'should not modify the manifest' do
195
+ expect(manifest).to eq(code)
196
+ end
197
+ end
121
198
  end
122
199
  end