From 5c41e85ae9335610cbbf47f1c23b3a20f00f06c8 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sun, 27 Aug 2023 17:03:02 -0700 Subject: [PATCH] update cmd/uses and cmd/deps tests These tests were very simple before and now this should result in more code coverage without affecting test performance. The only tricky thing was testing the `--missing` option without actually installing a package using `install_test_formula` because that is very slow (around 10 seconds on my machine). I ended up just writing the tab to a plausible keg directory for each package I wanted to "install". This allows us to test the behavior while also not increasing CI time by ~20 seconds (though it'd probably be faster on CI than my local machine). --- Library/Homebrew/test/cmd/deps_spec.rb | 24 +++++++++++-- Library/Homebrew/test/cmd/uses_spec.rb | 34 +++++++++++++++---- .../spec/shared_context/integration_test.rb | 8 ++--- 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/Library/Homebrew/test/cmd/deps_spec.rb b/Library/Homebrew/test/cmd/deps_spec.rb index 308e9d88f111b..4676d06587555 100644 --- a/Library/Homebrew/test/cmd/deps_spec.rb +++ b/Library/Homebrew/test/cmd/deps_spec.rb @@ -6,16 +6,34 @@ it_behaves_like "parseable arguments" it "outputs all of a Formula's dependencies and their dependencies on separate lines", :integration_test do - setup_test_formula "foo" + # Included in output setup_test_formula "bar" + setup_test_formula "foo" + setup_test_formula "test" + + # Excluded from output setup_test_formula "baz", <<~RUBY url "https://brew.sh/baz-1.0" depends_on "bar" + depends_on "build" => :build + depends_on "test" => :test + depends_on "optional" => :optional + depends_on "recommended_test" => [:recommended, :test] + depends_on "installed" RUBY + setup_test_formula "build" + setup_test_formula "optional" + setup_test_formula "recommended_test" + setup_test_formula "installed" + + # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory + keg_dir = HOMEBREW_CELLAR/"installed"/"1.0" + keg_dir.mkpath + touch keg_dir/Tab::FILENAME - expect { brew "deps", "baz" } + expect { brew "deps", "baz", "--include-test", "--missing", "--skip-recommended" } .to be_a_success - .and output("bar\nfoo\n").to_stdout + .and output("bar\nfoo\ntest\n").to_stdout .and not_to_output.to_stderr end end diff --git a/Library/Homebrew/test/cmd/uses_spec.rb b/Library/Homebrew/test/cmd/uses_spec.rb index 10977ba1138d0..eef1cc603a459 100644 --- a/Library/Homebrew/test/cmd/uses_spec.rb +++ b/Library/Homebrew/test/cmd/uses_spec.rb @@ -6,15 +6,37 @@ it_behaves_like "parseable arguments" it "prints the Formulae a given Formula is used by", :integration_test do - setup_test_formula "foo" + # Included in output setup_test_formula "bar" - setup_test_formula "baz", <<~RUBY - url "https://brew.sh/baz-1.0" - depends_on "bar" + setup_test_formula "optional", <<~RUBY + url "https://brew.sh/optional-1.0" + depends_on "bar" => :optional + RUBY + + # Excluded from output + setup_test_formula "foo" + setup_test_formula "test", <<~RUBY + url "https://brew.sh/test-1.0" + depends_on "foo" => :test RUBY + setup_test_formula "build", <<~RUBY + url "https://brew.sh/build-1.0" + depends_on "foo" => :build + RUBY + setup_test_formula "installed", <<~RUBY + url "https://brew.sh/installed-1.0" + depends_on "foo" + RUBY + + # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory + %w[foo installed].each do |formula_name| + keg_dir = HOMEBREW_CELLAR/formula_name/"1.0" + keg_dir.mkpath + touch keg_dir/Tab::FILENAME + end - expect { brew "uses", "--eval-all", "--recursive", "foo" } - .to output(/(bar\nbaz|baz\nbar)/).to_stdout + expect { brew "uses", "foo", "--eval-all", "--include-optional", "--missing", "--recursive" } + .to output(/^(bar\noptional|optional\nbar)$/).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 1ae7e966bd5af..bf488562d76b1 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -166,10 +166,6 @@ def install # something here RUBY - when "foo", "gnupg" - content = <<~RUBY - url "https://brew.sh/#{name}-1.0" - RUBY when "bar" content = <<~RUBY url "https://brew.sh/#{name}-1.0" @@ -180,6 +176,10 @@ def install url "https://brew.sh/#patchelf-1.0" license "0BSD" RUBY + else + content ||= <<~RUBY + url "https://brew.sh/#{name}-1.0" + RUBY end Formulary.core_path(name).tap do |formula_path|