| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  |     let(:formula_file) { path/"Formula/foo.rb" } | 
					
						
							|  |  |  |     let(:path) { (Tap::TAP_DIRECTORY/"homebrew/homebrew-foo").extend(GitRepositoryExtension) } | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-01 16:14:25 -05:00
										 |  |  |     describe "#autosquash!" do | 
					
						
							|  |  |  |       it "squashes a formula correctly" do | 
					
						
							|  |  |  |         secondary_author = "Someone Else <me@example.com>" | 
					
						
							|  |  |  |         (path/"Formula").mkpath | 
					
						
							|  |  |  |         formula_file.write(formula) | 
					
						
							|  |  |  |         cd path do | 
					
						
							|  |  |  |           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 | 
					
						
							|  |  |  |           File.open(formula_file, "w") { |f| f.write(formula_revision) } | 
					
						
							|  |  |  |           safe_system Utils::Git.git, "commit", formula_file, "-m", "revision" | 
					
						
							|  |  |  |           File.open(formula_file, "w") { |f| f.write(formula_version) } | 
					
						
							|  |  |  |           safe_system Utils::Git.git, "commit", formula_file, "-m", "version", "--author=#{secondary_author}" | 
					
						
							|  |  |  |           described_class.autosquash!(original_hash, path: path) | 
					
						
							|  |  |  |           expect(path.git_commit_message).to include("foo 2.0") | 
					
						
							|  |  |  |           expect(path.git_commit_message).to include("Co-authored-by: #{secondary_author}") | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2020-09-19 18:49:33 +10:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-01 16:14:25 -05:00
										 |  |  |     describe "#signoff!" do | 
					
						
							|  |  |  |       it "signs off a formula" do | 
					
						
							|  |  |  |         (path/"Formula").mkpath | 
					
						
							|  |  |  |         formula_file.write(formula) | 
					
						
							|  |  |  |         cd path do | 
					
						
							|  |  |  |           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 | 
					
						
							|  |  |  |         described_class.signoff!(path) | 
					
						
							|  |  |  |         expect(path.git_commit_message).to include("Signed-off-by:") | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-03-30 21:07:56 +11:00
										 |  |  | end |