Minor cleanups for readability.

Signed-off-by: Ryan Davis <zenspider@chef.io>
This commit is contained in:
Ryan Davis 2019-09-30 16:05:42 -07:00
parent 07dc5e3192
commit fd7a569d6b
3 changed files with 15 additions and 3 deletions

View file

@ -222,16 +222,20 @@ module Inspec
private
ALL_OF_OUR_REPORTERS = %w{json json-min json-rspec json-automate junit html yaml documentation progress}.freeze # BUT WHY?!?!
def suppress_log_output?(opts)
return false if opts["reporter"].nil?
match = %w{json json-min json-rspec json-automate junit html yaml documentation progress} & opts["reporter"].keys
match = ALL_OF_OUR_REPORTERS & opts["reporter"].keys
unless match.empty?
match.each do |m|
# check to see if we are outputting to stdout
return true if opts["reporter"][m]["stdout"] == true
end
end
false
end

View file

@ -340,7 +340,15 @@ class Inspec::InspecCLI < Inspec::BaseCLI
ui.exit res unless run_type == :ruby_eval
# No InSpec tests - just print evaluation output.
res = (res.respond_to?(:to_json) ? res.to_json : JSON.dump(res)) if o["reporter"]&.keys&.include?("json")
reporters = o["reporter"] || {}
if reporters.keys.include?("json")
res = if res.respond_to?(:to_json)
res.to_json
else
JSON.dump(res)
end
end
puts res
ui.exit Inspec::UI::EXIT_NORMAL
rescue RuntimeError, Train::UserError => e

View file

@ -83,7 +83,7 @@ module Inspec
return @rspec_exit_code if @formatter.results.empty?
stats = @formatter.results[:statistics][:controls]
skipped = @formatter.results&.fetch(:profiles, nil)&.first&.fetch(:status, nil) == "skipped"
skipped = @formatter.results.dig(:profiles, 0, :status) == "skipped"
if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0 && !skipped
0
elsif stats[:failed][:total] > 0