<commit_before># frozen_string_literal: true

require "cmd/uninstall"

require "cmd/shared_examples/args_parse"

describe "Homebrew.uninstall_args" do
  it_behaves_like "parseable arguments"
end

describe "brew uninstall", :integration_test do
  it "uninstalls a given Formula" do
    install_test_formula "testball"

    expect { brew "uninstall", "--force", "testball" }
      .to output(/Uninstalling testball/).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success
  end

  it "uninstalls a given Cask" do
    caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
    Cask::Installer.new(caffeine).install

    expect { brew "uninstall", "local-caffeine" }
      .to output(/Uninstalling Cask local-caffeine/).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect(caffeine).not_to be_installed

    # expect TEST_TMPDIR/cask-appdir to exist and be empty, then delete it
    expect(
      Find.find(TEST_TMPDIR)
        .reject { |f| File.basename(f) == ".DS_Store" }
        .filter { |f| File.path(f).start_with?("#{TEST_TMPDIR}/cask-appdir") },
    ).to eq(["#{TEST_TMPDIR}/cask-appdir"])

    rm_r "#{TEST_TMPDIR}/cask-appdir"
  end

  it "uninstalls given Formulae and Casks" do
    install_test_formula "testball"

    caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
    Cask::Installer.new(caffeine).install

    expect { brew "uninstall", "testball", "local-caffeine" }
      .to output(%r{
        Uninstalling\s#{TEST_TMPDIR}/cellar/testball/.*\n
        ==>\sUninstalling\sCask\slocal-caffeine
      }x).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect(caffeine).not_to be_installed

    # expect TEST_TMPDIR/cask-appdir to exist and be empty, then delete it
    expect(
      Find.find(TEST_TMPDIR)
        .reject { |f| File.basename(f) == ".DS_Store" }
        .filter { |f| File.path(f).start_with?("#{TEST_TMPDIR}/cask-appdir") },
    ).to eq(["#{TEST_TMPDIR}/cask-appdir"])

    rm_r "#{TEST_TMPDIR}/cask-appdir"
  end
end

describe Homebrew do
  let(:dependency) { formula("dependency") { url "f-1" } }
  let(:dependent) do
    formula("dependent") do
      url "f-1"
      depends_on "dependency"
    end
  end

  let(:opts) { { dependency.rack => [Keg.new(dependency.installed_prefix)] } }

  before do
    [dependency, dependent].each do |f|
      f.installed_prefix.mkpath
      Keg.new(f.installed_prefix).optlink
    end

    tab = Tab.empty
    tab.homebrew_version = "1.1.6"
    tab.tabfile = dependent.installed_prefix/Tab::FILENAME<commit_msg>uninstall: Clean up cask-appdir after tests<commit_after># frozen_string_literal: true

require "cmd/uninstall"

require "cmd/shared_examples/args_parse"

describe "Homebrew.uninstall_args" do
  it_behaves_like "parseable arguments"
end

describe "brew uninstall", :integration_test do
  it "uninstalls a given Formula" do
    install_test_formula "testball"

    expect { brew "uninstall", "--force", "testball" }
      .to output(/Uninstalling testball/).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success
  end

  it "uninstalls a given Cask" do
    caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
    Cask::Installer.new(caffeine).install

    expect { brew "uninstall", "local-caffeine" }
      .to output(/Uninstalling Cask local-caffeine/).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect(caffeine).not_to be_installed

    rm_r(TEST_TMPDIR + "/cask-appdir")
  end

  it "uninstalls given Formulae and Casks" do
    install_test_formula "testball"

    caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
    Cask::Installer.new(caffeine).install

    expect { brew "uninstall", "testball", "local-caffeine" }
      .to output(%r{
        Uninstalling\s#{TEST_TMPDIR}/cellar/testball/.*\n
        ==>\sUninstalling\sCask\slocal-caffeine
      }x).to_stdout
      .and not_to_output.to_stderr
      .and be_a_success

    expect(caffeine).not_to be_installed

    rm_r(TEST_TMPDIR + "/cask-appdir")
  end
end

describe Homebrew do
  let(:dependency) { formula("dependency") { url "f-1" } }
  let(:dependent) do
    formula("dependent") do
      url "f-1"
      depends_on "dependency"
    end
  end

  let(:opts) { { dependency.rack => [Keg.new(dependency.installed_prefix)] } }

  before do
    [dependency, dependent].each do |f|
      f.installed_prefix.mkpath
      Keg.new(f.installed_prefix).optlink
    end

    tab = Tab.empty
    tab.homebrew_version = "1.1.6"
    tab.tabfile = dependent.installed_prefix/Tab::FILENAME
{'fraction_non_alphanumeric': 0.12494539100043688, 'fraction_numerical': 0.00218435998252512, 'mean_word_length': 3.36510962821735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '122044', 'n_tokens_mistral': 1678, 'n_tokens_neox': 1627, 'n_words': 312}