audit: fix --display-failures-only failure messaging

This commit is contained in:
Rylan Polster 2021-03-21 17:11:17 -04:00
parent 83ebc5ef7e
commit b4a36bef64
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
2 changed files with 15 additions and 7 deletions

View File

@ -126,9 +126,10 @@ module Cask
end
end
sig { params(include_passed: T::Boolean).returns(String) }
def summary(include_passed: false)
sig { params(include_passed: T::Boolean, include_warnings: T::Boolean).returns(String) }
def summary(include_passed: false, include_warnings: true)
return if success? && !include_passed
return if warnings? && !errors? && !include_warnings
summary = ["audit for #{cask}: #{result}"]
@ -136,8 +137,10 @@ module Cask
summary << " #{Formatter.error("-")} #{error}"
end
warnings.each do |warning|
summary << " #{Formatter.warning("-")} #{warning}"
if include_warnings
warnings.each do |warning|
summary << " #{Formatter.warning("-")} #{warning}"
end
end
summary.join("\n")

View File

@ -75,7 +75,7 @@ module Cask
if !language && language_blocks
language_blocks.each_key do |l|
audit = audit_languages(l)
summary = audit.summary(include_passed: output_passed?)
summary = audit.summary(include_passed: output_passed?, include_warnings: output_warnings?)
if summary.present? && output_summary?(audit)
ohai "Auditing language: #{l.map { |lang| "'#{lang}'" }.to_sentence}" if output_summary?
puts summary
@ -85,7 +85,7 @@ module Cask
end
else
audit = audit_cask_instance(cask)
summary = audit.summary(include_passed: output_passed?)
summary = audit.summary(include_passed: output_passed?, include_warnings: output_warnings?)
puts summary if summary.present? && output_summary?(audit)
warnings += audit.warnings
errors += audit.errors
@ -97,7 +97,6 @@ module Cask
private
def output_summary?(audit = nil)
return false if @display_failures_only.present?
return true if @any_named_args.present?
return true if @audit_strict.present?
return false if audit.blank?
@ -112,6 +111,12 @@ module Cask
false
end
def output_warnings?
return false if @display_failures_only.present?
true
end
def audit_languages(languages)
original_config = cask.config
localized_config = original_config.merge(Config.new(explicit: { languages: languages }))