From 5d27b707579417860b295361351974e9aebbf105 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 1 Oct 2022 17:28:07 -0700 Subject: [PATCH] Set --formula by default on linux --- Library/Homebrew/cli/args.rb | 1 + Library/Homebrew/test/cli/named_args_spec.rb | 22 +++++++++++++++----- Library/Homebrew/test/cmd/--cache_spec.rb | 2 +- Library/Homebrew/test/cmd/home_spec.rb | 2 +- Library/Homebrew/test/spec_helper.rb | 4 ++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cli/args.rb b/Library/Homebrew/cli/args.rb index 49a9940541..bb219dd9dd 100644 --- a/Library/Homebrew/cli/args.rb +++ b/Library/Homebrew/cli/args.rb @@ -96,6 +96,7 @@ module Homebrew end def only_formula_or_cask + return :formula if OS.linux? && !Homebrew::EnvConfig.developer? return :formula if formula? && !cask? return :cask if cask? && !formula? end diff --git a/Library/Homebrew/test/cli/named_args_spec.rb b/Library/Homebrew/test/cli/named_args_spec.rb index 06e85a7344..826eab0021 100644 --- a/Library/Homebrew/test/cli/named_args_spec.rb +++ b/Library/Homebrew/test/cli/named_args_spec.rb @@ -118,6 +118,12 @@ describe Homebrew::CLI::NamedArgs do expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaOrCaskUnavailableError) end + it "raises an error when formula is absent and cask is available on linux", :needs_linux do + stub_cask_loader foo_cask + + expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaOrCaskUnavailableError) + end + it "returns formula when formula is present and cask is unreadable" do stub_formula_loader foo setup_unredable_cask "foo" @@ -126,7 +132,7 @@ describe Homebrew::CLI::NamedArgs do expect { described_class.new("foo").to_formulae_and_casks }.to output(/Failed to load cask: foo/).to_stderr end - it "returns cask when formula is unreadable and cask is present" do + it "returns cask when formula is unreadable and cask is present", :dev_on_linux do setup_unredable_formula "foo" stub_cask_loader foo_cask @@ -156,7 +162,7 @@ describe Homebrew::CLI::NamedArgs do end describe "#to_resolved_formulae_to_casks" do - it "returns resolved formulae, as well as casks" do + it "returns resolved formulae, as well as casks", :dev_on_linux do allow(Formulary).to receive(:resolve).and_call_original allow(Formulary).to receive(:resolve).with("foo", any_args).and_return foo stub_cask_loader baz, call_original: true @@ -245,7 +251,7 @@ describe Homebrew::CLI::NamedArgs do (HOMEBREW_CELLAR/"foo/1.0").mkpath end - it "returns kegs, as well as casks" do + it "returns kegs, as well as casks", :dev_on_linux do stub_cask_loader baz, call_original: true kegs, casks = described_class.new("foo", "baz").to_kegs_to_casks @@ -279,7 +285,7 @@ describe Homebrew::CLI::NamedArgs do allow(Cask::CaskLoader).to receive(:path).and_call_original end - it "returns taps, cask formula and existing paths" do + it "returns taps, cask formula and existing paths", :dev_on_linux do expect(Formulary).to receive(:path).with("foo").and_return(formula_path) expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path) @@ -287,7 +293,7 @@ describe Homebrew::CLI::NamedArgs do .to eq [Tap.fetch("homebrew/core").path, formula_path, cask_path, existing_path] end - it "returns both cask and formula paths if they exist" do + it "returns both cask and formula paths if they exist", :dev_on_linux do expect(Formulary).to receive(:path).with("foo").and_return(formula_path) expect(Cask::CaskLoader).to receive(:path).with("baz").and_return(cask_path) @@ -305,6 +311,12 @@ describe Homebrew::CLI::NamedArgs do expect(described_class.new("foo", "baz").to_paths(only: :cask)).to eq [cask_path, Cask::CaskLoader.path("baz")] end + + it "returns only formulae by default on linux", :needs_linux do + expect(Formulary).to receive(:path).with("foo").and_return(formula_path) + + expect(described_class.new("foo", "baz").to_paths).to eq [formula_path, Formulary.path("baz")] + end end describe "#to_taps" do diff --git a/Library/Homebrew/test/cmd/--cache_spec.rb b/Library/Homebrew/test/cmd/--cache_spec.rb index fbca7fddf9..8d9320dacd 100644 --- a/Library/Homebrew/test/cmd/--cache_spec.rb +++ b/Library/Homebrew/test/cmd/--cache_spec.rb @@ -28,7 +28,7 @@ describe "brew --cache" do .and be_a_success end - it "prints the cache files for a given Formula and Cask", :integration_test do + it "prints the cache files for a given Formula and Cask", :integration_test, :dev_on_linux do expect { brew "--cache", testball, cask_path("local-caffeine") } .to output( %r{ diff --git a/Library/Homebrew/test/cmd/home_spec.rb b/Library/Homebrew/test/cmd/home_spec.rb index d5908b20b5..c0cef3f443 100644 --- a/Library/Homebrew/test/cmd/home_spec.rb +++ b/Library/Homebrew/test/cmd/home_spec.rb @@ -45,7 +45,7 @@ describe "brew home" do .and be_a_success end - it "opens the homepages for a given formula and Cask", :integration_test do + it "opens the homepages for a given formula and Cask", :integration_test, :dev_on_linux do setup_test_formula "testballhome" expect { brew "home", "testballhome", local_caffeine_path, "HOMEBREW_BROWSER" => "echo" } diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 2aef66d976..e307836baa 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -180,6 +180,10 @@ RSpec.configure do |config| skip "Unzip is not installed." unless which("unzip") end + config.before(:each, :dev_on_linux) do + Allow(Homebrew::EnvConfig).to receive(:developer?).and_return(true) if OS.linux? + end + config.around do |example| def find_files return [] unless File.exist?(TEST_TMPDIR)