puppet-check 1.6.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4351237d9dbb4f8790fb4b3aa77dce9a3274b9146b566261ca089c4759c634ee
4
- data.tar.gz: 4a6c8d9e48b456bea5a130e3984613f7cb923891c9fe6779ac481ffdc043a3c1
3
+ metadata.gz: 9d2defe55b01e90b73fc2cb3dfc12b9004fbe02b73fc751b736529e454c0c92b
4
+ data.tar.gz: 96bce3d495f0a5778d5475659ba3fbf6360290ef565666478933cd867babc34d
5
5
  SHA512:
6
- metadata.gz: dcf4c5c9ec7906f130f8ae74f61b1efaab297d33276f1587c88ac68bea8f25a09aa1deeac0ede9cee835e0b2bed95b404e1a208649df29e76693d56a37ab867c
7
- data.tar.gz: 1b4a1c372216d42d5e0e547e98a606866d0576da2e494d56340eb7a025e0f3763a9139ca18c24165a473c03429c1cf271ca0606017889e29dfbead14a0e5e7da
6
+ metadata.gz: 52037386f7f9168822a8cc14da2455d3a6a2f38cc3686ef7edbed65bee382a07159328c9ca3e1472c97d533e0966b431b921d78380bec684489e7528ec443694
7
+ data.tar.gz: 859c21981164a0e002c6e8faeec55b285aa65d7cd953b838415873d482f7a32acf4ede39049329eb9435f435a7a96b741749a7501e1a0cfd045c43444f5cbc94
@@ -1,4 +1,14 @@
1
- ### 1.6.1 (Next)
1
+ ### 2.0.0
2
+ - Bump minimum version of Puppet to 4.0.0 and remove < 4 support code.
3
+ - Official support for Puppet 6.
4
+ - Minimum Ruby version bumped to 2.2.0.
5
+ - Bumped Rubocop and Reek minimum versions and fully migrated SPDX to Rubygems.
6
+ - Add rubocop-performance extension to Rubocop.
7
+ - Update manifest validation for breaking change in 6.5 API.
8
+ - Fix check on specified dependencies in metadata.
9
+ - Enable parallel module dependency retrieval.
10
+
11
+ ### 1.6.1
2
12
  - Removed check for hieradata nil/undef value for Hiera >= 5.
3
13
  - Add rudimentary checks for task metadata.
4
14
  - Preliminary support for Puppet 6.
data/README.md CHANGED
@@ -131,7 +131,6 @@ Please see the [Gemspec](puppet-check.gemspec) for dependency information. All
131
131
  ```
132
132
  usage: puppet-check [options] paths
133
133
  --version Display the current version.
134
- -f, --future Enable future parser
135
134
  --fail-on-warnings Fail on warnings
136
135
  -s, --style Enable style checks
137
136
  --smoke Enable smoke testing
@@ -148,7 +147,7 @@ usage: puppet-check [options] paths
148
147
  --rubocop arg_one,arg_two Arguments for Rubocop disabled cops
149
148
  ```
150
149
 
151
- The command line interface enables the ability to select the Puppet future parser, additional style checks besides the syntax checks, and to specify PuppetLint and Rubocop checks to ignore. If you require a more robust interface to PuppetLint, Rubocop, and Reek, then please use `.puppet-lint.rc`, `.rubocop.yml` and `*.reek` config files. The `.puppet-lint.rc` can be specified with the `-c` argument. If it is not specified, then PuppetLint will automatically load one from `.puppet-lint.rc`, `~/.puppet-lint.rc`, or `/etc/puppet-lint.rc`, in that order of preference. The nearest `.rubocop.yml` and `*.reek` will be automatically respected.
150
+ The command line interface enables the ability to select additional style checks besides the syntax checks, and to specify PuppetLint and Rubocop checks to ignore. If you require a more robust interface to PuppetLint, Rubocop, and Reek, then please use `.puppet-lint.rc`, `.rubocop.yml` and `*.reek` config files. The `.puppet-lint.rc` can be specified with the `-c` argument. If it is not specified, then PuppetLint will automatically load one from `.puppet-lint.rc`, `~/.puppet-lint.rc`, or `/etc/puppet-lint.rc`, in that order of preference. The nearest `.rubocop.yml` and `*.reek` will be automatically respected.
152
151
 
153
152
  Example:
154
153
  ```
@@ -167,15 +166,14 @@ rake puppetcheck:kitchen:* # Execute Test Kitchen acceptance tests
167
166
  ```
168
167
 
169
168
  #### puppetcheck:file
170
- You can add style, smoke, and regression checks to and select the future parser for the `rake puppetcheck:file`, or change the output format, by adding the following after the require:
169
+ You can add style, smoke, and regression checks to the `rake puppetcheck:file`, or change the output format, by adding the following after the require:
171
170
 
