Add tests for FormulaAuditor#audit_deps

These tests cover a few aspects of the `FormulaAuditor#audit_deps`
method. The main focus is the part where FormulaAuditor checks for
dependencies on formulas which are tagged `keg_only` with the
`:provided_by_macos` reason.

For this particular kind of `keg_only` formulas, we expect
`brew audit --new-formula` to fail with a problem message like:

> Dependency 'bc' may be unnecessary as it is provided by
> macOS; try to build this formula without it.

For more details, see the relevant discussion:

[1] https://github.com/Homebrew/homebrew-core/pull/14067#issuecomment-335046151

[2] https://github.com/Homebrew/brew/pull/3290#issuecomment-335052140
This commit is contained in:
Claudia 2017-10-09 02:32:44 +02:00
parent a2374cba6c
commit e0bb978cc9

View File

@ -217,6 +217,74 @@ describe FormulaAuditor do
end
end
describe "#audit_deps" do
describe "a dependency on a macOS-provided keg-only formula" do
describe "which is whitelisted" do
let(:fa) do
formula_auditor "foo", <<-EOS.undent, new_formula: true
class Foo < Formula
url "http://example.com/foo-1.0.tgz"
homepage "http://example.com"
depends_on "openssl"
end
EOS
end
let(:f_openssl) do
formula do
url "http://example.com/openssl-1.0.tgz"
homepage "http://example.com"
keg_only :provided_by_macos
end
end
before do
allow(fa.formula.deps.first)
.to receive(:to_formula).and_return(f_openssl)
fa.audit_deps
end
subject { fa }
its(:problems) { are_expected.to be_empty }
end
describe "which is not whitelisted" do
let(:fa) do
formula_auditor "foo", <<-EOS.undent, new_formula: true
class Foo < Formula
url "http://example.com/foo-1.0.tgz"
homepage "http://example.com"
depends_on "bc"
end
EOS
end
let(:f_bc) do
formula do
url "http://example.com/bc-1.0.tgz"
homepage "http://example.com"
keg_only :provided_by_macos
end
end
before do
allow(fa.formula.deps.first)
.to receive(:to_formula).and_return(f_bc)
fa.audit_deps
end
subject { fa }
its(:problems) { are_expected.to match([/unnecessary/]) }
end
end
end
describe "#audit_keg_only_style" do
specify "keg_only_needs_downcasing" do
fa = formula_auditor "foo", <<-EOS.undent, strict: true