mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
audit_conflicts: enable for third-party taps
This commit is contained in:
parent
1ddb6ef584
commit
43d67816ea
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user