172
171
  ```ruby
173
172
  # example of modifying Puppet Check behavior
174
- PuppetCheck.settings[:style_check] = true
173
+ PuppetCheck.settings[:style] = true
175
174
  PuppetCheck.settings[:fail_on_warnings] = true
176
- PuppetCheck.settings[:future_parser] = true
177
- PuppetCheck.settings[:smoke_check] = true
178
- PuppetCheck.settings[:regression_check] = true # in progress, do not use
175
+ PuppetCheck.settings[:smoke] = true
176
+ PuppetCheck.settings[:regression] = true # in progress, do not use
179
177
  PuppetCheck.settings[:public] = 'public.pem'
180
178
  PuppetCheck.settings[:private] = 'private.pem'
181
179
  PuppetCheck.settings[:output_format] = 'yaml'
@@ -256,11 +254,10 @@ If you are performing your Puppet testing from within a Ruby script or your own
256
254
  require 'puppet-check'
257
255
 
258
256
  settings = {}
259
- settings[:future_parser] = true # default false
260
257
  settings[:fail_on_warnings] = true # default false
261
- settings[:style_check] = true # default false
262
- settings[:smoke_check] = true # default false
263
- settings[:regression_check] = true # in progress, do not use; default false
258
+ settings[:style] = true # default false
259
+ settings[:smoke] = true # default false
260
+ settings[:regression] = true # in progress, do not use; default false
264
261
  settings[:public] = 'public.pem' # default nil
265
262
  settings[:private] = 'private.pem' # default nil
266
263
  settings[:output_format] = 'yaml' # also 'json'; default 'text'
@@ -301,6 +298,8 @@ ENTRYPOINT ["rake", "puppetcheck"]
301
298
 
302
299
  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.
303
300
 
301
+ As an alternative to copying Puppet code and data into the image for testing, it is also recommended to bind volume mount the container to the directory with your Puppet code and data.
302
+
304
303
  ### Vagrant
305
304
 
306
305
  As an alternative to Docker, you can also use Vagrant for quick and disposable testing, but it is not as portable as Docker for these testing purposes. Below is an example Vagrantfile for this purpose.
@@ -19,19 +19,19 @@ class PuppetCheck
19
19
  self.class.settings = settings
20
20
 
21
21
  # settings defaults
22
- self.class.defaults
22
+ self.class.defaults(settings)
23
23
 
24
24
  # grab all of the files to be processed
25
25
  files = self.class.parse_paths(paths)
26
26
 
27
27
  # parse the files
28
- execute_parsers(files, settings[:future_parser], settings[:style_check], settings[:public], settings[:private], settings[:puppetlint_args], settings[:rubocop_args])
28
+ execute_parsers(files, settings)
29
29
 
30
30
  # output the diagnostic results
31
- settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup
31
+ settings[:output_format] == 'text' ? OutputResults.text : OutputResults.markup(settings)
32
32
 
33
33
  # progress to regression checks if no errors in file checks
34
- if self.class.settings[:error_files].empty? && (!self.class.settings[:fail_on_warning] || self.class.settings[:warning_files].empty?)
34
+ if self.class.settings[:error_files].empty? && (!settings[:fail_on_warning] || self.class.settings[:warning_files].empty?)
35
35
  begin
36
36
  require_relative 'puppet-check/regression_check'
37
37
  # if octocatalog-diff is not installed then return immediately
@@ -41,7 +41,7 @@ class PuppetCheck
41
41
 
42
42
  # perform smoke checks if there were no errors and the user desires
43
43
  begin
44
- catalog = RegressionCheck.smoke(settings[:octonodes], settings[:octoconfig]) if settings[:smoke_check]
44
+ catalog = RegressionCheck.smoke(settings[:octonodes], settings[:octoconfig]) if settings[:smoke]
45
45
  # smoke check failure? output message and return 2
46
46
  rescue OctocatalogDiff::Errors::CatalogError => err
47
47
  puts 'There was a smoke check error:'
@@ -51,7 +51,7 @@ class PuppetCheck
51
51
  end
52
52
  # perform regression checks if there were no errors and the user desires
53
53
  # begin
54
- # catalog = RegressionCheck.regression(settings[:octonodes], settings[:octoconfig]) if settings[:regression_check]
54
+ # catalog = RegressionCheck.regression(settings[:octonodes], settings[:octoconfig]) if settings[:regression]
55
55
  # rescue OctocatalogDiff::Errors::CatalogError => err
56
56
  # puts 'There was a catalog compilation error during the regression check:'
57
57
  # puts err
@@ -68,20 +68,19 @@ class PuppetCheck
68
68
  end
69
69
 
70
70
  # establish default settings
71
- def self.defaults
72
- # initialize future parser, fail on warning, style check, and regression check bools
73
- @settings[:future_parser] ||= false
74
- @settings[:fail_on_warning] ||= false
75
- @settings[:style_check] ||= false
76
- @settings[:smoke_check] ||= false
77
- @settings[:regression_check] ||= false
71
+ def self.defaults(settings)
72
+ # initialize fail on warning, style check, and regression check bools
73
+ settings[:fail_on_warning] ||= false
74
+ settings[:style] ||= false
75
+ settings[:smoke] ||= false
76
+ settings[:regression] ||= false
78
77
 
79
78
  # initialize ssl keys for eyaml checks
80
- @settings[:public] ||= nil
81
- @settings[:private] ||= nil
79
+ settings[:public] ||= nil
80
+ settings[:private] ||= nil
82
81
 
83
82
  # initialize output format option
84
- @settings[:output_format] ||= 'text'
83
+ settings[:output_format] ||= 'text'
85
84
 
86
85
  # initialize diagnostic output arrays
87
86
  @settings[:error_files] = []
@@ -90,12 +89,12 @@ class PuppetCheck
90
89
  @settings[:ignored_files] = []
91
90
 
92
91
  # initialize octocatalog-diff options
93
- @settings[:octoconfig] ||= '.octocatalog-diff.cfg.rb'
94
- @settings[:octonodes] ||= %w[localhost.localdomain]
92
+ settings[:octoconfig] ||= '.octocatalog-diff.cfg.rb'
93
+ settings[:octonodes] ||= %w[localhost.localdomain]
95
94
 
96
95
  # initialize style arg arrays
97
- @settings[:puppetlint_args] ||= []
98
- @settings[:rubocop_args] ||= []
96
+ settings[:puppetlint_args] ||= []
97
+ settings[:rubocop_args] ||= []
99
98
  end
100
99
 
101
100
  # parse the paths and return the array of files
@@ -120,16 +119,16 @@ class PuppetCheck
120
119
  end
121
120
 
122
121
  # categorize and pass the files out to the parsers to determine their status
123
- def execute_parsers(files, future, style, public, private, pl_args, rc_args)
122
+ def execute_parsers(files, settings)
124
123
  # check manifests
125
124
  manifests, files = files.partition { |file| File.extname(file) == '.pp' }
126
- PuppetParser.manifest(manifests, future, style, pl_args) unless manifests.empty?
125
+ PuppetParser.manifest(manifests, settings[:style], settings[:puppetlint_args]) unless manifests.empty?
127
126
  # check puppet templates
128
127
  templates, files = files.partition { |file| File.extname(file) == '.epp' }
129
128
  PuppetParser.template(templates) unless templates.empty?
130
129
  # check ruby files
131
130
  rubies, files = files.partition { |file| File.extname(file) == '.rb' }
132
- RubyParser.ruby(rubies, style, rc_args) unless rubies.empty?
131
+ RubyParser.ruby(rubies, settings[:style], settings[:rubocop_args]) unless rubies.empty?
133
132
  # check ruby templates
134
133
  templates, files = files.partition { |file| File.extname(file) == '.erb' }
135
134
  RubyParser.template(templates) unless templates.empty?
@@ -144,7 +143,7 @@ class PuppetCheck
144
143
  # DataParser.eyaml(eyamls, public, private) unless eyamls.empty?
145
144
  # check misc ruby
146
145
  librarians, files = files.partition { |file| File.basename(file) =~ /(?:Puppet|Module|Rake|Gem)file$/ }
147
- RubyParser.librarian(librarians, style, rc_args) unless librarians.empty?
146
+ RubyParser.librarian(librarians, settings[:style], settings[:rubocop_args]) unless librarians.empty?
148
147
  # ignore everything else
149
148
  self.class.settings[:ignored_files].concat(files)
150
149
  end
@@ -27,16 +27,15 @@ class PuppetCheck::CLI
27
27
 
28
28
  # base options
29
29
  opts.on('--version', 'Display the current version.') do
30
- puts 'puppet-check 1.6.1'
30
+ puts 'puppet-check 2.0.0'
31
31
  exit 0
32
32
  end
33
33
 
34
34
  # bool options
35
- opts.on('-f', '--future', 'Enable future parser') { settings[:future_parser] = true }
36
35
  opts.on('--fail-on-warnings', 'Fail on warnings') { settings[:fail_on_warnings] = true }
37
- opts.on('-s', '--style', 'Enable style checks') { settings[:style_check] = true }
38
- opts.on('--smoke', 'Enable smoke testing') { settings[:smoke_check] = true }
39
- opts.on('-r', '--regression', 'Enable regression testing (in progress, do not use)') { settings[:regression_check] = true }
36
+ opts.on('-s', '--style', 'Enable style checks') { settings[:style] = true }
37
+ opts.on('--smoke', 'Enable smoke testing') { settings[:smoke] = true }
38
+ opts.on('-r', '--regression', 'Enable regression testing (in progress, do not use)') { settings[:regression] = true }
40
39
 
41
40
  # ssl key options for eyaml checks
42
41
  opts.on('--public cert.pem', String, 'Public key for EYAML checks') { |arg| settings[:public] = arg }
@@ -85,7 +85,7 @@ class DataParser
85
85
  # check metadata.json
86
86
  if File.basename(file) == 'metadata.json'
87
87
  # metadata-json-lint has issues and is essentially no longer maintained, so here is an improved and leaner version of it
88
- require 'spdx-licenses'
88
+ require 'rubygems/util/licenses'
89
89
 
90
90
  # check for errors
91
91
  errors = []
@@ -97,7 +97,7 @@ class DataParser
97
97
 
98
98
  # check requirements and dependencies keys
99
99
  %w[requirements dependencies].each do |key|
100
- # skip if key is missing or or value is an empty string, array, or hash
100
+ # skip if key is missing or value is an empty string, array, or hash
101
101
  next if !parsed.key?(key) || parsed[key].empty?
102
102
 
103
103
  # check that dependencies and requirements are an array of hashes
@@ -161,16 +161,8 @@ class DataParser
161
161
  end
162
162
 
163
163
  # check for spdx license
164
- begin
165
- require 'rubygems/util/licenses'
166
-
167
- if parsed.key?('license') && !Gem::Licenses.match?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
168
- warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/")
169
- end
170
- rescue LoadError
171
- if parsed.key?('license') && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
172
- warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/")
173
- end
164
+ if parsed.key?('license') && !Gem::Licenses.match?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/
165
+ warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/")
174
166
  end
175
167
  # assume this is task metadata if it has this key
176
168
  elsif parsed.key?('description')
@@ -22,7 +22,7 @@ class OutputResults
22
22
  end
23
23
 
24
24
  # output the results as yaml or json
25
- def self.markup
25
+ def self.markup(settings)
26
26
  # generate output hash
27
27
  hash = {}
28
28
  hash['errors'] = PuppetCheck.settings[:error_files] unless PuppetCheck.settings[:error_files].empty?
@@ -31,14 +31,14 @@ class OutputResults
31
31
  hash['ignored'] = PuppetCheck.settings[:ignored_files] unless PuppetCheck.settings[:ignored_files].empty?
32
32
 
33
33
  # convert hash to markup language
34
- if PuppetCheck.settings[:output_format] == 'yaml'
34
+ if settings[:output_format] == 'yaml'
35
35
  require 'yaml'
36
36
  puts Psych.dump(hash, indentation: 2)
37
- elsif PuppetCheck.settings[:output_format] == 'json'
37
+ elsif settings[:output_format] == 'json'
38
38
  require 'json'
39
39
  puts JSON.pretty_generate(hash)
40
40
  else
41
- raise "puppet-check: Unsupported output format '#{PuppetCheck.settings[:output_format]}' was specified."
41
+ raise "puppet-check: Unsupported output format '#{settings[:output_format]}' was specified."
42
42
  end
43
43
  end
44
44
  end
@@ -4,25 +4,29 @@ require_relative '../puppet-check'
4
4
  # executes diagnostics on puppet files
5
5
  class PuppetParser
6
6
  # checks puppet (.pp)
7
- def self.manifest(files, future, style, pl_args)
7
+ def self.manifest(files, style, pl_args)
8
8
  require 'puppet/face'
9
9
 
10
10
  # prepare the Puppet settings for the error checking
11
11
  Puppet.initialize_settings unless Puppet.settings.app_defaults_initialized?
12
- Puppet[:parser] = 'future' if future && (Puppet::PUPPETVERSION.to_i < 4)
13
12
 
14
13
  files.each do |file|
15
- # setup error logging and collection
14
+ # setup error logging and collection; warnings logged for all versions, but errors for only puppet < 6.5
16
15
  errors = []
17
16
  Puppet::Util::Log.newdestination(Puppet::Test::LogCollector.new(errors))
18
17
 
19
18
  # check puppet syntax
20
19
  begin
21
- Puppet::Face[:parser, :current].validate(file)
20
+ # in puppet >= 6.5 the return of this method is a hash with the error
21
+ new_error = Puppet::Face[:parser, :current].validate(file)
22
+ # puppet 6.5 output format is now a hash from the face api
23
+ if Puppet::PUPPETVERSION.to_f >= 6.5 && new_error != {}
24
+ next PuppetCheck.settings[:error_files].push("#{file}:\n#{new_error.values.map(&:to_s).join("\n").gsub(/ \(file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '')}")
25
+ end
22
26
  # this is the actual error that we need to rescue Puppet::Face from
23
27
  rescue SystemExit
24
- # puppet 5.4-5.x has a new validator output format and eof errors have fake dir env info
25
- if Puppet::PUPPETVERSION.to_f >= 5.4
28
+ # puppet 5.4-6.4 has a new validator output format and eof errors have fake dir env info
29
+ if Puppet::PUPPETVERSION.to_f >= 5.4 && Puppet::PUPPETVERSION.to_f < 6.5
26
30
  next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.map(&:to_s).join("\n").gsub(/file: #{File.absolute_path(file)}(, |\))/, '').gsub(/Could not parse.*: /, '')}")
27
31
  # puppet 5.0-5.2 can only do one error per line and outputs fake dir env info
28
32
  elsif Puppet::PUPPETVERSION.to_f >= 5.0 && Puppet::PUPPETVERSION.to_f < 5.3
@@ -77,9 +81,6 @@ class PuppetParser
77
81
  require 'puppet/pops'
78
82
 
79
83
  files.each do |file|
80
- # puppet before version 4 cannot check template syntax
81
- next PuppetCheck.settings[:ignored_files].push("#{file}: ignored due to Puppet < 4") if Puppet::PUPPETVERSION.to_i < 4
82
-
83
84
  # check puppet template syntax
84
85
  begin
85
86
  # credits to gds-operations/puppet-syntax for the parser function call
@@ -66,7 +66,7 @@ class RSpecPuppetSupport
66
66
  parsed = JSON.parse(File.read('metadata.json'))
67
67
 
68
68
  # grab dependencies if they exist
69
- return if parsed['dependencies'].empty?
69
+ return unless parsed.key?('dependencies')
70
70
  parsed['dependencies'].each do |dependency_hash|
71
71
  # determine how the user wants to download the module dependency
72
72
  if dependency_hash.key?('git')
@@ -81,6 +81,7 @@ class RSpecPuppetSupport
81
81
  warn "#{dependency_hash['name']} has an unspecified, or specified but unsupported, download method."
82
82
  end
83
83
  end
84
+ Process.waitall
84
85
  end
85
86
 
86
87
  # download external module dependency with git
@@ -89,7 +90,7 @@ class RSpecPuppetSupport
89
90
  # establish path to clone module to
90
91
  path = "spec/fixtures/modules/#{File.basename(git_url, '.git')}"
91
92
  # is the module present and already cloned with git? do a pull; otherwise, do a clone
92
- File.directory?("#{path}/.git") ? system("git -C #{path} pull") : system("git clone #{args} #{git_url} #{path}")
93
+ File.directory?("#{path}/.git") ? spawn("git -C #{path} pull") : spawn("git clone #{args} #{git_url} #{path}")
93
94
  end
94
95
 
95
96
  # download external module dependency with forge
@@ -97,7 +98,7 @@ class RSpecPuppetSupport
97
98
  private_class_method :method
98
99
  # is the module present? do an upgrade; otherwise, do an install
99
100
  subcommand = File.directory?("spec/fixtures/modules/#{forge_name}") ? 'upgrade' : 'install'
100
- system("puppet module #{subcommand} --modulepath spec/fixtures/modules/ #{args} #{forge_name}")
101
+ spawn("puppet module #{subcommand} --modulepath spec/fixtures/modules/ #{args} #{forge_name}")
101
102
  end
102
103
 
103
104
  # download external module dependency with svn
@@ -106,7 +107,7 @@ class RSpecPuppetSupport
106
107
  # establish path to checkout module to
107
108
  path = "spec/fixtures/modules/#{File.basename(svn_url)}"
108
109
  # is the module present and already checked out with svn? do an update; otherwise, do a checkout
109
- File.directory?("#{path}/.svn") ? system("svn update #{path}") : system("svn co #{args} #{svn_url} #{path}")
110
+ File.directory?("#{path}/.svn") ? spawn("svn update #{path}") : spawn("svn co #{args} #{svn_url} #{path}")
110
111
  end
111
112
 
112
113
  # download external module dependency with hg
@@ -115,6 +116,6 @@ class RSpecPuppetSupport
115
116
  # establish path to clone module to
116
117
  path = "spec/fixtures/modules/#{File.basename(hg_url)}"
117
118
  # is the module present and already cloned with hg? do a pull and update; otherwise do a clone
118
- File.directory?("#{path}/.hg") ? system("hg --cwd #{path} pull; hg --cwd #{path} update") : system("hg clone #{args} #{hg_url} #{path}")
119
+ File.directory?("#{path}/.hg") ? spawn("hg --cwd #{path} pull; hg --cwd #{path} update") : spawn("hg clone #{args} #{hg_url} #{path}")
119
120
  end
120
121
  end
@@ -18,7 +18,7 @@ class RubyParser
18
18
  require 'rubocop'
19
19
 
20
20
  # check RuboCop and collect warnings
21
- rubocop_warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--format', 'emacs', file]) }
21
+ rubocop_warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--require', 'rubocop-performance', '--format', 'emacs', file]) }
22
22
  warnings = rubocop_warnings == '' ? '' : rubocop_warnings.split("#{File.absolute_path(file)}:").join('')
23
23
 
24
24
  # check Reek and collect warnings
@@ -79,7 +79,7 @@ class RubyParser
79
79
  else
80
80
  if style
81
81
  # check Rubocop
82
- warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--format', 'emacs', file]) }
82
+ warnings = Utils.capture_stdout { RuboCop::CLI.new.run(rc_args + ['--require', 'rubocop-performance', '--format', 'emacs', file]) }
83
83
 
84
84
  # collect style warnings
85
85
  next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.split("#{File.absolute_path(file)}:").join('')}") unless warnings.empty?
@@ -13,8 +13,8 @@ describe PuppetCheck::CLI do
13
13
  expect { PuppetCheck::CLI.parse(%w[-s -f -asdf foo]) }.to raise_error(OptionParser::InvalidOption)
14
14
  end
15
15
 
16
- it 'allows future parser, fail on warnings, style, smoke, and regression checks to be enabled' do
17
- expect(PuppetCheck::CLI.parse(%w[-f --fail-on-warnings -s -r --smoke foo])).to include(future_parser: true, fail_on_warnings: true, style_check: true, smoke_check: true, regression_check: true)
16
+ it 'allows fail on warnings, style, smoke, and regression checks to be enabled' do
17
+ expect(PuppetCheck::CLI.parse(%w[--fail-on-warnings -s -r --smoke foo])).to include(fail_on_warnings: true, style: true, smoke: true, regression: true)
18
18
  end
19
19
 
20
20
  it 'correctly parser EYAML options' do
@@ -42,7 +42,7 @@ describe PuppetCheck::CLI do
42
42
  end
43
43
 
44
44
  it 'correctly parses multiple sets of arguments' do
45
- expect(PuppetCheck::CLI.parse(%w[-s -f --puppet-lint puppetlint-arg-one,puppetlint-arg-two --rubocop rubocop-arg-one,rubocop-arg-two foo])).to include(future_parser: true, style_check: true, puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'], rubocop_args: ['--except', 'rubocop-arg-one,rubocop-arg-two'])
45
+ expect(PuppetCheck::CLI.parse(%w[-s --puppet-lint puppetlint-arg-one,puppetlint-arg-two --rubocop rubocop-arg-one,rubocop-arg-two foo])).to include(style: true, puppetlint_args: ['--puppetlint-arg-one', '--puppetlint-arg-two'], rubocop_args: ['--except', 'rubocop-arg-one,rubocop-arg-two'])
46
46
  end
47
47
  end
48
48
  end
@@ -37,48 +37,39 @@ describe OutputResults do
37
37
  end
38
38
 
39
39
  it 'outputs files with errors as yaml' do
40
- PuppetCheck.settings[:output_format] = 'yaml'
41
40
  PuppetCheck.settings[:error_files] = ['foo: i had an error']
42
- expect { OutputResults.markup }.to output("---\nerrors:\n- 'foo: i had an error'\n").to_stdout
41
+ expect { OutputResults.markup(output_format: 'yaml') }.to output("---\nerrors:\n- 'foo: i had an error'\n").to_stdout
43
42
  end
44
43
  it 'outputs files with warnings as yaml' do
45
- PuppetCheck.settings[:output_format] = 'yaml'
46
44
  PuppetCheck.settings[:warning_files] = ['foo: i had a warning']
47
- expect { OutputResults.markup }.to output("---\nwarnings:\n- 'foo: i had a warning'\n").to_stdout
45
+ expect { OutputResults.markup(output_format: 'yaml') }.to output("---\nwarnings:\n- 'foo: i had a warning'\n").to_stdout
48
46
  end
49
47
  it 'outputs files with no errors or warnings as yaml' do
50
- PuppetCheck.settings[:output_format] = 'yaml'
51
48
  PuppetCheck.settings[: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
49
+ expect { OutputResults.markup(output_format: 'yaml') }.to output("---\nclean:\n- 'foo: i was totally good to go'\n").to_stdout
53
50
  end
54
51
  it 'outputs files that were not processed as yaml' do
55
- PuppetCheck.settings[:output_format] = 'yaml'
56
52
  PuppetCheck.settings[: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
53
+ expect { OutputResults.markup(output_format: 'yaml') }.to output("---\nignored:\n- 'foo: who knows what i am'\n").to_stdout
58
54
  end
59
55
  it 'outputs files with errors as json' do
60
- PuppetCheck.settings[:output_format] = 'json'
61
56
  PuppetCheck.settings[: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
57
+ expect { OutputResults.markup(output_format: 'json') }.to output("{\n \"errors\": [\n \"foo: i had an error\"\n ]\n}\n").to_stdout
63
58
  end
64
59
  it 'outputs files with warnings as json' do
65
- PuppetCheck.settings[:output_format] = 'json'
66
60
  PuppetCheck.settings[: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
61
+ expect { OutputResults.markup(output_format: 'json') }.to output("{\n \"warnings\": [\n \"foo: i had a warning\"\n ]\n}\n").to_stdout
68
62
  end
69
63
  it 'outputs files with no errors or warnings as json' do
70
- PuppetCheck.settings[:output_format] = 'json'
71
64
  PuppetCheck.settings[: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
65
+ expect { OutputResults.markup(output_format: 'json') }.to output("{\n \"clean\": [\n \"foo: i was totally good to go\"\n ]\n}\n").to_stdout
73
66
  end
74
67
  it 'outputs files that were not processed as json' do
75
- PuppetCheck.settings[:output_format] = 'json'
76
68
  PuppetCheck.settings[: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
69
+ expect { OutputResults.markup(output_format: 'json') }.to output("{\n \"ignored\": [\n \"foo: who knows what i am\"\n ]\n}\n").to_stdout
78
70
  end
79
71
  it 'raises an error for an unsupported output format' do
80
- PuppetCheck.settings[:output_format] = 'awesomesauce'
81
- expect { OutputResults.markup }.to raise_error(RuntimeError, 'puppet-check: Unsupported output format \'awesomesauce\' was specified.')
72
+ expect { OutputResults.markup(output_format: 'awesomesauce') }.to raise_error(RuntimeError, 'puppet-check: Unsupported output format \'awesomesauce\' was specified.')
82
73
  end
83
74
  end
84
75
  end
@@ -10,9 +10,11 @@ describe PuppetParser do
10
10
 
11
11
  context '.manifest' do
12
12
  it 'puts a bad syntax Puppet manifest in the error files array' do
13
- PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'], false, false, [])
14
- # dealing with annoying warning in puppet 5
15
- if RUBY_VERSION.to_f < 2.3
13
+ PuppetParser.manifest([fixtures_dir + 'manifests/syntax.pp'], false, [])
14
+ if Puppet::PUPPETVERSION.to_f >= 6.5
15
+ expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nLanguage validation logged 2 errors})
16
+ # dealing with annoying warning in puppet 5 and 6
17
+ elsif RUBY_VERSION.to_f < 2.3
16
18
  expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nSupport for ruby version.*\n.*\nThis Variable has no effect.*\nIllegal variable name})
17
19
  else
18
20
  expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/syntax.pp:\nThis Variable has no effect.*\nIllegal variable name})
@@ -21,37 +23,37 @@ describe PuppetParser do
21
23
  expect(PuppetCheck.settings[:clean_files]).to eql([])
22
24
  end
23
25
  it 'puts a bad syntax at eof Puppet manifest in the error files array' do
24
- PuppetParser.manifest([fixtures_dir + 'manifests/eof_syntax.pp'], false, false, [])
26
+ PuppetParser.manifest([fixtures_dir + 'manifests/eof_syntax.pp'], false, [])
25
27
  expect(PuppetCheck.settings[:error_files][0]).to match(%r{^#{fixtures_dir}manifests/eof_syntax.pp:\nSyntax error at end of input})
26
28
  expect(PuppetCheck.settings[:warning_files]).to eql([])
27
29
  expect(PuppetCheck.settings[:clean_files]).to eql([])
28
30
  end
29
31
  it 'puts a bad parser and lint style Puppet manifest in the warning files array' do
30
- PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'], false, true, [])
32
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_parser.pp'], true, [])
31
33
  expect(PuppetCheck.settings[:error_files]).to eql([])
32
34
  expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_parser.pp:\nUnrecognized escape sequence.*\nUnrecognized escape sequence.*\n.*double quoted string containing})
33
35
  expect(PuppetCheck.settings[:clean_files]).to eql([])
34
36
  end
35
37
  it 'puts a bad lint style Puppet manifest in the warning files array' do
36
- PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, [])
38
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], true, [])
37
39
  expect(PuppetCheck.settings[:error_files]).to eql([])
38
40
  expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}manifests/style_lint.pp:\n.*double quoted string containing.*\n.*indentation of})
39
41
  expect(PuppetCheck.settings[:clean_files]).to eql([])
40
42
  end
41
43
  it 'puts a bad style Puppet manifest in the clean files array when puppetlint_args ignores its warnings' do
42
- PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
44
+ PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], true, ['--no-double_quoted_strings-check', '--no-arrow_alignment-check'])
43
45
  expect(PuppetCheck.settings[:error_files]).to eql([])
44
46
  expect(PuppetCheck.settings[:warning_files]).to eql([])
45
47
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}manifests/style_lint.pp"])
46
48
  end
47
49
  it 'puts a good Puppet manifest in the clean files array' do
48
- PuppetParser.manifest([fixtures_dir + 'manifests/good.pp'], false, true, [])
50
+ PuppetParser.manifest([fixtures_dir + 'manifests/good.pp'], true, [])
49
51
  expect(PuppetCheck.settings[:error_files]).to eql([])
50
52
  expect(PuppetCheck.settings[:warning_files]).to eql([])
51
53
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}manifests/good.pp"])
52
54
  end
53
55
  it 'throws a well specified error for an invalid PuppetLint argument' do
54
- expect { PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], false, true, ['--non-existent', '--does-not-exist']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
56
+ expect { PuppetParser.manifest([fixtures_dir + 'manifests/style_lint.pp'], true, ['--non-existent', '--does-not-exist']) }.to raise_error(RuntimeError, 'puppet-lint: invalid option supplied among --non-existent --does-not-exist')
55
57
  end
56
58
  end
57
59
 
@@ -72,11 +72,11 @@ describe RubyParser do
72
72
  it 'puts a bad style librarian Puppet file in the warning files array' do
73
73
  RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'], true, [])
74
74
  expect(PuppetCheck.settings[:error_files]).to eql([])
75
- expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}librarian_style/Puppetfile:\n.*Align the parameters.*\n.*Use the new})
75
+ expect(PuppetCheck.settings[:warning_files][0]).to match(%r{^#{fixtures_dir}librarian_style/Puppetfile:\n.*Align the arguments.*\n.*Use the new})
76
76
  expect(PuppetCheck.settings[:clean_files]).to eql([])
77
77
  end
78
78
  it 'puts a bad style librarian Puppet file in the clean files array when rubocop_args ignores its warnings' do
79
- RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'], true, ['--except', 'Layout/AlignParameters,Style/HashSyntax'])
79
+ RubyParser.librarian([fixtures_dir + 'librarian_style/Puppetfile'], true, ['--except', 'Layout/AlignArguments,Style/HashSyntax'])
80
80
  expect(PuppetCheck.settings[:error_files]).to eql([])
81
81
  expect(PuppetCheck.settings[:warning_files]).to eql([])
82
82
  expect(PuppetCheck.settings[:clean_files]).to eql(["#{fixtures_dir}librarian_style/Puppetfile"])
@@ -4,16 +4,15 @@ require_relative '../lib/puppet-check'
4
4
  describe PuppetCheck do
5
5
  context 'self' do
6
6
  it 'settings can be altered' do
7
- PuppetCheck.settings[:future_parser] = true
8
- expect(PuppetCheck.settings[:future_parser]).to eql(true)
7
+ expect(PuppetCheck.settings[:future_parser]).to eql(nil)
9
8
  PuppetCheck.settings[:fail_on_warnings] = true
10
9
  expect(PuppetCheck.settings[:fail_on_warnings]).to eql(true)
11
- PuppetCheck.settings[:style_check] = true
12
- expect(PuppetCheck.settings[:style_check]).to eql(true)
13
- PuppetCheck.settings[:smoke_check] = true
14
- expect(PuppetCheck.settings[:smoke_check]).to eql(true)
15
- PuppetCheck.settings[:regression_check] = true
16
- expect(PuppetCheck.settings[:regression_check]).to eql(true)
10
+ PuppetCheck.settings[:style] = true
11
+ expect(PuppetCheck.settings[:style]).to eql(true)
12
+ PuppetCheck.settings[:smoke] = true
13
+ expect(PuppetCheck.settings[:smoke]).to eql(true)
14
+ PuppetCheck.settings[:regression] = true
15
+ expect(PuppetCheck.settings[:regression]).to eql(true)
17
16
  PuppetCheck.settings[:public] = 'public.pem'
18
17
  expect(PuppetCheck.settings[:public]).to eql('public.pem')
19
18
  PuppetCheck.settings[:private] = 'private.pem'
@@ -66,7 +65,7 @@ describe PuppetCheck do
66
65
 
67
66
  context '.execute_parsers' do
68
67
  it 'correctly organizes a set of files and invokes the correct parsers' do
69
- # parser_output = instance_double('execute_parsers', files: %w[puppet.pp puppet_template.epp ruby.rb ruby_template.erb yaml.yaml yaml.yml json.json Puppetfile Modulefile foobarbaz], future: false, style: false, pl_args: [], rc_args: [])
68
+ # parser_output = instance_double('execute_parsers', files: %w[puppet.pp puppet_template.epp ruby.rb ruby_template.erb yaml.yaml yaml.yml json.json Puppetfile Modulefile foobarbaz], style: false, pl_args: [], rc_args: [])
70
69
  # expect(parser_output).to receive(:manifest).with(%w[puppet.pp])
71
70
  # expect(parser_output).to receive(:template).with(%w[puppet_template.epp])
72
71
  # expect(parser_output).to receive(:ruby).with(%w[ruby.rb])
@@ -38,10 +38,10 @@ describe PuppetCheck do
38
38
  PuppetCheck.settings[:warning_files] = []
39
39
  PuppetCheck.settings[:clean_files] = []
40
40
  PuppetCheck.settings[:ignored_files] = []
41
- PuppetCheck.settings[:style_check] = true
41
+ PuppetCheck.settings[:style] = true
42
42
  # see regression_check_spec
43
43
  unless File.directory?('/home/travis')
44
- PuppetCheck.settings[:smoke_check] = true
44
+ PuppetCheck.settings[:smoke] = true
45
45
  PuppetCheck.settings[:octonodes] = %w[good.example.com]
46
46
  PuppetCheck.settings[:octoconfig] = 'spec/octocatalog-diff/octocatalog-diff.cfg.rb'
47
47
  end
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.6.1
4
+ version: 2.0.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: 2018-12-30 00:00:00.000000000 Z
11
+ date: 2019-09-27 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.7'
19
+ version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '7'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '3.7'
29
+ version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '7'
@@ -48,7 +48,7 @@ dependencies:
48
48
  name: reek
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ">"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '4.0'
54
54
  - - "<"
@@ -58,7 +58,7 @@ dependencies:
58
58
  prerelease: false
59
59
  version_requirements: !ruby/object:Gem::Requirement
60
60
  requirements:
61
- - - ">"
61
+ - - ">="
62
62
  - !ruby/object:Gem::Version
63
63
  version: '4.0'
64
64
  - - "<"
@@ -70,16 +70,16 @@ dependencies:
70
70
  requirements:
71
71
  - - "~>"
72
72
  - !ruby/object:Gem::Version
73
- version: '0.51'
73
+ version: '0.58'
74
74
  type: :runtime
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
78
  - - "~>"
79
79
  - !ruby/object:Gem::Version
80
- version: '0.51'
80
+ version: '0.58'
81
81
  - !ruby/object:Gem::Dependency
82
- name: spdx-licenses
82
+ name: rubocop-performance
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
85
  - - "~>"
@@ -110,22 +110,16 @@ dependencies:
110
110
  name: rake
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - ">="
114
- - !ruby/object:Gem::Version
115
- version: '9'
116
- - - "<"
113
+ - - "~>"
117
114
  - !ruby/object:Gem::Version
118
- version: '13'
115
+ version: '12.0'
119
116
  type: :development
120
117
  prerelease: false
121
118
  version_requirements: !ruby/object:Gem::Requirement
122
119
  requirements:
123
- - - ">="
124
- - !ruby/object:Gem::Version
125
- version: '9'
126
- - - "<"
120
+ - - "~>"
127
121
  - !ruby/object:Gem::Version
128
- version: '13'
122
+ version: '12.0'
129
123
  - !ruby/object:Gem::Dependency
130
124
  name: rspec
131
125
  requirement: !ruby/object:Gem::Requirement
@@ -229,7 +223,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
229
223
  requirements:
230
224
  - - ">="
231
225
  - !ruby/object:Gem::Version
232
- version: 2.1.0
226
+ version: 2.2.0
233
227
  required_rubygems_version: !ruby/object:Gem::Requirement
234
228
  requirements:
235
229
  - - ">="