Skip to content

Commit

Permalink
audit: fix --display-failures-only failure messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylan12 committed Mar 23, 2021
1 parent 83ebc5e commit b4a36be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
11 changes: 7 additions & 4 deletions Library/Homebrew/cask/audit.rb
Expand Up @@ -126,18 +126,21 @@ def result
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}"]

errors.each do |error|
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")
Expand Down
11 changes: 8 additions & 3 deletions Library/Homebrew/cask/auditor.rb
Expand Up @@ -75,7 +75,7 @@ def audit
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
Expand All @@ -85,7 +85,7 @@ def audit
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
Expand All @@ -97,7 +97,6 @@ def audit
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?
Expand All @@ -112,6 +111,12 @@ def output_passed?
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 }))
Expand Down

0 comments on commit b4a36be

Please sign in to comment.