brew/Library/Homebrew/test/cmd/tab_spec.rb
Ruoyu Zhong 9cd5078efb
cmd/tab: new command
Add `brew tab`, a new command to edit tab information, as previously
discussed in https://github.com/Homebrew/brew/pull/17125#issuecomment-2068473483.
Currently, this supports marking or unmarking formulae as installed on
request.

Sample usage:

    $ brew tab --installed-on-request curl
    ==> curl is now marked as installed on request.
    $ brew autoremove --dry-run
    [no output]
    $ brew tab --no-installed-on-request curl
    ==> curl is now marked as not installed on request.
    $ brew autoremove --dry-run
    ==> Would autoremove 2 unneeded formulae:
    curl
    rtmpdump

Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2024-06-13 11:44:14 +08:00

34 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require "cmd/tab"
require "cmd/shared_examples/args_parse"
require "tab"
RSpec.describe Homebrew::Cmd::TabCmd do
def installed_on_request?(formula)
# `brew` subprocesses can change the tab, invalidating the cached values.
Tab.clear_cache
Tab.for_formula(formula).installed_on_request
end
it_behaves_like "parseable arguments"
it "marks or unmarks a formula as installed on request", :integration_test do
setup_test_formula "foo",
tab_attributes: { "installed_on_request" => false }
foo = Formula["foo"]
expect { brew "tab", "--installed-on-request", "foo" }
.to be_a_success
.and output(/foo is now marked as installed on request/).to_stdout
.and not_to_output.to_stderr
expect(installed_on_request?(foo)).to be true
expect { brew "tab", "--no-installed-on-request", "foo" }
.to be_a_success
.and output(/foo is now marked as not installed on request/).to_stdout
.and not_to_output.to_stderr
expect(installed_on_request?(foo)).to be false
end
end