Fix legacy reporter output to file (#2667)

* Fix legacy reporter output.

Signed-off-by: Jared Quick <jquick@chef.io>

* Wrap test in a proc to catch warnings.

Signed-off-by: Jared Quick <jquick@chef.io>

* Add output deprecation.

Signed-off-by: Jared Quick <jquick@chef.io>
This commit is contained in:
Jared Quick 2018-02-18 06:17:00 -05:00 committed by Christoph Hartmann
parent db78ab4858
commit 97dd0546c0
3 changed files with 21 additions and 8 deletions

View file

@ -91,11 +91,19 @@ module Inspec
}
end
def self.parse_reporters(opts) # rubocop:disable Metrics/AbcSize
def self.parse_reporters(opts) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
# merge in any legacy formats as reporter
# this method will only be used for ad-hoc runners
if !opts['format'].nil? && opts['reporter'].nil?
warn '[DEPRECATED] The option --format is being is being deprecated and will be removed in inspec 3.0. Please use --reporter'
# see if we are using the legacy output to write to files
if opts['output']
warn '[DEPRECATED] The option \'output\' is being is being deprecated and will be removed in inspec 3.0. Please use --reporter name:path'
opts['format'] = "#{opts['format']}:#{opts['output']}"
opts.delete('output')
end
opts['reporter'] = Array(opts['format'])
opts.delete('format')
end

View file

@ -137,12 +137,7 @@ module Inspec
#
# @return [nil]
def configure_output
if !@conf['output'] || @conf['output'] == '-'
RSpec.configuration.output_stream = $stdout
else
RSpec.configuration.output_stream = @conf['output']
end
RSpec.configuration.output_stream = $stdout
@formatter = RSpec.configuration.add_formatter(Inspec::Formatters::Base)
RSpec.configuration.add_formatter(Inspec::Formatters::ShowProgress, $stderr) if @conf[:show_progress]
set_optional_formatters

View file

@ -119,7 +119,17 @@ describe 'BaseCLI' do
assert = { 'reporter' => { 'json' => { 'stdout' => true }}}
parsed.must_equal assert
end
end
it 'parse cli reporters with format and output' do
error = "[DEPRECATED] The option --format is being is being deprecated and will be removed in inspec 3.0. Please use --reporter\n"
error += "[DEPRECATED] The option 'output' is being is being deprecated and will be removed in inspec 3.0. Please use --reporter name:path\n"
proc {
opts = { 'format' => 'json', 'output' => '/tmp/inspec_out.json' }
parsed = Inspec::BaseCLI.parse_reporters(opts)
assert = { 'reporter' => { 'json' => { 'file' => '/tmp/inspec_out.json', 'stdout' => false }}}
parsed.must_equal assert
}.must_output nil, error end
end
describe 'validate_reporters' do
it 'valid reporter' do