From 43d67816ea48ac9ef1356015bef2d515b1de7b0f Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Fri, 18 Jun 2021 16:40:12 +0100 Subject: [PATCH] audit_conflicts: enable for third-party taps --- Library/Homebrew/formula_auditor.rb | 9 +-- Library/Homebrew/test/dev-cmd/audit_spec.rb | 66 ++++++++++++--------- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 55c6d0976f..1bb9c55339 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -314,13 +314,14 @@ module Homebrew end def audit_conflicts + tap = formula.tap formula.conflicts.each do |c| conflicting_formula = Formulary.factory(c.name) + next if tap != conflicting_formula.tap + problem "Formula should not conflict with itself" if formula == conflicting_formula - next unless @core_tap - - if CoreTap.instance.formula_renames.key?(c.name) || Formula.aliases.include?(c.name) + if tap.formula_renames.key?(c.name) || tap.aliases.include?(c.name) problem "Formula conflict should be declared using " \ "canonical name (#{conflicting_formula.name}) instead of #{c.name}" end @@ -328,7 +329,7 @@ module Homebrew rev_conflict_found = false conflicting_formula.conflicts.each do |rc| rc_formula = Formulary.factory(rc.name) - if CoreTap.instance.formula_renames.key?(rc.name) || Formula.aliases.include?(rc.name) + if tap.formula_renames.key?(rc.name) || tap.aliases.include?(rc.name) problem "Formula #{conflicting_formula.name} conflict should be declared using " \ "canonical name (#{rc_formula.name}) instead of #{rc.name}" end diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index d9040f4055..cd33d61b27 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -58,13 +58,20 @@ module Homebrew end describe FormulaAuditor do - def formula_auditor(name, text, options = {}) - path = Pathname.new "#{dir}/#{name}.rb" - path.open("w") do |f| - f.write text + def formula_auditor(name_or_formula, text = nil, options = {}) + formula = case name_or_formula + when String + path = Pathname.new "#{dir}/#{name_or_formula}.rb" + path.open("w") do |f| + f.write text + end + + Formulary.factory(path) + when Formula + name_or_formula end - described_class.new(Formulary.factory(path), options) + described_class.new(formula, options) end let(:dir) { mktmpdir } @@ -1141,15 +1148,18 @@ module Homebrew end describe "#audit_conflicts" do + before do + allow(File).to receive(:open).and_return("") + end + specify "it warns when conflicting with non-existing formula" do - fa = formula_auditor "foo", <<~RUBY, core_tap: true - class Foo < Formula - url "https://brew.sh/foo-1.0.tgz" + foo = formula("foo") do + url "https://brew.sh/bar-1.0.tgz" - conflicts_with "bar" - end - RUBY + conflicts_with "bar" + end + fa = formula_auditor foo fa.audit_conflicts expect(fa.problems.first[:message]) @@ -1157,14 +1167,14 @@ module Homebrew end specify "it warns when conflicting with itself" do - fa = formula_auditor "foo", <<~RUBY, core_tap: true - class Foo < Formula - url "https://brew.sh/foo-1.0.tgz" + foo = formula("foo") do + url "https://brew.sh/bar-1.0.tgz" - conflicts_with "#{dir}/foo.rb" - end - RUBY + conflicts_with "foo" + end + stub_formula_loader foo + fa = formula_auditor foo fa.audit_conflicts expect(fa.problems.first[:message]) @@ -1172,24 +1182,22 @@ module Homebrew end specify "it warns when another formula does not have a symmetric conflict" do - formula_auditor "bar", <<~RUBY, core_tap: true - class Bar < Formula - url "https://brew.sh/foo-1.0.tgz" - end - RUBY + foo = formula("foo") do + url "https://brew.sh/foo-1.0.tgz" + end + stub_formula_loader foo - fa = formula_auditor "foo", <<~RUBY, core_tap: true - class Foo < Formula - url "https://brew.sh/foo-1.0.tgz" + bar = formula("bar") do + url "https://brew.sh/bar-1.0.tgz" - conflicts_with "#{dir}/bar.rb" - end - RUBY + conflicts_with "foo" + end + fa = formula_auditor bar fa.audit_conflicts expect(fa.problems.first[:message]) - .to match("Formula bar should also have a conflict declared with foo") + .to match("Formula foo should also have a conflict declared with bar") end end end