puppet-check 1.2.1 → 1.3.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 +20 -5
- data/README.md +14 -10
- data/lib/puppet-check.rb +7 -11
- data/lib/puppet-check/cli.rb +4 -1
- data/lib/puppet-check/data_parser.rb +16 -10
- data/lib/puppet-check/output_results.rb +46 -0
- data/lib/puppet-check/puppet_parser.rb +9 -9
- data/lib/puppet-check/rspec_puppet_support.rb +4 -6
- data/lib/puppet-check/ruby_parser.rb +9 -9
- data/lib/puppet-check/tasks.rb +3 -3
- data/spec/fixtures/metadata_style/metadata.json +0 -11
- data/spec/puppet-check/cli_spec.rb +6 -0
- data/spec/puppet-check/data_parser_spec.rb +8 -8
- data/spec/puppet-check/output_results_spec.rb +84 -0
- data/spec/puppet-check/puppet_parser_spec.rb +13 -8
- data/spec/puppet-check/rspec_puppet_support_spec.rb +1 -0
- data/spec/puppet-check/ruby_parser_spec.rb +17 -26
- data/spec/puppet-check_spec.rb +2 -24
- data/spec/system/system_spec.rb +7 -3
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ce83eaa817c69d2ca4cd5219571bc0af2d0e125
|
4
|
+
data.tar.gz: 34afb49f0e47a20d75417dd11d5f2d277192394b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d5e0aae72d0fd85ac9332c2abbccb16d5000c458677ade54adac994a343037301f7abc123245a582ecbd1b151cd52f633264d43d1fe815895fa4f0af58ed602
|
7
|
+
data.tar.gz: 3ea14379bdcd682feedbdf10a82c2939f175832c2794ebc9fb81d0e673703d8f354c63664a4cbc6ce31380829a306424033e1190b0489e29ac58581e17796d46
|
data/CHANGELOG.md
CHANGED
@@ -1,13 +1,28 @@
|
|
1
|
-
### 1.
|
2
|
-
-
|
3
|
-
- minimum
|
1
|
+
### 1.4.0 (Roadmap)
|
2
|
+
- rudimentary catalog compilation testing? (only for Puppet4)
|
3
|
+
- minimum Puppet version increased from 3.4 to 3.7.
|
4
4
|
- rakefile interface with puppet-lint, rubocop, reek
|
5
|
-
- json and yaml output formats support (error_files becomes hash with file keys and array of issues; refactor output_results)
|
6
|
-
- rudimentary catalog compilation testing?
|
7
5
|
- rspec puppet stubbing
|
8
6
|
- infrataster and analogous docker task like thing ripienaar did?
|
7
|
+
- some multithreading for speedup
|
8
|
+
|
9
|
+
### 1.3.1 (Roadmap)
|
10
|
+
- split syntax and style checks to separate methods for speedup
|
11
|
+
- more args, fewer self accessors
|
12
|
+
- improved json and yaml output formats support (file arrays become file hashes and output results further handles formatting)
|
13
|
+
- metadata.json checks for dependency upper bounds, dependencies/operatingsystem_support as array of hashes, and operatingsystem and operatingsystem_release within operatingsystem_support
|
14
|
+
- do another reek and rubocop check
|
9
15
|
- add additional hiera checks
|
10
16
|
|
17
|
+
### 1.3.0
|
18
|
+
- Minimum Ruby version increased from 1.9.3 to 2.0.0.
|
19
|
+
- Minimum Puppet version increased from 3.2 to 3.4.
|
20
|
+
- Fixed issue where invalid arguments to PuppetLint were not displayed in error message.
|
21
|
+
- Support for outputting the results in YAML or JSON formats.
|
22
|
+
- Additional style check for `metadata.json`.
|
23
|
+
- Slight code cleanup and optimization.
|
24
|
+
- Block hieradata checks from excuting on `hiera.yaml`.
|
25
|
+
|
11
26
|
### 1.2.1
|
12
27
|
- Code and output cleanup.
|
13
28
|
- Add arguments support to external module download methods.
|
data/README.md
CHANGED
@@ -116,16 +116,17 @@ The following files have unrecognized formats and therefore were not processed:
|
|
116
116
|
It is worth nothing that there is no current development objective for Puppet Check to achieve the same advanced level of robustness for spec testing that Puppetlabs Spec Helper enables. If you are performing standard spec testing on your Puppet code and data, then Puppet Check's spec testing is a fantastic lightweight and faster alternative to Puppetlabs Spec Helper. If you require advanced and intricate capabilities in your spec testing (e.g. direct interfacing to the `Puppet::Parser::Scope` API), then you will likely prefer Puppetlabs Spec Helper's spec testing in conjunction with Puppet Check's file validation.
|
117
117
|
|
118
118
|
## Usage
|
119
|
-
Puppet Check requires `ruby >=
|
119
|
+
Puppet Check requires `ruby >= 2.0.0`, `puppet >= 3.4`, and `puppet-lint >= 2.0.0`. All other dependencies should be fine with various versions. Puppet Check can be used either with a CLI or Rake tasks. Please note both interfaces will ignore any directories named `fixtures` or specified paths with that directory during file checks and spec tests.
|
120
120
|
|
121
|
-
#### Important Note for Ruby 1.9.3
|
122
|
-
If you are using Ruby 1.9.3, there is
|
121
|
+
#### Important Note for Ruby 1.9.3 and PuppetCheck <= 1.2.1
|
122
|
+
If you are using Ruby 1.9.3, there is an issue where `Hiera <= 3.2.0` has an unspecified version dependency on JSonPure. Since JSonPure 2.0.2 requires `ruby >= 2.0.0`, this breaks Hiera installs on Ruby 1.9.3, which breaks Puppet installs, which breaks PuppetCheck installs. Therefore, you will need to either restrict your installed version of JSonPure to something lower than 2.0.2 if you are using Ruby 1.9.3, or use `Hiera >= 3.2.1`.
|
123
123
|
|
124
124
|
### CLI
|
125
125
|
```
|
126
126
|
usage: puppet-check [options] paths
|
127
127
|
-f, --future Enable future parser
|
128
128
|
-s, --style Enable style checks
|
129
|
+
-o, --output format Format for results output (default is text): text, json, or yaml
|
129
130
|
--puppet-lint arg_one,arg_two
|
130
131
|
Arguments for PuppetLint ignored checks
|
131
132
|
-c, --config file Load PuppetLint options from file.
|
@@ -150,13 +151,16 @@ rake puppetcheck:beaker # Execute Beaker acceptance tests
|
|
150
151
|
```
|
151
152
|
|
152
153
|
#### puppetcheck:file
|
153
|
-
You can add style checks to and select the future parser for the `rake puppetcheck:file
|
154
|
+
You can add style checks to and select the future parser for the `rake puppetcheck:file`, or change the output format, by adding the following after the require:
|
154
155
|
|
155
156
|
```ruby
|
156
157
|
PuppetCheck.style_check = true
|
157
158
|
PuppetCheck.future_parser = true
|
159
|
+
PuppetCheck.output_format = yaml
|
158
160
|
```
|
159
161
|
|
162
|
+
Please note that `rspec` does not support yaml output and therefore would still use the default 'progress' formatter even if `yaml` is specified as the format option to Puppet Check.
|
163
|
+
|
160
164
|
The style checks from within `rake puppetcheck:file` are directly interfaced to `puppet-lint`, `rubocop`, and `reek`. This means that all arguments and options should be specified from within your `.puppet-lint.rc`, `.rubocop.yml`, and `*.reek`. The capability to pass style arguments and options from within the `Rakefile` task block will be considered for future versions.
|
161
165
|
|
162
166
|
#### puppetcheck:spec
|
@@ -222,19 +226,19 @@ RUN apt-get update && apt-get install ruby git -y
|
|
222
226
|
RUN gem install --no-rdoc --no-ri puppet-check reek rspec-puppet rake
|
223
227
|
# this is needed for the ruby json parser to not flip out on fresh os installs for some reason (change encoding value as necessary)
|
224
228
|
ENV LANG en_US.UTF-8
|
225
|
-
# create the directory for your module and change directory into it
|
226
|
-
WORKDIR /
|
227
|
-
# copy the module contents into the module directory inside the container
|
229
|
+
# create the directory for your module, directory environment, etc. and change directory into it
|
230
|
+
WORKDIR /module_name_or_directory_environment_name
|
231
|
+
# copy the module, directory environment, etc. contents into the module directory inside the container
|
228
232
|
COPY / .
|
229
|
-
# execute your tests; in this example we are executing the full suite of tests
|
230
|
-
|
233
|
+
# execute your tests; in this example we are executing the full suite of tests
|
234
|
+
ENTRYPOINT ["rake", "puppetcheck"]
|
231
235
|
```
|
232
236
|
|
233
237
|
You can also build your own general container for testing various Puppet situations by removing the last three lines. You can then test each module, directory environment, etc. on top of that container by merely adding and modifying the final three lines to a Dockerfile that uses the container you built from the first four lines. This is recommended usage due to being very efficient and stable.
|
234
238
|
|
235
239
|
### Exit Codes
|
236
240
|
- 0: PuppetCheck exited with no internal exceptions or errors in your Puppet code and data.
|
237
|
-
- 1: PuppetCheck exited with an internal exception (takes preference over other non-zero exit codes).
|
241
|
+
- 1: PuppetCheck exited with an internal exception (takes preference over other non-zero exit codes) or failed spec test.
|
238
242
|
- 2: PuppetCheck exited with one or more errors in your Puppet code and data.
|
239
243
|
|
240
244
|
### Optional dependencies
|
data/lib/puppet-check.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require_relative 'puppet-check/puppet_parser'
|
2
2
|
require_relative 'puppet-check/ruby_parser'
|
3
3
|
require_relative 'puppet-check/data_parser'
|
4
|
+
require_relative 'puppet-check/output_results'
|
4
5
|
|
5
6
|
# interfaces from CLI/tasks and to individual parsers
|
6
7
|
class PuppetCheck
|
@@ -8,6 +9,9 @@ class PuppetCheck
|
|
8
9
|
@future_parser = false
|
9
10
|
@style_check = false
|
10
11
|
|
12
|
+
# initialize output format option
|
13
|
+
@output_format = 'text'
|
14
|
+
|
11
15
|
# initialize diagnostic output arrays
|
12
16
|
@error_files = []
|
13
17
|
@warning_files = []
|
@@ -20,7 +24,7 @@ class PuppetCheck
|
|
20
24
|
|
21
25
|
# allow the parser methods read user options and append to the file arrays; allow CLI and tasks write to user options
|
22
26
|
class << self
|
23
|
-
attr_accessor :future_parser, :style_check, :error_files, :warning_files, :clean_files, :ignored_files, :puppetlint_args, :rubocop_args
|
27
|
+
attr_accessor :future_parser, :style_check, :output_format, :error_files, :warning_files, :clean_files, :ignored_files, :puppetlint_args, :rubocop_args
|
24
28
|
end
|
25
29
|
|
26
30
|
# main runner for PuppetCheck
|
@@ -32,7 +36,7 @@ class PuppetCheck
|
|
32
36
|
execute_parsers(files)
|
33
37
|
|
34
38
|
# output the diagnostic results
|
35
|
-
|
39
|
+
PuppetCheck.output_format == 'text' ? OutputResults.text : OutputResults.markup
|
36
40
|
|
37
41
|
# exit code
|
38
42
|
self.class.error_files.empty? ? 0 : 2
|
@@ -75,14 +79,6 @@ class PuppetCheck
|
|
75
79
|
files.reject! { |file| File.extname(file) == '.json' }
|
76
80
|
RubyParser.librarian(files.select { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ })
|
77
81
|
files.reject! { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
|
78
|
-
files.each { |file| self.class.ignored_files.push(
|
79
|
-
end
|
80
|
-
|
81
|
-
# output the results for the files that were requested to be checked
|
82
|
-
def self.output_results
|
83
|
-
puts "\033[31mThe following files have errors:\033[0m", error_files.join("\n\n") unless error_files.empty?
|
84
|
-
puts "\n\033[33mThe following files have warnings:\033[0m", warning_files.join("\n\n") unless warning_files.empty?
|
85
|
-
puts "\n\033[32mThe following files have no errors or warnings:\033[0m", clean_files unless clean_files.empty?
|
86
|
-
puts "\n\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m", ignored_files unless ignored_files.empty?
|
82
|
+
files.each { |file| self.class.ignored_files.push(file.to_s) }
|
87
83
|
end
|
88
84
|
end
|
data/lib/puppet-check/cli.rb
CHANGED
@@ -21,7 +21,7 @@ class PuppetCheck::CLI
|
|
21
21
|
|
22
22
|
# base options
|
23
23
|
opts.on('--version', 'Display the current version.') do
|
24
|
-
puts 'puppet-check 1.
|
24
|
+
puts 'puppet-check 1.3.0'
|
25
25
|
exit 0
|
26
26
|
end
|
27
27
|
|
@@ -29,6 +29,9 @@ class PuppetCheck::CLI
|
|
29
29
|
opts.on('-f', '--future', 'Enable future parser') { PuppetCheck.future_parser = true }
|
30
30
|
opts.on('-s', '--style', 'Enable style checks') { PuppetCheck.style_check = true }
|
31
31
|
|
32
|
+
# formatting options
|
33
|
+
opts.on('-o', '--output format', String, 'Format for results output (default is text): text, json, or yaml') { |arg| PuppetCheck.output_format = arg }
|
34
|
+
|
32
35
|
# arguments to style checkers
|
33
36
|
opts.on('--puppet-lint arg_one,arg_two', Array, 'Arguments for PuppetLint ignored checks') do |puppetlint_args|
|
34
37
|
PuppetCheck.puppetlint_args += puppetlint_args.map { |arg| "--#{arg}" }
|
@@ -10,13 +10,16 @@ class DataParser
|
|
10
10
|
# check yaml syntax
|
11
11
|
begin
|
12
12
|
parsed = YAML.load_file(file)
|
13
|
-
rescue
|
14
|
-
PuppetCheck.error_files.push("
|
13
|
+
rescue StandardError => err
|
14
|
+
PuppetCheck.error_files.push("#{file}:\n#{err.to_s.gsub("(#{file}): ", '')}")
|
15
15
|
else
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
warnings = []
|
17
|
+
|
18
|
+
# perform some rudimentary hiera checks if data exists and is hieradata
|
19
|
+
warnings = hiera(parsed) unless (parsed.class.to_s == 'NilClass') || (file == 'hiera.yaml')
|
20
|
+
|
21
|
+
next PuppetCheck.warning_files.push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty?
|
22
|
+
PuppetCheck.clean_files.push(file.to_s)
|
20
23
|
end
|
21
24
|
end
|
22
25
|
end
|
@@ -30,7 +33,7 @@ class DataParser
|
|
30
33
|
begin
|
31
34
|
parsed = JSON.parse(File.read(file))
|
32
35
|
rescue JSON::ParserError => err
|
33
|
-
PuppetCheck.error_files.push("
|
36
|
+
PuppetCheck.error_files.push("#{file}:\n#{err.to_s.lines.first.strip}")
|
34
37
|
else
|
35
38
|
warnings = []
|
36
39
|
|
@@ -66,9 +69,12 @@ class DataParser
|
|
66
69
|
# check for summary under 144 character
|
67
70
|
errors.push('Summary exceeds 144 characters.') if parsed.key?('summary') && parsed['summary'].size > 144
|
68
71
|
|
69
|
-
next PuppetCheck.error_files.push("
|
72
|
+
next PuppetCheck.error_files.push("#{file}:\n#{errors.join("\n")}") unless errors.empty?
|
70
73
|
|
71
74
|
# check for warnings
|
75
|
+
# check for operatingsystem_support
|
76
|
+
warnings.push('Recommended field \'operatingsystem_support\' not found.') unless parsed.key?('operatingsystem_support')
|
77
|
+
|
72
78
|
# check for spdx license (rubygems/util/licenses for rubygems >= 2.5 in the far future)
|
73
79
|
if parsed.key?('license') && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
|
74
80
|
warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/")
|
@@ -78,8 +84,8 @@ class DataParser
|
|
78
84
|
# perform some rudimentary hiera checks if data exists
|
79
85
|
warnings = hiera(parsed) unless parsed.class.to_s == 'NilClass'
|
80
86
|
end
|
81
|
-
next PuppetCheck.warning_files.push("
|
82
|
-
PuppetCheck.clean_files.push(
|
87
|
+
next PuppetCheck.warning_files.push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty?
|
88
|
+
PuppetCheck.clean_files.push(file.to_s)
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require_relative '../puppet-check'
|
2
|
+
|
3
|
+
# class to handle outputting diagnostic results in desired format
|
4
|
+
class OutputResults
|
5
|
+
# output the results as text
|
6
|
+
def self.text
|
7
|
+
unless PuppetCheck.error_files.empty?
|
8
|
+
print "\033[31mThe following files have errors:\033[0m\n-- "
|
9
|
+
puts PuppetCheck.error_files.join("\n\n-- ")
|
10
|
+
end
|
11
|
+
unless PuppetCheck.warning_files.empty?
|
12
|
+
print "\n\033[33mThe following files have warnings:\033[0m\n-- "
|
13
|
+
puts PuppetCheck.warning_files.join("\n\n-- ")
|
14
|
+
end
|
15
|
+
unless PuppetCheck.clean_files.empty?
|
16
|
+
print "\n\033[32mThe following files have no errors or warnings:\033[0m\n-- "
|
17
|
+
puts PuppetCheck.clean_files.join("\n-- ")
|
18
|
+
end
|
19
|
+
unless PuppetCheck.ignored_files.empty?
|
20
|
+
print "\n\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- "
|
21
|
+
puts PuppetCheck.ignored_files.join("\n-- ")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# output the results as yaml or json
|
26
|
+
def self.markup
|
27
|
+
require 'yaml'
|
28
|
+
require 'json'
|
29
|
+
|
30
|
+
# generate output hash
|
31
|
+
hash = {}
|
32
|
+
hash['errors'] = PuppetCheck.error_files unless PuppetCheck.error_files.empty?
|
33
|
+
hash['warnings'] = PuppetCheck.warning_files unless PuppetCheck.warning_files.empty?
|
34
|
+
hash['clean'] = PuppetCheck.clean_files unless PuppetCheck.clean_files.empty?
|
35
|
+
hash['ignored'] = PuppetCheck.ignored_files unless PuppetCheck.ignored_files.empty?
|
36
|
+
|
37
|
+
# convert hash to markup language
|
38
|
+
if PuppetCheck.output_format == 'yaml'
|
39
|
+
puts Psych.dump(hash, indentation: 2)
|
40
|
+
elsif PuppetCheck.output_format == 'json'
|
41
|
+
puts JSON.pretty_generate(hash)
|
42
|
+
else
|
43
|
+
raise "puppet-check: Unsupported output format '#{PuppetCheck.output_format}' was specified."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -21,11 +21,11 @@ class PuppetParser
|
|
21
21
|
Puppet::Face[:parser, :current].validate(file)
|
22
22
|
# this is the actual error that we need to rescue Puppet::Face from
|
23
23
|
rescue SystemExit
|
24
|
-
next PuppetCheck.error_files.push("
|
24
|
+
next PuppetCheck.error_files.push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}")
|
25
25
|
end
|
26
26
|
|
27
27
|
# initialize warnings with output from the parser if it exists, since the output is warnings if Puppet::Face did not trigger a SystemExit
|
28
|
-
warnings = errors.empty? ? "
|
28
|
+
warnings = errors.empty? ? "#{file}:" : "#{file}:\n#{errors.map(&:to_s).join("\n").gsub("#{File.absolute_path(file)}:", '')}"
|
29
29
|
Puppet::Util::Log.close_all
|
30
30
|
|
31
31
|
# check puppet style
|
@@ -35,9 +35,9 @@ class PuppetParser
|
|
35
35
|
|
36
36
|
# check for invalid arguments to PuppetLint
|
37
37
|
begin
|
38
|
-
PuppetLint::OptParser.build.parse!(PuppetCheck.puppetlint_args)
|
38
|
+
PuppetLint::OptParser.build.parse!(PuppetCheck.puppetlint_args.clone)
|
39
39
|
rescue OptionParser::InvalidOption
|
40
|
-
raise "puppet-lint: invalid option supplied among #{PuppetCheck.puppetlint_args}"
|
40
|
+
raise "puppet-lint: invalid option supplied among #{PuppetCheck.puppetlint_args.join(' ')}"
|
41
41
|
end
|
42
42
|
|
43
43
|
# prepare the PuppetLint object for style checks
|
@@ -50,8 +50,8 @@ class PuppetParser
|
|
50
50
|
puppet_lint.problems.each { |values| warnings += "\n#{values[:line]}:#{values[:column]}: #{values[:message]}" }
|
51
51
|
end
|
52
52
|
end
|
53
|
-
next PuppetCheck.warning_files.push(warnings) unless warnings == "
|
54
|
-
PuppetCheck.clean_files.push(
|
53
|
+
next PuppetCheck.warning_files.push(warnings) unless warnings == "#{file}:"
|
54
|
+
PuppetCheck.clean_files.push(file.to_s)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -61,16 +61,16 @@ class PuppetParser
|
|
61
61
|
|
62
62
|
files.each do |file|
|
63
63
|
# puppet before version 4 cannot check template syntax
|
64
|
-
next PuppetCheck.ignored_files.push("
|
64
|
+
next PuppetCheck.ignored_files.push("#{file}: ignored due to Puppet < 4.0.0") if Puppet::PUPPETVERSION.to_i < 4
|
65
65
|
|
66
66
|
# check puppet template syntax
|
67
67
|
begin
|
68
68
|
# credits to gds-operations/puppet-syntax for the parser function call
|
69
69
|
Puppet::Pops::Parser::EvaluatingParser::EvaluatingEppParser.new.parse_file(file)
|
70
70
|
rescue StandardError => err
|
71
|
-
PuppetCheck.error_files.push("
|
71
|
+
PuppetCheck.error_files.push("#{file}:\n#{err.to_s.gsub("#{file}:", '')}")
|
72
72
|
else
|
73
|
-
PuppetCheck.clean_files.push(
|
73
|
+
PuppetCheck.clean_files.push(file.to_s)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -16,7 +16,7 @@ class RSpecPuppetSupport
|
|
16
16
|
# skip to next specdir if it does not seem like a puppet module
|
17
17
|
next unless File.directory?(specdir + '/../manifests')
|
18
18
|
|
19
|
-
#
|
19
|
+
# change to module directory
|
20
20
|
Dir.chdir(specdir + '/..')
|
21
21
|
|
22
22
|
# grab the module name from the directory name of the module to pass to file_setup
|
@@ -29,19 +29,17 @@ class RSpecPuppetSupport
|
|
29
29
|
|
30
30
|
# setup the files, directories, and symlinks for rspec-puppet testing
|
31
31
|
def self.file_setup(module_name)
|
32
|
-
require 'fileutils'
|
33
|
-
|
34
32
|
# create all the necessary fixture dirs that are missing
|
35
33
|
['spec/fixtures', 'spec/fixtures/manifests', 'spec/fixtures/modules', "spec/fixtures/modules/#{module_name}"].each do |dir|
|
36
|
-
|
34
|
+
Dir.mkdir(dir) unless File.directory?(dir)
|
37
35
|
end
|
38
36
|
|
39
37
|
# create empty site.pp if missing
|
40
|
-
|
38
|
+
File.write('spec/fixtures/manifests/site.pp', '') unless File.file?('spec/fixtures/manifests/site.pp')
|
41
39
|
|
42
40
|
# symlink over everything the module needs for compilation
|
43
41
|
%w(hiera.yaml data hieradata functions manifests lib files templates).each do |file|
|
44
|
-
|
42
|
+
File.symlink("../../../../#{file}", "spec/fixtures/modules/#{module_name}/#{file}") if File.exist?(file) && !File.exist?("spec/fixtures/modules/#{module_name}/#{file}")
|
45
43
|
end
|
46
44
|
|
47
45
|
# create spec_helper if missing
|
@@ -11,7 +11,7 @@ class RubyParser
|
|
11
11
|
# prevents ruby code from actually executing
|
12
12
|
catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)}") }
|
13
13
|
rescue ScriptError, StandardError => err
|
14
|
-
PuppetCheck.error_files.push("
|
14
|
+
PuppetCheck.error_files.push("#{file}:\n#{err}")
|
15
15
|
else
|
16
16
|
# check ruby style
|
17
17
|
if PuppetCheck.style_check
|
@@ -30,9 +30,9 @@ class RubyParser
|
|
30
30
|
end
|
31
31
|
|
32
32
|
# return warnings
|
33
|
-
next PuppetCheck.warning_files.push("
|
33
|
+
next PuppetCheck.warning_files.push("#{file}:\n#{warnings.strip}") unless warnings == ''
|
34
34
|
end
|
35
|
-
PuppetCheck.clean_files.push(
|
35
|
+
PuppetCheck.clean_files.push(file.to_s)
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -52,11 +52,11 @@ class RubyParser
|
|
52
52
|
# empty out warnings since it would contain an error if this pass triggers
|
53
53
|
warnings = ''
|
54
54
|
rescue ScriptError => err
|
55
|
-
next PuppetCheck.error_files.push("
|
55
|
+
next PuppetCheck.error_files.push("#{file}:\n#{err}")
|
56
56
|
end
|
57
57
|
# return warnings from the check if there were any
|
58
|
-
next PuppetCheck.warning_files.push("
|
59
|
-
PuppetCheck.clean_files.push(
|
58
|
+
next PuppetCheck.warning_files.push("#{file}:\n#{warnings.gsub('warning: ', '').split('(erb):').join('').strip}") unless warnings == ''
|
59
|
+
PuppetCheck.clean_files.push(file.to_s)
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -68,7 +68,7 @@ class RubyParser
|
|
68
68
|
# prevents ruby code from actually executing
|
69
69
|
catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)}") }
|
70
70
|
rescue SyntaxError, LoadError, ArgumentError => err
|
71
|
-
PuppetCheck.error_files.push("
|
71
|
+
PuppetCheck.error_files.push("#{file}:\n#{err}")
|
72
72
|
# check librarian puppet style
|
73
73
|
else
|
74
74
|
if PuppetCheck.style_check
|
@@ -81,9 +81,9 @@ class RubyParser
|
|
81
81
|
warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rubocop_args + ['--format', 'emacs', file]) }
|
82
82
|
|
83
83
|
# collect style warnings
|
84
|
-
next PuppetCheck.warning_files.push("
|
84
|
+
next PuppetCheck.warning_files.push("#{file}:\n#{warnings.split("#{File.absolute_path(file)}:").join('')}") unless warnings.empty?
|
85
85
|
end
|
86
|
-
PuppetCheck.clean_files.push(
|
86
|
+
PuppetCheck.clean_files.push(file.to_s)
|
87
87
|
end
|
88
88
|
end
|
89
89
|
end
|
data/lib/puppet-check/tasks.rb
CHANGED
@@ -12,9 +12,7 @@ class PuppetCheck::Tasks < ::Rake::TaskLib
|
|
12
12
|
namespace :puppetcheck do
|
13
13
|
desc 'Execute Puppet-Check file checks'
|
14
14
|
task :file do
|
15
|
-
|
16
|
-
# changes nothing if this task is run separately; aborts 'puppetcheck' task if there are errors here
|
17
|
-
exit exit_code if exit_code != 0
|
15
|
+
PuppetCheck.new.run(Dir.glob('*'))
|
18
16
|
end
|
19
17
|
|
20
18
|
desc 'Execute RSpec and RSpec-Puppet tests'
|
@@ -23,6 +21,7 @@ class PuppetCheck::Tasks < ::Rake::TaskLib
|
|
23
21
|
# generate tasks for all recognized directories and ensure spec tests inside module dependencies are ignored
|
24
22
|
spec_dirs = Dir.glob('**/{classes,defines,facter,functions,hosts,puppet,unit,types}/**/*_spec.rb').reject { |dir| dir =~ /fixtures/ }
|
25
23
|
task.pattern = spec_dirs.empty? ? 'skip_rspec' : spec_dirs
|
24
|
+
task.rspec_opts = '-f json' if PuppetCheck.output_format == 'json'
|
26
25
|
end
|
27
26
|
|
28
27
|
desc 'Execute Beaker acceptance tests'
|
@@ -30,6 +29,7 @@ class PuppetCheck::Tasks < ::Rake::TaskLib
|
|
30
29
|
# generate tasks for all recognized directories and ensure acceptance tests inside module dependencies are ignored
|
31
30
|
acceptance_dirs = Dir.glob('**/acceptance').reject { |dir| dir =~ /fixtures/ }
|
32
31
|
task.pattern = acceptance_dirs.empty? ? 'skip_beaker' : acceptance_dirs
|
32
|
+
task.rspec_opts = '-f json' if PuppetCheck.output_format == 'json'
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
@@ -7,17 +7,6 @@
|
|
7
7
|
"source": "https://github.com/puppetlabs/puppetlabs-stdlib",
|
8
8
|
"project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
|
9
9
|
"issues_url": "https://tickets.puppetlabs.com/browse/MODULES",
|
10
|
-
"operatingsystem_support": [
|
11
|
-
{
|
12
|
-
"operatingsystem": "RedHat",
|
13
|
-
"operatingsystemrelease": [
|
14
|
-
"4",
|
15
|
-
"5",
|
16
|
-
"6",
|
17
|
-
"7"
|
18
|
-
]
|
19
|
-
}
|
20
|
-
],
|
21
10
|
"requirements": [
|
22
11
|
{
|
23
12
|
"name": "pe",
|
@@ -21,6 +21,12 @@ describe PuppetCheck::CLI do
|
|
21
21
|
expect(PuppetCheck.style_check).to eql(true)
|
22
22
|
end
|
23
23
|
|
24
|
+
it 'correctly parses a formatting option' do
|
25
|
+
PuppetCheck.output_format = ''
|
26
|
+
PuppetCheck::CLI.parse(%w(-o text))
|
27
|
+
expect(PuppetCheck.output_format).to eql('text')
|
28
|
+
end
|
29
|
+
|
24
30
|
it 'correctly parses PuppetLint arguments' do
|
25
31
|
PuppetCheck.puppetlint_args = []
|
26
32
|
PuppetCheck::CLI.parse(%w(--puppet-lint puppetlint-arg-one,puppetlint-arg-two foo))
|
@@ -11,54 +11,54 @@ describe DataParser do
|
|
11
11
|
context '.yaml' do
|
12
12
|
it 'puts a bad syntax yaml file in the error files array' do
|
13
13
|
DataParser.yaml([fixtures_dir + 'hieradata/syntax.yaml'])
|
14
|
-
expect(PuppetCheck.error_files[0]).to match(%r{
|
14
|
+
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}hieradata/syntax.yaml:\nblock sequence entries are not allowed})
|
15
15
|
expect(PuppetCheck.warning_files).to eql([])
|
16
16
|
expect(PuppetCheck.clean_files).to eql([])
|
17
17
|
end
|
18
18
|
it 'puts a good yaml file with potential hiera issues in the warning files array' do
|
19
19
|
DataParser.yaml([fixtures_dir + 'hieradata/style.yaml'])
|
20
20
|
expect(PuppetCheck.error_files).to eql([])
|
21
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{
|
21
|
+
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}hieradata/style.yaml:\nValue\(s\) missing in key.*\nValue\(s\) missing in key})
|
22
22
|
expect(PuppetCheck.clean_files).to eql([])
|
23
23
|
end
|
24
24
|
it 'puts a good yaml file in the clean files array' do
|
25
25
|
DataParser.yaml([fixtures_dir + 'hieradata/good.yaml'])
|
26
26
|
expect(PuppetCheck.error_files).to eql([])
|
27
27
|
expect(PuppetCheck.warning_files).to eql([])
|
28
|
-
expect(PuppetCheck.clean_files).to eql(["
|
28
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}hieradata/good.yaml"])
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
context '.json' do
|
33
33
|
it 'puts a bad syntax json file in the error files array' do
|
34
34
|
DataParser.json([fixtures_dir + 'hieradata/syntax.json'])
|
35
|
-
expect(PuppetCheck.error_files[0]).to match(%r{
|
35
|
+
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}hieradata/syntax.json:\n.*unexpected token})
|
36
36
|
expect(PuppetCheck.warning_files).to eql([])
|
37
37
|
expect(PuppetCheck.clean_files).to eql([])
|
38
38
|
end
|
39
39
|
it 'puts a bad metadata json file in the error files array' do
|
40
40
|
DataParser.json([fixtures_dir + 'metadata_syntax/metadata.json'])
|
41
|
-
expect(PuppetCheck.error_files[0]).to match(%r{
|
41
|
+
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}metadata_syntax/metadata.json:\nRequired field.*\nDuplicate dependencies.*\nDeprecated field.*\nSummary exceeds})
|
42
42
|
expect(PuppetCheck.warning_files).to eql([])
|
43
43
|
expect(PuppetCheck.clean_files).to eql([])
|
44
44
|
end
|
45
45
|
it 'puts a bad style metadata json file in the warning files array' do
|
46
46
|
DataParser.json([fixtures_dir + 'metadata_style/metadata.json'])
|
47
47
|
expect(PuppetCheck.error_files).to eql([])
|
48
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{
|
48
|
+
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}metadata_style/metadata.json:\n.*operatingsystem_support.*\nLicense identifier})
|
49
49
|
expect(PuppetCheck.clean_files).to eql([])
|
50
50
|
end
|
51
51
|
it 'puts a good json file in the clean files array' do
|
52
52
|
DataParser.json([fixtures_dir + 'hieradata/good.json'])
|
53
53
|
expect(PuppetCheck.error_files).to eql([])
|
54
54
|
expect(PuppetCheck.warning_files).to eql([])
|
55
|
-
expect(PuppetCheck.clean_files).to eql(["
|
55
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}hieradata/good.json"])
|
56
56
|
end
|
57
57
|
it 'puts a good metadata json file in the clean files array' do
|
58
58
|
DataParser.json([fixtures_dir + 'metadata_good/metadata.json'])
|
59
59
|
expect(PuppetCheck.error_files).to eql([])
|
60
60
|
expect(PuppetCheck.warning_files).to eql([])
|
61
|
-
expect(PuppetCheck.clean_files).to eql(["
|
61
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}metadata_good/metadata.json"])
|
62
62
|
end
|
63
63
|
end
|
64
64
|
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
require_relative '../../lib/puppet-check/output_results'
|
3
|
+
|
4
|
+
describe OutputResults do
|
5
|
+
context '.text' do
|
6
|
+
before(:each) do
|
7
|
+
PuppetCheck.error_files = []
|
8
|
+
PuppetCheck.warning_files = []
|
9
|
+
PuppetCheck.clean_files = []
|
10
|
+
PuppetCheck.ignored_files = []
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'outputs files with errors' do
|
14
|
+
PuppetCheck.error_files = ['foo: i had an error']
|
15
|
+
expect { OutputResults.text }.to output("\033[31mThe following files have errors:\033[0m\n-- foo: i had an error\n").to_stdout
|
16
|
+
end
|
17
|
+
it 'outputs files with warnings' do
|
18
|
+
PuppetCheck.warning_files = ['foo: i had a warning']
|
19
|
+
expect { OutputResults.text }.to output("\n\033[33mThe following files have warnings:\033[0m\n-- foo: i had a warning\n").to_stdout
|
20
|
+
end
|
21
|
+
it 'outputs files with no errors or warnings' do
|
22
|
+
PuppetCheck.clean_files = ['foo: i was totally good to go']
|
23
|
+
expect { OutputResults.text }.to output("\n\033[32mThe following files have no errors or warnings:\033[0m\n-- foo: i was totally good to go\n").to_stdout
|
24
|
+
end
|
25
|
+
it 'outputs files that were not processed' do
|
26
|
+
PuppetCheck.ignored_files = ['foo: who knows what i am']
|
27
|
+
expect { OutputResults.text }.to output("\n\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- foo: who knows what i am\n").to_stdout
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context '.markup' do
|
32
|
+
before(:each) do
|
33
|
+
PuppetCheck.error_files = []
|
34
|
+
PuppetCheck.warning_files = []
|
35
|
+
PuppetCheck.clean_files = []
|
36
|
+
PuppetCheck.ignored_files = []
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'outputs files with errors as yaml' do
|
40
|
+
PuppetCheck.output_format = 'yaml'
|
41
|
+
PuppetCheck.error_files = ['foo: i had an error']
|
42
|
+
expect { OutputResults.markup }.to output("---\nerrors:\n- 'foo: i had an error'\n").to_stdout
|
43
|
+
end
|
44
|
+
it 'outputs files with warnings as yaml' do
|
45
|
+
PuppetCheck.output_format = 'yaml'
|
46
|
+
PuppetCheck.warning_files = ['foo: i had a warning']
|
47
|
+
expect { OutputResults.markup }.to output("---\nwarnings:\n- 'foo: i had a warning'\n").to_stdout
|
48
|
+
end
|
49
|
+
it 'outputs files with no errors or warnings as yaml' do
|
50
|
+
PuppetCheck.output_format = 'yaml'
|
51
|
+
PuppetCheck.clean_files = ['foo: i was totally good to go']
|
52
|
+
expect { OutputResults.markup }.to output("---\nclean:\n- 'foo: i was totally good to go'\n").to_stdout
|
53
|
+
end
|
54
|
+
it 'outputs files that were not processed as yaml' do
|
55
|
+
PuppetCheck.output_format = 'yaml'
|
56
|
+
PuppetCheck.ignored_files = ['foo: who knows what i am']
|
57
|
+
expect { OutputResults.markup }.to output("---\nignored:\n- 'foo: who knows what i am'\n").to_stdout
|
58
|
+
end
|
59
|
+
it 'outputs files with errors as json' do
|
60
|
+
PuppetCheck.output_format = 'json'
|
61
|
+
PuppetCheck.error_files = ['foo: i had an error']
|
62
|
+
expect { OutputResults.markup }.to output("{\n \"errors\": [\n \"foo: i had an error\"\n ]\n}\n").to_stdout
|
63
|
+
end
|
64
|
+
it 'outputs files with warnings as json' do
|
65
|
+
PuppetCheck.output_format = 'json'
|
66
|
+
PuppetCheck.warning_files = ['foo: i had a warning']
|
67
|
+
expect { OutputResults.markup }.to output("{\n \"warnings\": [\n \"foo: i had a warning\"\n ]\n}\n").to_stdout
|
68
|
+
end
|
69
|
+
it 'outputs files with no errors or warnings as json' do
|
70
|
+
PuppetCheck.output_format = 'json'
|
71
|
+
PuppetCheck.clean_files = ['foo: i was totally good to go']
|
72
|
+
expect { OutputResults.markup }.to output("{\n \"clean\": [\n \"foo: i was totally good to go\"\n ]\n}\n").to_stdout
|
73
|
+
end
|
74
|
+
it 'outputs files that were not processed as json' do
|
75
|
+
PuppetCheck.output_format = 'json'
|
76
|
+
PuppetCheck.ignored_files = ['foo: who knows what i am']
|
77
|
+
expect { OutputResults.markup }.to output("{\n \"ignored\": [\n \"foo: who knows what i am\"\n ]\n}\n").to_stdout
|
78
|
+
end
|
79
|
+
it 'raises an error for an unsupported output format' do
|
80
|
+
PuppetCheck.output_format = 'awesomesauce'
|
81
|
+
expect { OutputResults.markup }.to raise_error(RuntimeError, 'puppet-check: Unsupported output format \'awesomesauce\' was specified.')
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -14,8 +14,8 @@ describe PuppetParser do
|
|
14
14
|
context '.manifest' do
|
15
15
|
it 'puts a bad syntax Puppet manifest in the error files array' do
|
16
16
|
PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'])
|
17
|
-
# expect(subject.instance_variable_get(:@error_files)[0]).to match(%r{
|
18
|
-
expect(PuppetCheck.error_files[0]).to match(%r{
|
17
|
+
# expect(subject.instance_variable_get(:@error_files)[0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:.*syntax error})
|
18
|
+
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
|
19
19
|
expect(PuppetCheck.warning_files).to eql([])
|
20
20
|
expect(PuppetCheck.clean_files).to eql([])
|
21
21
|
end
|
@@ -23,14 +23,14 @@ describe PuppetParser do
|
|
23
23
|
PuppetCheck.style_check = true
|
24
24
|
PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'])
|
25
25
|
expect(PuppetCheck.error_files).to eql([])
|
26
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{
|
26
|
+
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}manifests/style_parser.pp:\nUnrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing})
|
27
27
|
expect(PuppetCheck.clean_files).to eql([])
|
28
28
|
end
|
29
29
|
it 'puts a bad lint style Puppet manifest in the warning files array' do
|
30
30
|
PuppetCheck.style_check = true
|
31
31
|
PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'])
|
32
32
|
expect(PuppetCheck.error_files).to eql([])
|
33
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{
|
33
|
+
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*double quoted string containing.*\n.*indentation of})
|
34
34
|
expect(PuppetCheck.clean_files).to eql([])
|
35
35
|
end
|
36
36
|
it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
|
@@ -39,21 +39,26 @@ describe PuppetParser do
|
|
39
39
|
PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'])
|
40
40
|
expect(PuppetCheck.error_files).to eql([])
|
41
41
|
expect(PuppetCheck.warning_files).to eql([])
|
42
|
-
expect(PuppetCheck.clean_files).to eql(["
|
42
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
|
43
43
|
end
|
44
44
|
it 'puts a good Puppet manifest in the clean files array' do
|
45
45
|
PuppetCheck.style_check = true
|
46
46
|
PuppetParser.manifest([fixtures_dir + 'manifests/good.pp'])
|
47
47
|
expect(PuppetCheck.error_files).to eql([])
|
48
48
|
expect(PuppetCheck.warning_files).to eql([])
|
49
|
-
expect(PuppetCheck.clean_files).to eql(["
|
49
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}manifests/good.pp"])
|
50
|
+
end
|
51
|
+
it 'throws a well specified error for an invalid PuppetLint argument' do
|
52
|
+
PuppetCheck.style_check = true
|
53
|
+
PuppetCheck.puppetlint_args = ['--non-existent', '--does-not-exist']
|
54
|
+
expect { PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
|
50
55
|
end
|
51
56
|
end
|
52
57
|
|
53
58
|
context '.template' do
|
54
59
|
it 'puts a bad syntax Puppet template in the error files array' do
|
55
60
|
PuppetParser.template([fixtures_dir + 'templates/syntax.epp'])
|
56
|
-
expect(PuppetCheck.error_files[0]).to match(%r{
|
61
|
+
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}templates/syntax.epp:\nThis Name has no effect})
|
57
62
|
expect(PuppetCheck.warning_files).to eql([])
|
58
63
|
expect(PuppetCheck.clean_files).to eql([])
|
59
64
|
end
|
@@ -61,7 +66,7 @@ describe PuppetParser do
|
|
61
66
|
PuppetParser.template([fixtures_dir + 'templates/good.epp'])
|
62
67
|
expect(PuppetCheck.error_files).to eql([])
|
63
68
|
expect(PuppetCheck.warning_files).to eql([])
|
64
|
-
expect(PuppetCheck.clean_files).to eql(["
|
69
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}templates/good.epp"])
|
65
70
|
end
|
66
71
|
end
|
67
72
|
end
|
@@ -13,7 +13,7 @@ describe RubyParser do
|
|
13
13
|
context '.ruby' do
|
14
14
|
it 'puts a bad syntax ruby file in the error files array' do
|
15
15
|
RubyParser.ruby([fixtures_dir + 'lib/syntax.rb'])
|
16
|
-
expect(PuppetCheck.error_files[0]).to match(%r{
|
16
|
+
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}lib/syntax.rb:\n.*syntax error})
|
17
17
|
expect(PuppetCheck.warning_files).to eql([])
|
18
18
|
expect(PuppetCheck.clean_files).to eql([])
|
19
19
|
end
|
@@ -22,7 +22,7 @@ describe RubyParser do
|
|
22
22
|
PuppetCheck.style_check = true
|
23
23
|
RubyParser.ruby([fixtures_dir + 'lib/style.rb'])
|
24
24
|
expect(PuppetCheck.error_files).to eql([])
|
25
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{
|
25
|
+
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment})
|
26
26
|
expect(PuppetCheck.clean_files).to eql([])
|
27
27
|
end
|
28
28
|
else
|
@@ -30,7 +30,7 @@ describe RubyParser do
|
|
30
30
|
PuppetCheck.style_check = true
|
31
31
|
RubyParser.ruby([fixtures_dir + 'lib/style.rb'])
|
32
32
|
expect(PuppetCheck.error_files).to eql([])
|
33
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{
|
33
|
+
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}lib/style.rb:\n.*Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single})
|
34
34
|
expect(PuppetCheck.clean_files).to eql([])
|
35
35
|
end
|
36
36
|
end
|
@@ -40,57 +40,48 @@ describe RubyParser do
|
|
40
40
|
RubyParser.ruby([fixtures_dir + 'lib/rubocop_style.rb'])
|
41
41
|
expect(PuppetCheck.error_files).to eql([])
|
42
42
|
expect(PuppetCheck.warning_files).to eql([])
|
43
|
-
expect(PuppetCheck.clean_files).to eql(["
|
43
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}lib/rubocop_style.rb"])
|
44
44
|
end
|
45
45
|
it 'puts a good ruby file in the clean files array' do
|
46
46
|
PuppetCheck.style_check = true
|
47
47
|
RubyParser.ruby([fixtures_dir + 'lib/good.rb'])
|
48
48
|
expect(PuppetCheck.error_files).to eql([])
|
49
49
|
expect(PuppetCheck.warning_files).to eql([])
|
50
|
-
expect(PuppetCheck.clean_files).to eql(["
|
50
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}lib/good.rb"])
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
context '.template' do
|
55
55
|
it 'puts a bad syntax ruby template file in the error files array' do
|
56
56
|
RubyParser.template([fixtures_dir + 'templates/syntax.erb'])
|
57
|
-
expect(PuppetCheck.error_files[0]).to match(%r{
|
57
|
+
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}templates/syntax.erb:\n.*syntax error, unexpected tIDENTIFIER})
|
58
58
|
expect(PuppetCheck.warning_files).to eql([])
|
59
59
|
expect(PuppetCheck.clean_files).to eql([])
|
60
60
|
end
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
expect(PuppetCheck.clean_files).to eql([])
|
67
|
-
end
|
68
|
-
else
|
69
|
-
it 'puts a bad style ruby template file in the warning files array' do
|
70
|
-
RubyParser.template([fixtures_dir + 'templates/style.erb'])
|
71
|
-
expect(PuppetCheck.error_files).to eql([])
|
72
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{^\-\- #{fixtures_dir}templates/style.erb:})
|
73
|
-
expect(PuppetCheck.clean_files).to eql([])
|
74
|
-
end
|
61
|
+
it 'puts a bad style ruby template file in the warning files array' do
|
62
|
+
RubyParser.template([fixtures_dir + 'templates/style.erb'])
|
63
|
+
expect(PuppetCheck.error_files).to eql([])
|
64
|
+
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}templates/style.erb:\n.*already initialized constant.*\n.*previous definition of})
|
65
|
+
expect(PuppetCheck.clean_files).to eql([])
|
75
66
|
end
|
76
67
|
it 'puts a ruby template file with ignored errors in the clean files array' do
|
77
68
|
RubyParser.template([fixtures_dir + 'templates/no_method_error.erb'])
|
78
69
|
expect(PuppetCheck.error_files).to eql([])
|
79
70
|
expect(PuppetCheck.warning_files).to eql([])
|
80
|
-
expect(PuppetCheck.clean_files).to eql(["
|
71
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}templates/no_method_error.erb"])
|
81
72
|
end
|
82
73
|
it 'puts a good ruby template file in the clean files array' do
|
83
74
|
RubyParser.template([fixtures_dir + 'templates/good.erb'])
|
84
75
|
expect(PuppetCheck.error_files).to eql([])
|
85
76
|
expect(PuppetCheck.warning_files).to eql([])
|
86
|
-
expect(PuppetCheck.clean_files).to eql(["
|
77
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}templates/good.erb"])
|
87
78
|
end
|
88
79
|
end
|
89
80
|
|
90
81
|
context '.librarian' do
|
91
82
|
it 'puts a bad syntax librarian Puppet file in the error files array' do
|
92
83
|
RubyParser.librarian([fixtures_dir + 'librarian_syntax/Puppetfile'])
|
93
|
-
expect(PuppetCheck.error_files[0]).to match(%r{
|
84
|
+
expect(PuppetCheck.error_files[0]).to match(%r{^#{fixtures_dir}librarian_syntax/Puppetfile:\n.*syntax error})
|
94
85
|
expect(PuppetCheck.warning_files).to eql([])
|
95
86
|
expect(PuppetCheck.clean_files).to eql([])
|
96
87
|
end
|
@@ -98,7 +89,7 @@ describe RubyParser do
|
|
98
89
|
PuppetCheck.style_check = true
|
99
90
|
RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'])
|
100
91
|
expect(PuppetCheck.error_files).to eql([])
|
101
|
-
expect(PuppetCheck.warning_files[0]).to match(%r{
|
92
|
+
expect(PuppetCheck.warning_files[0]).to match(%r{^#{fixtures_dir}librarian_style/Puppetfile:\n.*Align the parameters.*\n.*Use the new})
|
102
93
|
expect(PuppetCheck.clean_files).to eql([])
|
103
94
|
end
|
104
95
|
it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
|
@@ -107,14 +98,14 @@ describe RubyParser do
|
|
107
98
|
RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'])
|
108
99
|
expect(PuppetCheck.error_files).to eql([])
|
109
100
|
expect(PuppetCheck.warning_files).to eql([])
|
110
|
-
expect(PuppetCheck.clean_files).to eql(["
|
101
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}librarian_style/Puppetfile"])
|
111
102
|
end
|
112
103
|
it 'puts a good librarian Puppet file in the clean files array' do
|
113
104
|
PuppetCheck.style_check = true
|
114
105
|
RubyParser.librarian([fixtures_dir + 'librarian_good/Puppetfile'])
|
115
106
|
expect(PuppetCheck.error_files).to eql([])
|
116
107
|
expect(PuppetCheck.warning_files).to eql([])
|
117
|
-
expect(PuppetCheck.clean_files).to eql(["
|
108
|
+
expect(PuppetCheck.clean_files).to eql(["#{fixtures_dir}librarian_good/Puppetfile"])
|
118
109
|
end
|
119
110
|
end
|
120
111
|
end
|
data/spec/puppet-check_spec.rb
CHANGED
@@ -54,29 +54,7 @@ describe PuppetCheck do
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
context '.
|
58
|
-
|
59
|
-
PuppetCheck.error_files = []
|
60
|
-
PuppetCheck.warning_files = []
|
61
|
-
PuppetCheck.clean_files = []
|
62
|
-
PuppetCheck.ignored_files = []
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'outputs files with errors' do
|
66
|
-
PuppetCheck.error_files = ['-- foo: i had an error']
|
67
|
-
expect { PuppetCheck.output_results }.to output("\033[31mThe following files have errors:\033[0m\n-- foo: i had an error\n").to_stdout
|
68
|
-
end
|
69
|
-
it 'outputs files with warnings' do
|
70
|
-
PuppetCheck.warning_files = ['-- foo: i had a warning']
|
71
|
-
expect { PuppetCheck.output_results }.to output("\n\033[33mThe following files have warnings:\033[0m\n-- foo: i had a warning\n").to_stdout
|
72
|
-
end
|
73
|
-
it 'outputs files with no errors or warnings' do
|
74
|
-
PuppetCheck.clean_files = ['-- foo: i was totally good to go']
|
75
|
-
expect { PuppetCheck.output_results }.to output("\n\033[32mThe following files have no errors or warnings:\033[0m\n-- foo: i was totally good to go\n").to_stdout
|
76
|
-
end
|
77
|
-
it 'outputs files that were not processed' do
|
78
|
-
PuppetCheck.ignored_files = ['-- foo: who knows what i am']
|
79
|
-
expect { PuppetCheck.output_results }.to output("\n\033[36mThe following files have unrecognized formats and therefore were not processed:\033[0m\n-- foo: who knows what i am\n").to_stdout
|
80
|
-
end
|
57
|
+
context '.execute_parsers' do
|
58
|
+
#
|
81
59
|
end
|
82
60
|
end
|
data/spec/system/system_spec.rb
CHANGED
@@ -3,19 +3,21 @@ require_relative '../spec_helper.rb'
|
|
3
3
|
require_relative '../../lib/puppet-check/cli'
|
4
4
|
require_relative '../../lib/puppet-check/tasks'
|
5
5
|
|
6
|
-
describe
|
6
|
+
describe PuppetCheck do
|
7
7
|
context 'executed as a system from the CLI with arguments and various files to be processed' do
|
8
8
|
let(:cli) { PuppetCheck::CLI.run(%w(-s --puppet-lint no-hard_tabs-check,no-140chars-check --rubocop Metrics/LineLength,Style/Encoding .)) }
|
9
9
|
|
10
10
|
it 'outputs diagnostic results correctly after processing all of the files' do
|
11
11
|
Dir.chdir(fixtures_dir)
|
12
12
|
|
13
|
-
expect(cli).to eql(2)
|
14
13
|
expect { cli }.not_to raise_exception
|
14
|
+
|
15
15
|
expect(PuppetCheck.error_files.length).to eql(8)
|
16
16
|
expect(PuppetCheck.warning_files.length).to eql(8)
|
17
17
|
expect(PuppetCheck.clean_files.length).to eql(11)
|
18
18
|
expect(PuppetCheck.ignored_files.length).to eql(1)
|
19
|
+
|
20
|
+
expect(cli).to eql(2)
|
19
21
|
end
|
20
22
|
end
|
21
23
|
|
@@ -25,14 +27,16 @@ describe 'PuppetCheck' do
|
|
25
27
|
it 'outputs diagnostic results correctly after processing all of the files' do
|
26
28
|
# ensure rake only checks the files inside fixtures
|
27
29
|
Dir.chdir(fixtures_dir)
|
30
|
+
|
31
|
+
# clear out arrays from previous system test
|
28
32
|
PuppetCheck.error_files = []
|
29
33
|
PuppetCheck.warning_files = []
|
30
34
|
PuppetCheck.clean_files = []
|
31
35
|
PuppetCheck.ignored_files = []
|
32
36
|
PuppetCheck.style_check = true
|
33
37
|
|
34
|
-
expect(tasks).to eql(2)
|
35
38
|
expect { tasks }.not_to raise_exception
|
39
|
+
|
36
40
|
expect(PuppetCheck.error_files.length).to eql(8)
|
37
41
|
expect(PuppetCheck.warning_files.length).to eql(8)
|
38
42
|
expect(PuppetCheck.clean_files.length).to eql(11)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Schuchard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.4'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '3.
|
29
|
+
version: '3.4'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '5'
|
@@ -122,6 +122,7 @@ files:
|
|
122
122
|
- lib/puppet-check.rb
|
123
123
|
- lib/puppet-check/cli.rb
|
124
124
|
- lib/puppet-check/data_parser.rb
|
125
|
+
- lib/puppet-check/output_results.rb
|
125
126
|
- lib/puppet-check/puppet_parser.rb
|
126
127
|
- lib/puppet-check/rspec_puppet_support.rb
|
127
128
|
- lib/puppet-check/ruby_parser.rb
|
@@ -158,6 +159,7 @@ files:
|
|
158
159
|
- spec/fixtures/templates/syntax.erb
|
159
160
|
- spec/puppet-check/cli_spec.rb
|
160
161
|
- spec/puppet-check/data_parser_spec.rb
|
162
|
+
- spec/puppet-check/output_results_spec.rb
|
161
163
|
- spec/puppet-check/puppet_parser_spec.rb
|
162
164
|
- spec/puppet-check/rspec_puppet_support_spec.rb
|
163
165
|
- spec/puppet-check/ruby_parser_spec.rb
|
@@ -178,7 +180,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
178
180
|
requirements:
|
179
181
|
- - ">="
|
180
182
|
- !ruby/object:Gem::Version
|
181
|
-
version:
|
183
|
+
version: 2.0.0
|
182
184
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
183
185
|
requirements:
|
184
186
|
- - ">="
|
@@ -186,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
188
|
version: '0'
|
187
189
|
requirements: []
|
188
190
|
rubyforge_project:
|
189
|
-
rubygems_version: 2.
|
191
|
+
rubygems_version: 2.5.1
|
190
192
|
signing_key:
|
191
193
|
specification_version: 4
|
192
194
|
summary: A streamlined comprehensive set of checks for your entire Puppet code and
|
@@ -223,6 +225,7 @@ test_files:
|
|
223
225
|
- spec/fixtures/templates/syntax.erb
|
224
226
|
- spec/puppet-check/cli_spec.rb
|
225
227
|
- spec/puppet-check/data_parser_spec.rb
|
228
|
+
- spec/puppet-check/output_results_spec.rb
|
226
229
|
- spec/puppet-check/puppet_parser_spec.rb
|
227
230
|
- spec/puppet-check/rspec_puppet_support_spec.rb
|
228
231
|
- spec/puppet-check/ruby_parser_spec.rb
|