| 
									
										
										
										
											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" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  | describe Homebrew do | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10:00
										 |  |  |   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" } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |   describe "Homebrew.pr_pull_args" do | 
					
						
							|  |  |  |     it_behaves_like "parseable arguments" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 18:49:33 +10: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: ".") | 
					
						
							|  |  |  |         expect(Utils::Git.commit_message(path)).to include("foo 2.0") | 
					
						
							|  |  |  |         expect(Utils::Git.commit_message(path)).to include("Co-authored-by: #{secondary_author}") | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10: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(Utils::Git.commit_message(path)).to include("Signed-off-by:") | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10:00
										 |  |  |   describe "#determine_bump_subject" do | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |     it "correctly bumps a new formula" do | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10:00
										 |  |  |       expect(described_class.determine_bump_subject("", formula, formula_file)).to eq("foo 1.0 (new formula)") | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "correctly bumps a formula version" do | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10:00
										 |  |  |       expect(described_class.determine_bump_subject(formula, formula_version, formula_file)).to eq("foo 2.0") | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "correctly bumps a formula revision with reason" do | 
					
						
							|  |  |  |       expect(described_class.determine_bump_subject( | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10:00
										 |  |  |                formula, formula_revision, formula_file, reason: "for fun" | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |              )).to eq("foo: revision for fun") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "correctly bumps a formula rebuild" do | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10:00
										 |  |  |       expect(described_class.determine_bump_subject(formula, formula_rebuild, formula_file)).to eq("foo: rebuild") | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "correctly bumps a formula deletion" do | 
					
						
							| 
									
										
										
										
											2020-09-19 17:14:06 +10:00
										 |  |  |       expect(described_class.determine_bump_subject(formula, "", formula_file)).to eq("foo: delete") | 
					
						
							| 
									
										
										
										
											2020-09-19 15:22:02 +10:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-03-30 21:07:56 +11:00
										 |  |  | end |