puppet-lint 0.2.0.pre1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +1 -14
- data/Gemfile +2 -0
- data/Rakefile +5 -0
- data/bin/puppet-lint +1 -99
- data/lib/puppet-lint.rb +4 -12
- data/lib/puppet-lint/bin.rb +115 -0
- data/lib/puppet-lint/configuration.rb +6 -2
- data/lib/puppet-lint/lexer.rb +135 -83
- data/lib/puppet-lint/lexer/token.rb +62 -0
- data/lib/puppet-lint/plugin.rb +57 -51
- data/lib/puppet-lint/plugins.rb +2 -0
- data/lib/puppet-lint/plugins/check_classes.rb +161 -45
- data/lib/puppet-lint/plugins/check_comments.rb +33 -0
- data/lib/puppet-lint/plugins/check_conditionals.rb +8 -10
- data/lib/puppet-lint/plugins/check_documentation.rb +41 -0
- data/lib/puppet-lint/plugins/check_resources.rb +28 -2
- data/lib/puppet-lint/plugins/check_strings.rb +6 -4
- data/lib/puppet-lint/plugins/check_variables.rb +1 -1
- data/lib/puppet-lint/plugins/check_whitespace.rb +26 -49
- data/lib/puppet-lint/tasks/puppet-lint.rb +2 -1
- data/lib/puppet-lint/version.rb +1 -1
- data/puppet-lint.gemspec +1 -0
- data/spec/fixtures/test/manifests/fail.pp +2 -0
- data/spec/fixtures/test/manifests/init.pp +3 -0
- data/spec/fixtures/test/manifests/warning.pp +2 -0
- data/spec/puppet-lint/bin_spec.rb +266 -0
- data/spec/puppet-lint/configuration_spec.rb +51 -0
- data/spec/puppet-lint/lexer/token_spec.rb +18 -0
- data/spec/puppet-lint/lexer_spec.rb +738 -0
- data/spec/puppet-lint/{check_classes_spec.rb → plugins/check_classes_spec.rb} +74 -7
- data/spec/puppet-lint/plugins/check_comments_spec.rb +40 -0
- data/spec/puppet-lint/{check_conditionals_spec.rb → plugins/check_conditionals_spec.rb} +19 -0
- data/spec/puppet-lint/plugins/check_documentation_spec.rb +55 -0
- data/spec/puppet-lint/{check_resources_spec.rb → plugins/check_resources_spec.rb} +65 -0
- data/spec/puppet-lint/{check_strings_spec.rb → plugins/check_strings_spec.rb} +18 -1
- data/spec/puppet-lint/{check_variables_spec.rb → plugins/check_variables_spec.rb} +0 -0
- data/spec/puppet-lint/plugins/check_whitespace_spec.rb +291 -0
- data/spec/puppet-lint_spec.rb +10 -0
- data/spec/spec_helper.rb +5 -0
- metadata +58 -24
- data/spec/puppet-lint/check_whitespace_spec.rb +0 -120
@@ -0,0 +1,33 @@
|
|
1
|
+
class PuppetLint::Plugins::CheckComments < PuppetLint::CheckPlugin
|
2
|
+
# Public: Check the manifest tokens for any comments started with slashes
|
3
|
+
# (//) and record a warning for each instance found.
|
4
|
+
#
|
5
|
+
# Returns nothing.
|
6
|
+
check 'slash_comments' do
|
7
|
+
tokens.select { |token|
|
8
|
+
token.type == :SLASH_COMMENT
|
9
|
+
}.each do |token|
|
10
|
+
notify :warning, {
|
11
|
+
:message => '// comment found',
|
12
|
+
:linenumber => token.line,
|
13
|
+
:column => token.column,
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Public: Check the manifest tokens for any comments encapsulated with
|
19
|
+
# slash-asterisks (/* */) and record a warning for each instance found.
|
20
|
+
#
|
21
|
+
# Returns nothing.
|
22
|
+
check 'star_comments' do
|
23
|
+
tokens.select { |token|
|
24
|
+
token.type == :MLCOMMENT
|
25
|
+
}.each do |token|
|
26
|
+
notify :warning, {
|
27
|
+
:message => '/* */ comment found',
|
28
|
+
:linenumber => token.line,
|
29
|
+
:column => token.column,
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -5,19 +5,17 @@ class PuppetLint::Plugins::CheckConditionals < PuppetLint::CheckPlugin
|
|
5
5
|
# Returns nothing.
|
6
6
|
check 'selector_inside_resource' do
|
7
7
|
resource_indexes.each do |resource|
|
8
|
-
resource_tokens = tokens[resource[:start]..resource[:end]]
|
9
|
-
formatting_tokens.include? r.type
|
10
|
-
}
|
8
|
+
resource_tokens = tokens[resource[:start]..resource[:end]]
|
11
9
|
|
12
|
-
resource_tokens.
|
13
|
-
if
|
14
|
-
if
|
15
|
-
unless
|
16
|
-
if
|
10
|
+
resource_tokens.each do |token|
|
11
|
+
if token.type == :FARROW
|
12
|
+
if token.next_code_token.type == :VARIABLE
|
13
|
+
unless token.next_code_token.next_code_token.nil?
|
14
|
+
if token.next_code_token.next_code_token.type == :QMARK
|
17
15
|
notify :warning, {
|
18
16
|
:message => 'selector inside resource block',
|
19
|
-
:linenumber =>
|
20
|
-
:column =>
|
17
|
+
:linenumber => token.line,
|
18
|
+
:column => token.column,
|
21
19
|
}
|
22
20
|
end
|
23
21
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class PuppetLint::Plugins::CheckDocumentation < PuppetLint::CheckPlugin
|
2
|
+
def whitespace_tokens
|
3
|
+
@whitespace_tokens ||= {
|
4
|
+
:WHITESPACE => true,
|
5
|
+
:NEWLINE => true,
|
6
|
+
:INDENT => true,
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
def comment_tokens
|
11
|
+
@comment_tokens ||= {
|
12
|
+
:COMMENT => true,
|
13
|
+
:MLCOMMENT => true,
|
14
|
+
:SLASH_COMMENT => true,
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
check 'documentation' do
|
19
|
+
(class_indexes + defined_type_indexes).each do |item_idx|
|
20
|
+
prev_token = tokens[item_idx[:start] - 1]
|
21
|
+
while whitespace_tokens.include? prev_token.type
|
22
|
+
prev_token = prev_token.prev_token
|
23
|
+
end
|
24
|
+
|
25
|
+
unless comment_tokens.include? prev_token.type
|
26
|
+
first_token = tokens[item_idx[:start]]
|
27
|
+
if first_token.type == :CLASS
|
28
|
+
type = 'class'
|
29
|
+
else
|
30
|
+
type = 'defined type'
|
31
|
+
end
|
32
|
+
|
33
|
+
notify :warning, {
|
34
|
+
:message => "#{type} not documented",
|
35
|
+
:linenumber => first_token.line,
|
36
|
+
:column => first_token.column,
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -43,6 +43,31 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
+
check 'duplicate_params' do
|
47
|
+
resource_indexes.each do |resource|
|
48
|
+
resource_tokens = tokens[resource[:start]..resource[:end]].reject { |r|
|
49
|
+
formatting_tokens.include? r.type
|
50
|
+
}
|
51
|
+
|
52
|
+
seen_params = {}
|
53
|
+
resource_tokens.each_with_index do |token, idx|
|
54
|
+
if token.type == :FARROW
|
55
|
+
prev_token = resource_tokens[idx - 1]
|
56
|
+
next unless prev_token.type == :NAME
|
57
|
+
if seen_params.include? prev_token.value
|
58
|
+
notify :error, {
|
59
|
+
:message => 'duplicate parameter found in resource',
|
60
|
+
:linenumber => prev_token.line,
|
61
|
+
:column => prev_token.column,
|
62
|
+
}
|
63
|
+
else
|
64
|
+
seen_params[prev_token.value] = true
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
46
71
|
# Public: Check the tokens of each File resource instance for a mode
|
47
72
|
# parameter and if found, record a warning if the value of that parameter is
|
48
73
|
# not a quoted string.
|
@@ -68,7 +93,7 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
|
|
68
93
|
attr_token = resource_tokens[resource_token_idx]
|
69
94
|
if attr_token.type == :NAME and attr_token.value == 'mode'
|
70
95
|
value_token = resource_tokens[resource_token_idx + 2]
|
71
|
-
if value_token.type
|
96
|
+
if {:NAME => true, :NUMBER => true}.include? value_token.type
|
72
97
|
notify :warning, {
|
73
98
|
:message => 'unquoted file mode',
|
74
99
|
:linenumber => value_token.line,
|
@@ -110,9 +135,10 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
|
|
110
135
|
if attr_token.type == :NAME and attr_token.value == 'mode'
|
111
136
|
value_token = resource_tokens[resource_token_idx + 2]
|
112
137
|
|
113
|
-
break if value_token.value =~ /\
|
138
|
+
break if value_token.value =~ /\A[0-7]{4}\Z/
|
114
139
|
break if value_token.type == :VARIABLE
|
115
140
|
break if value_token.value =~ sym_mode
|
141
|
+
break if value_token.type == :UNDEF
|
116
142
|
|
117
143
|
notify :warning, {
|
118
144
|
:message => msg,
|
@@ -7,8 +7,10 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
|
|
7
7
|
check 'double_quoted_strings' do
|
8
8
|
tokens.select { |r|
|
9
9
|
r.type == :STRING
|
10
|
-
}.
|
11
|
-
r.value.
|
10
|
+
}.each { |r|
|
11
|
+
r.value.gsub!(' '*r.column, "\n")
|
12
|
+
}.select { |r|
|
13
|
+
r.value[/(\t|\\t|\n|\\n)/].nil?
|
12
14
|
}.each do |token|
|
13
15
|
notify :warning, {
|
14
16
|
:message => 'double quoted string containing no variables',
|
@@ -27,7 +29,7 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
|
|
27
29
|
token = tokens[token_idx]
|
28
30
|
|
29
31
|
if token.type == :DQPRE and token.value == ''
|
30
|
-
if
|
32
|
+
if {:VARIABLE => true, :UNENC_VARIABLE => true}.include? tokens[token_idx + 1].type
|
31
33
|
if tokens[token_idx + 2].type == :DQPOST
|
32
34
|
if tokens[token_idx + 2].value == ''
|
33
35
|
notify :warning, {
|
@@ -82,7 +84,7 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
|
|
82
84
|
# Returns nothing.
|
83
85
|
check 'quoted_booleans' do
|
84
86
|
tokens.select { |r|
|
85
|
-
|
87
|
+
{:STRING => true, :SSTRING => true}.include?(r.type) && %w{true false}.include?(r.value)
|
86
88
|
}.each do |token|
|
87
89
|
notify :warning, {
|
88
90
|
:message => 'quoted boolean value found',
|
@@ -5,7 +5,7 @@ class PuppetLint::Plugins::CheckVariables < PuppetLint::CheckPlugin
|
|
5
5
|
# Returns nothing.
|
6
6
|
check 'variable_contains_dash' do
|
7
7
|
tokens.select { |r|
|
8
|
-
|
8
|
+
{:VARIABLE => true, :UNENC_VARIABLE => true}.include? r.type
|
9
9
|
}.each do |token|
|
10
10
|
if token.value.match(/-/)
|
11
11
|
notify :warning, {
|
@@ -69,64 +69,41 @@ class PuppetLint::Plugins::CheckWhitespace < PuppetLint::CheckPlugin
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
# Check the
|
73
|
-
#
|
72
|
+
# Check the manifest tokens for any arrows (=>) in a grouping ({}) that are
|
73
|
+
# not aligned with other arrows in that grouping.
|
74
74
|
#
|
75
75
|
# Returns nothing.
|
76
76
|
check 'arrow_alignment' do
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
line_indent = $1
|
84
|
-
if in_resource
|
85
|
-
if selectors.count > 0
|
86
|
-
if selectors.last == 0
|
87
|
-
selectors[-1] = line_indent.length
|
88
|
-
end
|
77
|
+
resource_indexes.each do |res_idx|
|
78
|
+
indent_depth = [nil]
|
79
|
+
resource_tokens = tokens[res_idx[:start]..res_idx[:end]]
|
80
|
+
resource_tokens.reject! do |token|
|
81
|
+
{:COMMENT => true, :SLASH_COMMENT => true, :MLCOMMENT => true}.include? token.type
|
82
|
+
end
|
89
83
|
|
90
|
-
|
91
|
-
|
92
|
-
notify :warning, {
|
93
|
-
:message => '=> is not properly aligned for selector',
|
94
|
-
:linenumber => idx + 1,
|
95
|
-
:column => line_indent.length,
|
96
|
-
}
|
97
|
-
end
|
84
|
+
# If this is a single line resource, skip it
|
85
|
+
next if resource_tokens.select { |r| r.type == :NEWLINE }.empty?
|
98
86
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
elsif line.strip =~ /\}[,;]?$/
|
103
|
-
selectors.pop
|
104
|
-
end
|
105
|
-
else
|
106
|
-
unless line_indent.length == resource_indent_length
|
107
|
-
notify :warning, {
|
108
|
-
:message => '=> is not properly aligned for resource',
|
109
|
-
:linenumber => idx + 1,
|
110
|
-
:column => line_indent.length,
|
111
|
-
}
|
112
|
-
end
|
87
|
+
resource_tokens.each_with_index do |token, idx|
|
88
|
+
if token.type == :FARROW
|
89
|
+
indent_length = token.column
|
113
90
|
|
114
|
-
|
115
|
-
|
116
|
-
end
|
91
|
+
if indent_depth.last.nil?
|
92
|
+
indent_depth[-1] = indent_length
|
117
93
|
end
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
94
|
+
|
95
|
+
unless indent_depth.last == indent_length
|
96
|
+
notify :warning, {
|
97
|
+
:message => '=> is not properly aligned',
|
98
|
+
:linenumber => token.line,
|
99
|
+
:column => token.column,
|
100
|
+
}
|
123
101
|
end
|
102
|
+
elsif token.type == :LBRACE
|
103
|
+
indent_depth.push(nil)
|
104
|
+
elsif token.type == :RBRACE
|
105
|
+
indent_depth.pop
|
124
106
|
end
|
125
|
-
elsif line.strip =~ /\}[,;]?$/ and selectors.count > 0
|
126
|
-
selectors.pop
|
127
|
-
else
|
128
|
-
in_resource = false
|
129
|
-
resource_indent_length = 0
|
130
107
|
end
|
131
108
|
end
|
132
109
|
end
|
@@ -8,6 +8,8 @@ class PuppetLint
|
|
8
8
|
desc 'Run puppet-lint'
|
9
9
|
|
10
10
|
task :lint do
|
11
|
+
PuppetLint.configuration.with_filename = true
|
12
|
+
|
11
13
|
RakeFileUtils.send(:verbose, true) do
|
12
14
|
linter = PuppetLint.new
|
13
15
|
matched_files = FileList['**/*.pp']
|
@@ -17,7 +19,6 @@ class PuppetLint
|
|
17
19
|
end
|
18
20
|
|
19
21
|
matched_files.to_a.each do |puppet_file|
|
20
|
-
puts "Evaluating #{puppet_file}"
|
21
22
|
linter.file = puppet_file
|
22
23
|
linter.run
|
23
24
|
end
|
data/lib/puppet-lint/version.rb
CHANGED
data/puppet-lint.gemspec
CHANGED
@@ -0,0 +1,266 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'rspec/mocks'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
class CommandRun
|
6
|
+
attr_accessor :stdout, :stderr, :exitstatus
|
7
|
+
|
8
|
+
def initialize(args)
|
9
|
+
out = StringIO.new
|
10
|
+
err = StringIO.new
|
11
|
+
|
12
|
+
$stdout = out
|
13
|
+
$stderr = err
|
14
|
+
|
15
|
+
PuppetLint.configuration.defaults
|
16
|
+
@exitstatus = PuppetLint::Bin.new(args).run
|
17
|
+
PuppetLint.configuration.defaults
|
18
|
+
|
19
|
+
@stdout = out.string.strip
|
20
|
+
@stderr = err.string.strip
|
21
|
+
|
22
|
+
$stdout = STDOUT
|
23
|
+
$stderr = STDERR
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe PuppetLint::Bin do
|
28
|
+
subject do
|
29
|
+
if args.is_a? Array
|
30
|
+
sane_args = args
|
31
|
+
else
|
32
|
+
sane_args = [args]
|
33
|
+
end
|
34
|
+
|
35
|
+
CommandRun.new(sane_args)
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when running normally' do
|
39
|
+
let(:args) { 'spec/fixtures/test/manifests/init.pp' }
|
40
|
+
|
41
|
+
its(:exitstatus) { should == 0 }
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when running without arguments' do
|
45
|
+
let(:args) { [] }
|
46
|
+
|
47
|
+
its(:exitstatus) { should == 1 }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when asked to display version' do
|
51
|
+
let(:args) { '--version' }
|
52
|
+
|
53
|
+
its(:exitstatus) { should == 0 }
|
54
|
+
its(:stdout) { should == "Puppet-lint #{PuppetLint::VERSION}" }
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'when passed multiple files' do
|
58
|
+
let(:args) { [
|
59
|
+
'spec/fixtures/test/manifests/warning.pp',
|
60
|
+
'spec/fixtures/test/manifests/fail.pp',
|
61
|
+
] }
|
62
|
+
|
63
|
+
its(:exitstatus) { should == 1 }
|
64
|
+
its(:stdout) { should == [
|
65
|
+
'WARNING: optional parameter listed before required parameter on line 2',
|
66
|
+
'ERROR: test::foo not in autoload module layout on line 2',
|
67
|
+
].join("\n") }
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when limited to errors only' do
|
71
|
+
let(:args) { [
|
72
|
+
'--error-level', 'error',
|
73
|
+
'spec/fixtures/test/manifests/warning.pp',
|
74
|
+
'spec/fixtures/test/manifests/fail.pp',
|
75
|
+
] }
|
76
|
+
|
77
|
+
its(:exitstatus) { should == 1 }
|
78
|
+
its(:stdout) { should match(/^ERROR/) }
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when limited to errors only' do
|
82
|
+
let(:args) { [
|
83
|
+
'--error-level', 'warning',
|
84
|
+
'spec/fixtures/test/manifests/warning.pp',
|
85
|
+
'spec/fixtures/test/manifests/fail.pp',
|
86
|
+
] }
|
87
|
+
|
88
|
+
its(:exitstatus) { should == 1 }
|
89
|
+
its(:stdout) { should match(/^WARNING/) }
|
90
|
+
end
|
91
|
+
|
92
|
+
context 'when asked to display filenames ' do
|
93
|
+
let(:args) { ['--with-filename', 'spec/fixtures/test/manifests/fail.pp'] }
|
94
|
+
|
95
|
+
its(:exitstatus) { should == 1 }
|
96
|
+
its(:stdout) { should match(%r{^spec/fixtures/test/manifests/fail\.pp -}) }
|
97
|
+
end
|
98
|
+
|
99
|
+
context 'when not asked to fail on warnings' do
|
100
|
+
let(:args) { ['spec/fixtures/test/manifests/warning.pp'] }
|
101
|
+
|
102
|
+
its(:exitstatus) { should == 0 }
|
103
|
+
its(:stdout) { should match(/optional parameter/) }
|
104
|
+
end
|
105
|
+
|
106
|
+
context 'when asked to fail on warnings' do
|
107
|
+
let(:args) { [
|
108
|
+
'--fail-on-warnings',
|
109
|
+
'spec/fixtures/test/manifests/warning.pp',
|
110
|
+
] }
|
111
|
+
|
112
|
+
its(:exitstatus) { should == 1 }
|
113
|
+
its(:stdout) { should match(/optional parameter/) }
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'when used with an invalid option' do
|
117
|
+
let(:args) { '--foo-bar-baz' }
|
118
|
+
|
119
|
+
its(:exitstatus) { should == 1 }
|
120
|
+
its(:stdout) { should match(/invalid option/) }
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'when passed a file that does not exist' do
|
124
|
+
let(:args) { 'spec/fixtures/test/manifests/enoent.pp' }
|
125
|
+
|
126
|
+
its(:exitstatus) { should == 1 }
|
127
|
+
its(:stdout) { should match(/specified file does not exist/) }
|
128
|
+
end
|
129
|
+
|
130
|
+
context 'when passed a directory' do
|
131
|
+
let(:args) { 'spec/fixtures/' }
|
132
|
+
|
133
|
+
its(:exitstatus) { should == 1 }
|
134
|
+
its(:stdout) { should match(/^ERROR/) }
|
135
|
+
end
|
136
|
+
|
137
|
+
context 'when disabling a check' do
|
138
|
+
let(:args) { [
|
139
|
+
'--no-autoloader_layout',
|
140
|
+
'spec/fixtures/test/manifests/fail.pp'
|
141
|
+
] }
|
142
|
+
|
143
|
+
its(:exitstatus) { should == 0 }
|
144
|
+
its(:stdout) { should == "" }
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when changing the log format' do
|
148
|
+
context 'to print %{filename}' do
|
149
|
+
let(:args) { [
|
150
|
+
'--log-format', '%{filename}',
|
151
|
+
'spec/fixtures/test/manifests/fail.pp'
|
152
|
+
] }
|
153
|
+
|
154
|
+
its(:exitstatus) { should == 1 }
|
155
|
+
its(:stdout) { should == 'fail.pp' }
|
156
|
+
end
|
157
|
+
|
158
|
+
context 'to print %{path}' do
|
159
|
+
let(:args) { [
|
160
|
+
'--log-format', '%{path}',
|
161
|
+
'spec/fixtures/test/manifests/fail.pp'
|
162
|
+
] }
|
163
|
+
|
164
|
+
its(:exitstatus) { should == 1 }
|
165
|
+
its(:stdout) { should == 'spec/fixtures/test/manifests/fail.pp' }
|
166
|
+
end
|
167
|
+
|
168
|
+
context 'to print %{fullpath}' do
|
169
|
+
let(:args) { [
|
170
|
+
'--log-format', '%{fullpath}',
|
171
|
+
'spec/fixtures/test/manifests/fail.pp'
|
172
|
+
] }
|
173
|
+
|
174
|
+
its(:exitstatus) { should == 1 }
|
175
|
+
its(:stdout) {
|
176
|
+
should match(%r{^/.+/spec/fixtures/test/manifests/fail\.pp$})
|
177
|
+
}
|
178
|
+
end
|
179
|
+
|
180
|
+
context 'to print %{linenumber}' do
|
181
|
+
let(:args) { [
|
182
|
+
'--log-format', '%{linenumber}',
|
183
|
+
'spec/fixtures/test/manifests/fail.pp'
|
184
|
+
] }
|
185
|
+
|
186
|
+
its(:exitstatus) { should == 1 }
|
187
|
+
its(:stdout) { should == '2' }
|
188
|
+
end
|
189
|
+
|
190
|
+
context 'to print %{kind}' do
|
191
|
+
let(:args) { [
|
192
|
+
'--log-format', '%{kind}',
|
193
|
+
'spec/fixtures/test/manifests/fail.pp'
|
194
|
+
] }
|
195
|
+
|
196
|
+
its(:exitstatus) { should == 1 }
|
197
|
+
its(:stdout) { should == 'error' }
|
198
|
+
end
|
199
|
+
|
200
|
+
context 'to print %{KIND}' do
|
201
|
+
let(:args) { [
|
202
|
+
'--log-format', '%{KIND}',
|
203
|
+
'spec/fixtures/test/manifests/fail.pp'
|
204
|
+
] }
|
205
|
+
|
206
|
+
its(:exitstatus) { should == 1 }
|
207
|
+
its(:stdout) { should == 'ERROR' }
|
208
|
+
end
|
209
|
+
|
210
|
+
context 'to print %{check}' do
|
211
|
+
let(:args) { [
|
212
|
+
'--log-format', '%{check}',
|
213
|
+
'spec/fixtures/test/manifests/fail.pp'
|
214
|
+
] }
|
215
|
+
|
216
|
+
its(:exitstatus) { should == 1 }
|
217
|
+
its(:stdout) { should == 'autoloader_layout' }
|
218
|
+
end
|
219
|
+
|
220
|
+
context 'to print %{message}' do
|
221
|
+
let(:args) { [
|
222
|
+
'--log-format', '%{message}',
|
223
|
+
'spec/fixtures/test/manifests/fail.pp'
|
224
|
+
] }
|
225
|
+
|
226
|
+
its(:exitstatus) { should == 1 }
|
227
|
+
its(:stdout) { should == 'test::foo not in autoload module layout' }
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'when loading options from a file' do
|
231
|
+
let(:args) { 'spec/fixtures/test/manifests/fail.pp' }
|
232
|
+
|
233
|
+
it 'should have ~/.puppet-lintrc as depreciated' do
|
234
|
+
OptionParser.any_instance.stub(:load).
|
235
|
+
with(File.expand_path('~/.puppet-lintrc')).and_return(true)
|
236
|
+
OptionParser.any_instance.stub(:load).
|
237
|
+
with(File.expand_path('~/.puppet-lint.rc')).and_return(false)
|
238
|
+
OptionParser.any_instance.stub(:load).
|
239
|
+
with('.puppet-lintrc').and_return(false)
|
240
|
+
OptionParser.any_instance.stub(:load).
|
241
|
+
with('.puppet-lint.rc').and_return(false)
|
242
|
+
OptionParser.any_instance.stub(:load).
|
243
|
+
with('/etc/puppet-lint.rc').and_return(false)
|
244
|
+
|
245
|
+
msg = 'Depreciated: Found ~/.puppet-lintrc instead of ~/.puppet-lint.rc'
|
246
|
+
subject.stderr.should == msg
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'should have .puppet-lintrc as depreciated' do
|
250
|
+
OptionParser.any_instance.stub(:load).
|
251
|
+
with(File.expand_path('~/.puppet-lintrc')).and_return(false)
|
252
|
+
OptionParser.any_instance.stub(:load).
|
253
|
+
with(File.expand_path('~/.puppet-lint.rc')).and_return(false)
|
254
|
+
OptionParser.any_instance.stub(:load).
|
255
|
+
with('.puppet-lintrc').and_return(true)
|
256
|
+
OptionParser.any_instance.stub(:load).
|
257
|
+
with('.puppet-lint.rc').and_return(false)
|
258
|
+
OptionParser.any_instance.stub(:load).
|
259
|
+
with('/etc/puppet-lint.rc').and_return(false)
|
260
|
+
|
261
|
+
msg = 'Depreciated: Read .puppet-lintrc instead of .puppet-lint.rc'
|
262
|
+
subject.stderr.should == msg
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end
|