2020-03-30 21:07:56 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-09-19 15:22:02 +10:00
|
|
|
require "dev-cmd/pr-pull"
|
2020-09-19 17:14:06 +10:00
|
|
|
require "utils/git"
|
|
|
|
require "tap"
|
2020-03-30 21:07:56 +11:00
|
|
|
require "cmd/shared_examples/args_parse"
|
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
describe "brew pr-pull" do
|
|
|
|
it_behaves_like "parseable arguments"
|
2020-09-19 17:14:06 +10:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
describe Homebrew do
|
|
|
|
let(:formula_rebuild) do
|
|
|
|
<<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
desc "Helpful description"
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
let(:formula_revision) do
|
|
|
|
<<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
revision 1
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
let(:formula_version) do
|
|
|
|
<<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
url "https://brew.sh/foo-2.0.tgz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
let(:formula) do
|
|
|
|
<<~EOS
|
|
|
|
class Foo < Formula
|
|
|
|
url "https://brew.sh/foo-1.0.tgz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
2022-01-10 18:57:56 +02:00
|
|
|
let(:cask_rebuild) do
|
|
|
|
<<~EOS
|
|
|
|
cask "food" do
|
|
|
|
desc "Helpful description"
|
|
|
|
version "1.0"
|
2022-04-26 08:57:29 +02:00
|
|
|
sha256 "a"
|
|
|
|
url "https://brew.sh/food-\#{version}.tgz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
let(:cask_checksum) do
|
|
|
|
<<~EOS
|
|
|
|
cask "food" do
|
|
|
|
desc "Helpful description"
|
|
|
|
version "1.0"
|
|
|
|
sha256 "b"
|
2022-01-10 18:57:56 +02:00
|
|
|
url "https://brew.sh/food-\#{version}.tgz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
let(:cask_version) do
|
|
|
|
<<~EOS
|
|
|
|
cask "food" do
|
|
|
|
version "2.0"
|
2022-04-26 08:57:29 +02:00
|
|
|
sha256 "a"
|
2022-01-10 18:57:56 +02:00
|
|
|
url "https://brew.sh/food-\#{version}.tgz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
let(:cask) do
|
|
|
|
<<~EOS
|
|
|
|
cask "food" do
|
|
|
|
version "1.0"
|
2022-04-26 08:57:29 +02:00
|
|
|
sha256 "a"
|
2022-01-10 18:57:56 +02:00
|
|
|
url "https://brew.sh/food-\#{version}.tgz"
|
|
|
|
end
|
|
|
|
EOS
|
|
|
|
end
|
2022-03-01 16:11:50 +00:00
|
|
|
let(:tap) { Tap.fetch("Homebrew", "foo") }
|
|
|
|
let(:formula_file) { tap.path/"Formula/foo.rb" }
|
2022-01-10 18:57:56 +02:00
|
|
|
let(:cask_file) { tap.cask_dir/"food.rb" }
|
2023-04-15 18:13:38 -07:00
|
|
|
let(:path) { Pathname(Tap::TAP_DIRECTORY/"homebrew/homebrew-foo") }
|
2020-09-19 15:22:02 +10:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
describe "#autosquash!" do
|
2022-01-10 18:57:56 +02:00
|
|
|
it "squashes a formula or cask correctly" do
|
2021-02-01 16:14:25 -05:00
|
|
|
secondary_author = "Someone Else <me@example.com>"
|
2022-03-01 16:11:50 +00:00
|
|
|
(tap.path/"Formula").mkpath
|
2021-02-01 16:14:25 -05:00
|
|
|
formula_file.write(formula)
|
2022-03-01 16:11:50 +00:00
|
|
|
cd tap.path do
|
2021-02-01 16:14:25 -05:00
|
|
|
safe_system Utils::Git.git, "init"
|
|
|
|
safe_system Utils::Git.git, "add", formula_file
|
|
|
|
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
|
|
|
|
original_hash = `git rev-parse HEAD`.chomp
|
2021-12-23 14:49:05 -05:00
|
|
|
File.write(formula_file, formula_revision)
|
2021-02-01 16:14:25 -05:00
|
|
|
safe_system Utils::Git.git, "commit", formula_file, "-m", "revision"
|
2021-12-23 14:49:05 -05:00
|
|
|
File.write(formula_file, formula_version)
|
2021-02-01 16:14:25 -05:00
|
|
|
safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}"
|
2022-03-01 16:11:50 +00:00
|
|
|
described_class.autosquash!(original_hash, tap: tap)
|
2023-04-15 18:13:38 -07:00
|
|
|
expect(tap.git_repo.commit_message).to include("foo 2.0")
|
|
|
|
expect(tap.git_repo.commit_message).to include("Co-authored-by: #{secondary_author}")
|
2021-02-01 16:14:25 -05:00
|
|
|
end
|
2022-01-10 18:57:56 +02:00
|
|
|
|
|
|
|
(path/"Casks").mkpath
|
|
|
|
cask_file.write(cask)
|
|
|
|
cd path do
|
|
|
|
safe_system Utils::Git.git, "add", cask_file
|
|
|
|
safe_system Utils::Git.git, "commit", "-m", "food 1.0 (new cask)"
|
|
|
|
original_hash = `git rev-parse HEAD`.chomp
|
|
|
|
File.write(cask_file, cask_rebuild)
|
|
|
|
safe_system Utils::Git.git, "commit", cask_file, "-m", "rebuild"
|
|
|
|
File.write(cask_file, cask_version)
|
|
|
|
safe_system Utils::Git.git, "commit", cask_file, "-m", "version", "--author=#{secondary_author}"
|
|
|
|
described_class.autosquash!(original_hash, tap: tap)
|
2023-04-15 19:06:40 -07:00
|
|
|
git_repo = GitRepository.new(path)
|
2023-04-15 18:13:38 -07:00
|
|
|
expect(git_repo.commit_message).to include("food 2.0")
|
|
|
|
expect(git_repo.commit_message).to include("Co-authored-by: #{secondary_author}")
|
2022-01-10 18:57:56 +02:00
|
|
|
end
|
2020-09-19 18:49:33 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
describe "#signoff!" do
|
2022-01-10 18:57:56 +02:00
|
|
|
it "signs off a formula or cask" do
|
2022-03-01 16:11:50 +00:00
|
|
|
(tap.path/"Formula").mkpath
|
2021-02-01 16:14:25 -05:00
|
|
|
formula_file.write(formula)
|
2022-03-01 16:11:50 +00:00
|
|
|
cd tap.path do
|
2021-02-01 16:14:25 -05:00
|
|
|
safe_system Utils::Git.git, "init"
|
|
|
|
safe_system Utils::Git.git, "add", formula_file
|
|
|
|
safe_system Utils::Git.git, "commit", "-m", "foo 1.0 (new formula)"
|
|
|
|
end
|
2023-04-15 19:06:40 -07:00
|
|
|
described_class.signoff!(tap.git_repo)
|
2023-04-15 18:13:38 -07:00
|
|
|
expect(tap.git_repo.commit_message).to include("Signed-off-by:")
|
2022-01-10 18:57:56 +02:00
|
|
|
|
|
|
|
(path/"Casks").mkpath
|
|
|
|
cask_file.write(cask)
|
|
|
|
cd path do
|
|
|
|
safe_system Utils::Git.git, "add", cask_file
|
|
|
|
safe_system Utils::Git.git, "commit", "-m", "food 1.0 (new cask)"
|
|
|
|
end
|
2023-04-15 19:06:40 -07:00
|
|
|
described_class.signoff!(tap.git_repo)
|
2023-04-15 18:13:38 -07:00
|
|
|
expect(tap.git_repo.commit_message).to include("Signed-off-by:")
|
2022-01-10 18:57:56 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#get_package" do
|
|
|
|
it "returns a formula" do
|
|
|
|
expect(described_class.get_package(tap, "foo", formula_file, formula)).to be_a(Formula)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil for an unknown formula" do
|
|
|
|
expect(described_class.get_package(tap, "foo", formula_file, "")).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns a cask" do
|
|
|
|
expect(described_class.get_package(tap, "foo", cask_file, cask)).to be_a(Cask::Cask)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns nil for an unknown cask" do
|
|
|
|
expect(described_class.get_package(tap, "foo", cask_file, "")).to be_nil
|
2020-09-19 17:14:06 +10:00
|
|
|
end
|
2020-09-19 15:22:02 +10:00
|
|
|
end
|
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
describe "#determine_bump_subject" do
|
|
|
|
it "correctly bumps a new formula" do
|
|
|
|
expect(described_class.determine_bump_subject("", formula, formula_file)).to eq("foo 1.0 (new formula)")
|
|
|
|
end
|
2020-09-19 15:22:02 +10:00
|
|
|
|
2022-01-10 18:57:56 +02:00
|
|
|
it "correctly bumps a new cask" do
|
|
|
|
expect(described_class.determine_bump_subject("", cask, cask_file)).to eq("food 1.0 (new cask)")
|
|
|
|
end
|
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
it "correctly bumps a formula version" do
|
|
|
|
expect(described_class.determine_bump_subject(formula, formula_version, formula_file)).to eq("foo 2.0")
|
|
|
|
end
|
2020-09-19 15:22:02 +10:00
|
|
|
|
2022-01-10 18:57:56 +02:00
|
|
|
it "correctly bumps a cask version" do
|
|
|
|
expect(described_class.determine_bump_subject(cask, cask_version, cask_file)).to eq("food 2.0")
|
|
|
|
end
|
|
|
|
|
2022-04-26 08:57:29 +02:00
|
|
|
it "correctly bumps a cask checksum" do
|
|
|
|
expect(described_class.determine_bump_subject(cask, cask_checksum, cask_file)).to eq("food: checksum update")
|
|
|
|
end
|
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
it "correctly bumps a formula revision with reason" do
|
|
|
|
expect(described_class.determine_bump_subject(
|
|
|
|
formula, formula_revision, formula_file, reason: "for fun"
|
|
|
|
)).to eq("foo: revision for fun")
|
|
|
|
end
|
2020-09-19 15:22:02 +10:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
it "correctly bumps a formula rebuild" do
|
|
|
|
expect(described_class.determine_bump_subject(formula, formula_rebuild, formula_file)).to eq("foo: rebuild")
|
|
|
|
end
|
2020-09-19 15:22:02 +10:00
|
|
|
|
2021-02-01 16:14:25 -05:00
|
|
|
it "correctly bumps a formula deletion" do
|
|
|
|
expect(described_class.determine_bump_subject(formula, "", formula_file)).to eq("foo: delete")
|
|
|
|
end
|
2022-01-10 18:57:56 +02:00
|
|
|
|
|
|
|
it "correctly bumps a cask deletion" do
|
|
|
|
expect(described_class.determine_bump_subject(cask, "", cask_file)).to eq("food: delete")
|
|
|
|
end
|
2020-09-19 15:22:02 +10:00
|
|
|
end
|
|
|
|
end
|
2020-03-30 21:07:56 +11:00
|
|
|
end
|