2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-08-05 18:23:08 +02:00
|
|
|
require "cmd/update-report"
|
|
|
|
require "formula_versions"
|
|
|
|
require "yaml"
|
2019-03-28 08:35:36 +00:00
|
|
|
require "cmd/shared_examples/args_parse"
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe "brew update-report" do
|
2019-03-28 08:35:36 +00:00
|
|
|
it_behaves_like "parseable arguments"
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
describe Reporter do
|
|
|
|
let(:tap) { CoreTap.new }
|
|
|
|
let(:reporter_class) do
|
|
|
|
Class.new(described_class) do
|
|
|
|
def initialize(tap)
|
|
|
|
@tap = tap
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2024-02-15 21:24:34 +01:00
|
|
|
ENV["HOMEBREW_UPDATE_BEFORE#{tap.repo_var_suffix}"] = "12345678"
|
|
|
|
ENV["HOMEBREW_UPDATE_AFTER#{tap.repo_var_suffix}"] = "abcdef00"
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
super(tap)
|
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
end
|
|
|
|
end
|
2021-02-01 16:14:25 -05:00
|
|
|
let(:reporter) { reporter_class.new(tap) }
|
|
|
|
let(:hub) { ReporterHub.new }
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
def perform_update(fixture_name = "")
|
2023-01-22 17:05:16 -08:00
|
|
|
allow(Formulary).to receive(:factory).and_return(instance_double(Formula, pkg_version: "1.0"))
|
|
|
|
allow(FormulaVersions).to receive(:new).and_return(instance_double(FormulaVersions, formula_at_revision: "2.0"))
|
2019-03-28 08:35:36 +00:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
diff = YAML.load_file("#{TEST_FIXTURE_DIR}/updater_fixture.yaml")[fixture_name]
|
|
|
|
allow(reporter).to receive(:diff).and_return(diff || "")
|
2019-03-28 08:35:36 +00:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
hub.add(reporter) if reporter.updated?
|
|
|
|
end
|
2019-03-28 08:35:36 +00:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "without revision variable" do
|
|
|
|
ENV.delete_if { |k, _v| k.start_with? "HOMEBREW_UPDATE" }
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2023-03-08 23:14:46 +00:00
|
|
|
expect do
|
2021-02-01 16:14:25 -05:00
|
|
|
described_class.new(tap)
|
2023-03-08 23:14:46 +00:00
|
|
|
end.to raise_error(Reporter::ReporterRevisionUnsetError)
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "without any changes" do
|
|
|
|
perform_update
|
|
|
|
expect(hub).to be_empty
|
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "without Formula changes" do
|
|
|
|
perform_update("update_git_diff_output_without_formulae_changes")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:M)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:A)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:D)).to be_empty
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "with Formula changes" do
|
|
|
|
perform_update("update_git_diff_output_with_formulae_changes")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:M)).to eq(%w[xar yajl])
|
|
|
|
expect(hub.select_formula_or_cask(:A)).to eq(%w[antiword bash-completion ddrescue dict lua])
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "with removed Formulae" do
|
|
|
|
perform_update("update_git_diff_output_with_removed_formulae")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:D)).to eq(%w[libgsasl])
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "with changed file type" do
|
|
|
|
perform_update("update_git_diff_output_with_changed_filetype")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:M)).to eq(%w[elixir])
|
|
|
|
expect(hub.select_formula_or_cask(:A)).to eq(%w[libbson])
|
|
|
|
expect(hub.select_formula_or_cask(:D)).to eq(%w[libgsasl])
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "with renamed Formula" do
|
|
|
|
allow(tap).to receive(:formula_renames).and_return("cv" => "progress")
|
|
|
|
perform_update("update_git_diff_output_with_formula_rename")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:A)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:D)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:R)).to eq([["cv", "progress"]])
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
context "when updating a Tap other than the core Tap" do
|
|
|
|
let(:tap) { Tap.new("foo", "bar") }
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
before do
|
|
|
|
(tap.path/"Formula").mkpath
|
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
after do
|
|
|
|
tap.path.parent.rmtree
|
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "with restructured Tap" do
|
|
|
|
perform_update("update_git_diff_output_with_restructured_tap")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:A)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:D)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:R)).to be_empty
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "with renamed Formula and restructured Tap" do
|
|
|
|
allow(tap).to receive(:formula_renames).and_return("xchat" => "xchat2")
|
|
|
|
perform_update("update_git_diff_output_with_formula_rename_and_restructuring")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:A)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:D)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:R)).to eq([%w[foo/bar/xchat foo/bar/xchat2]])
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "with simulated 'homebrew/php' restructuring" do
|
|
|
|
perform_update("update_git_diff_simulate_homebrew_php_restructuring")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:A)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:D)).to be_empty
|
|
|
|
expect(hub.select_formula_or_cask(:R)).to be_empty
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
specify "with Formula changes" do
|
|
|
|
perform_update("update_git_diff_output_with_tap_formulae_changes")
|
2018-08-05 18:23:08 +02:00
|
|
|
|
2022-06-03 19:16:15 +01:00
|
|
|
expect(hub.select_formula_or_cask(:A)).to eq(%w[foo/bar/lua])
|
|
|
|
expect(hub.select_formula_or_cask(:M)).to eq(%w[foo/bar/git])
|
|
|
|
expect(hub.select_formula_or_cask(:D)).to be_empty
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2018-08-05 18:23:08 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|