From e0bb978cc93ab81ffeaa15656fe74384cf7982fc Mon Sep 17 00:00:00 2001 From: Claudia Date: Mon, 9 Oct 2017 02:32:44 +0200 Subject: 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 --- Library/Homebrew/test/dev-cmd/audit_spec.rb | 68 +++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) (limited to 'Library') diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index 3e99bd06b..cea8daf6b 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -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 -- cgit v1.2.3