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
|
end
|
||||||
|
|
||||||
def audit_conflicts
|
def audit_conflicts
|
||||||
|
tap = formula.tap
|
||||||
formula.conflicts.each do |c|
|
formula.conflicts.each do |c|
|
||||||
conflicting_formula = Formulary.factory(c.name)
|
conflicting_formula = Formulary.factory(c.name)
|
||||||
|
next if tap != conflicting_formula.tap
|
||||||
|
|
||||||
problem "Formula should not conflict with itself" if formula == conflicting_formula
|
problem "Formula should not conflict with itself" if formula == conflicting_formula
|
||||||
|
|
||||||
next unless @core_tap
|
if tap.formula_renames.key?(c.name) || tap.aliases.include?(c.name)
|
||||||
|
|
||||||
if CoreTap.instance.formula_renames.key?(c.name) || Formula.aliases.include?(c.name)
|
|
||||||
problem "Formula conflict should be declared using " \
|
problem "Formula conflict should be declared using " \
|
||||||
"canonical name (#{conflicting_formula.name}) instead of #{c.name}"
|
"canonical name (#{conflicting_formula.name}) instead of #{c.name}"
|
||||||
end
|
end
|
||||||
@ -328,7 +329,7 @@ module Homebrew
|
|||||||
rev_conflict_found = false
|
rev_conflict_found = false
|
||||||
conflicting_formula.conflicts.each do |rc|
|
conflicting_formula.conflicts.each do |rc|
|
||||||
rc_formula = Formulary.factory(rc.name)
|
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 " \
|
problem "Formula #{conflicting_formula.name} conflict should be declared using " \
|
||||||
"canonical name (#{rc_formula.name}) instead of #{rc.name}"
|
"canonical name (#{rc_formula.name}) instead of #{rc.name}"
|
||||||
end
|
end
|
||||||
|
@ -58,13 +58,20 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe FormulaAuditor do
|
describe FormulaAuditor do
|
||||||
def formula_auditor(name, text, options = {})
|
def formula_auditor(name_or_formula, text = nil, options = {})
|
||||||
path = Pathname.new "#{dir}/#{name}.rb"
|
formula = case name_or_formula
|
||||||
|
when String
|
||||||
|
path = Pathname.new "#{dir}/#{name_or_formula}.rb"
|
||||||
path.open("w") do |f|
|
path.open("w") do |f|
|
||||||
f.write text
|
f.write text
|
||||||
end
|
end
|
||||||
|
|
||||||
described_class.new(Formulary.factory(path), options)
|
Formulary.factory(path)
|
||||||
|
when Formula
|
||||||
|
name_or_formula
|
||||||
|
end
|
||||||
|
|
||||||
|
described_class.new(formula, options)
|
||||||
end
|
end
|
||||||
|
|
||||||
let(:dir) { mktmpdir }
|
let(:dir) { mktmpdir }
|
||||||
@ -1141,15 +1148,18 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "#audit_conflicts" do
|
describe "#audit_conflicts" do
|
||||||
|
before do
|
||||||
|
allow(File).to receive(:open).and_return("")
|
||||||
|
end
|
||||||
|
|
||||||
specify "it warns when conflicting with non-existing formula" do
|
specify "it warns when conflicting with non-existing formula" do
|
||||||
fa = formula_auditor "foo", <<~RUBY, core_tap: true
|
foo = formula("foo") do
|
||||||
class Foo < Formula
|
url "https://brew.sh/bar-1.0.tgz"
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
|
||||||
|
|
||||||
conflicts_with "bar"
|
conflicts_with "bar"
|
||||||
end
|
end
|
||||||
RUBY
|
|
||||||
|
|
||||||
|
fa = formula_auditor foo
|
||||||
fa.audit_conflicts
|
fa.audit_conflicts
|
||||||
|
|
||||||
expect(fa.problems.first[:message])
|
expect(fa.problems.first[:message])
|
||||||
@ -1157,14 +1167,14 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
specify "it warns when conflicting with itself" do
|
specify "it warns when conflicting with itself" do
|
||||||
fa = formula_auditor "foo", <<~RUBY, core_tap: true
|
foo = formula("foo") do
|
||||||
class Foo < Formula
|
url "https://brew.sh/bar-1.0.tgz"
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
|
||||||
|
|
||||||
conflicts_with "#{dir}/foo.rb"
|
conflicts_with "foo"
|
||||||
end
|
end
|
||||||
RUBY
|
stub_formula_loader foo
|
||||||
|
|
||||||
|
fa = formula_auditor foo
|
||||||
fa.audit_conflicts
|
fa.audit_conflicts
|
||||||
|
|
||||||
expect(fa.problems.first[:message])
|
expect(fa.problems.first[:message])
|
||||||
@ -1172,24 +1182,22 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
specify "it warns when another formula does not have a symmetric conflict" do
|
specify "it warns when another formula does not have a symmetric conflict" do
|
||||||
formula_auditor "bar", <<~RUBY, core_tap: true
|
foo = formula("foo") do
|
||||||
class Bar < Formula
|
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
end
|
end
|
||||||
RUBY
|
stub_formula_loader foo
|
||||||
|
|
||||||
fa = formula_auditor "foo", <<~RUBY, core_tap: true
|
bar = formula("bar") do
|
||||||
class Foo < Formula
|
url "https://brew.sh/bar-1.0.tgz"
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
|
||||||
|
|
||||||
conflicts_with "#{dir}/bar.rb"
|
conflicts_with "foo"
|
||||||
end
|
end
|
||||||
RUBY
|
|
||||||
|
|
||||||
|
fa = formula_auditor bar
|
||||||
fa.audit_conflicts
|
fa.audit_conflicts
|
||||||
|
|
||||||
expect(fa.problems.first[:message])
|
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
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user