| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | require "formula" | 
					
						
							|  |  |  | require "formula_installer" | 
					
						
							|  |  |  | require "keg" | 
					
						
							|  |  |  | require "tab" | 
					
						
							| 
									
										
										
										
											2020-05-03 19:00:36 +05:30
										 |  |  | require "cmd/install" | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | require "test/support/fixtures/testball" | 
					
						
							|  |  |  | require "test/support/fixtures/testball_bottle" | 
					
						
							| 
									
										
										
										
											2018-08-17 22:42:37 -04:00
										 |  |  | require "test/support/fixtures/failball" | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe FormulaInstaller do | 
					
						
							| 
									
										
										
										
											2017-05-09 23:00:51 +02:00
										 |  |  |   define_negated_matcher :need_bottle, :be_bottle_unneeded | 
					
						
							|  |  |  |   alias_matcher :have_disabled_bottle, :be_bottle_disabled | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  |   matcher :be_poured_from_bottle do | 
					
						
							|  |  |  |     match(&:poured_from_bottle) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def temporary_install(formula) | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |     expect(formula).not_to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     installer = described_class.new(formula) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-04 17:48:17 -05:00
										 |  |  |     installer.fetch | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |     installer.install | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     keg = Keg.new(formula.prefix) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |     expect(formula).to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       Tab.clear_cache | 
					
						
							|  |  |  |       expect(Tab.for_keg(keg)).not_to be_poured_from_bottle | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-17 22:42:37 -04:00
										 |  |  |       yield formula if block_given? | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  |     ensure | 
					
						
							|  |  |  |       Tab.clear_cache | 
					
						
							|  |  |  |       keg.unlink | 
					
						
							|  |  |  |       keg.uninstall | 
					
						
							|  |  |  |       formula.clear_cache | 
					
						
							|  |  |  |       # there will be log files when sandbox is enable. | 
					
						
							|  |  |  |       formula.logs.rmtree if formula.logs.directory? | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(keg).not_to exist | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |     expect(formula).not_to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   specify "basic installation" do | 
					
						
							|  |  |  |     temporary_install(Testball.new) do |f| | 
					
						
							|  |  |  |       # Test that things made it into the Keg | 
					
						
							|  |  |  |       expect(f.prefix/"readme").to exist | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(f.bin).to be_a_directory | 
					
						
							|  |  |  |       expect(f.bin.children.count).to eq(3) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(f.libexec).to be_a_directory | 
					
						
							|  |  |  |       expect(f.libexec.children.count).to eq(1) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect(f.prefix/"main.c").not_to exist | 
					
						
							|  |  |  |       expect(f.prefix/"license").not_to exist | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Test that things make it into the Cellar | 
					
						
							|  |  |  |       keg = Keg.new f.prefix | 
					
						
							|  |  |  |       keg.link | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       bin = HOMEBREW_PREFIX/"bin" | 
					
						
							|  |  |  |       expect(bin).to be_a_directory | 
					
						
							|  |  |  |       expect(bin.children.count).to eq(3) | 
					
						
							|  |  |  |       expect(f.prefix/".brew/testball.rb").to be_readable | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   specify "Formula installation with unneeded bottle" do | 
					
						
							|  |  |  |     allow(DevelopmentTools).to receive(:installed?).and_return(false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     formula = Testball.new | 
					
						
							|  |  |  |     allow(formula).to receive(:bottle_unneeded?).and_return(true) | 
					
						
							|  |  |  |     allow(formula).to receive(:bottle_disabled?).and_return(true) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(formula).not_to be_bottled | 
					
						
							|  |  |  |     expect(formula).not_to need_bottle | 
					
						
							|  |  |  |     expect(formula).to have_disabled_bottle | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     temporary_install(formula) do |f| | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |       expect(f).to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   specify "Formula is not poured from bottle when compiler specified" do | 
					
						
							| 
									
										
										
										
											2020-05-03 19:00:36 +05:30
										 |  |  |     expect(Homebrew.args.cc).to be nil | 
					
						
							|  |  |  |     Homebrew.install_args.parse(["--cc=clang", "testball_bottle"]) | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  |     temporary_install(TestballBottle.new) do |f| | 
					
						
							|  |  |  |       tab = Tab.for_formula(f) | 
					
						
							|  |  |  |       expect(tab.compiler).to eq("clang") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   specify "check installation sanity pinned dependency" do | 
					
						
							|  |  |  |     dep_name = "dependency" | 
					
						
							|  |  |  |     dep_path = CoreTap.new.formula_dir/"#{dep_name}.rb" | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |     dep_path.write <<~RUBY | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  |       class #{Formulary.class_s(dep_name)} < Formula | 
					
						
							|  |  |  |         url "foo" | 
					
						
							|  |  |  |         version "0.2" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |     RUBY | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-07 00:31:28 +02:00
										 |  |  |     Formulary.cache.delete(dep_path) | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  |     dependency = Formulary.factory(dep_name) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dependent = formula do | 
					
						
							|  |  |  |       url "foo" | 
					
						
							|  |  |  |       version "0.5" | 
					
						
							|  |  |  |       depends_on dependency.name.to_s | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     (dependency.prefix("0.1")/"bin"/"a").mkpath | 
					
						
							|  |  |  |     HOMEBREW_PINNED_KEGS.mkpath | 
					
						
							|  |  |  |     FileUtils.ln_s dependency.prefix("0.1"), HOMEBREW_PINNED_KEGS/dep_name | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dependency_keg = Keg.new(dependency.prefix("0.1")) | 
					
						
							|  |  |  |     dependency_keg.link | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(dependency_keg).to be_linked | 
					
						
							|  |  |  |     expect(dependency).to be_pinned | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |     fi = described_class.new(dependent) | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect { | 
					
						
							|  |  |  |       fi.check_install_sanity | 
					
						
							|  |  |  |     }.to raise_error(CannotInstallFormulaError) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-08-17 22:42:37 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |   specify "install fails with BuildError when a system() call fails" do | 
					
						
							|  |  |  |     ENV["HOMEBREW_TEST_NO_EXIT_CLEANUP"] = "1" | 
					
						
							|  |  |  |     ENV["FAILBALL_BUILD_ERROR"] = "1" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect { | 
					
						
							|  |  |  |       temporary_install(Failball.new) | 
					
						
							|  |  |  |     }.to raise_error(BuildError) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   specify "install fails with a RuntimeError when #install raises" do | 
					
						
							|  |  |  |     ENV["HOMEBREW_TEST_NO_EXIT_CLEANUP"] = "1" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect { | 
					
						
							|  |  |  |       temporary_install(Failball.new) | 
					
						
							|  |  |  |     }.to raise_error(RuntimeError) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-09-19 06:14:20 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |   describe "#caveats" do | 
					
						
							|  |  |  |     subject(:formula_installer) { described_class.new(Testball.new) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it "shows audit problems if HOMEBREW_DEVELOPER is set" do | 
					
						
							|  |  |  |       ENV["HOMEBREW_DEVELOPER"] = "1" | 
					
						
							| 
									
										
										
										
											2020-03-04 17:48:17 -05:00
										 |  |  |       formula_installer.fetch | 
					
						
							| 
									
										
										
										
											2018-09-19 06:14:20 +02:00
										 |  |  |       formula_installer.install | 
					
						
							|  |  |  |       expect(formula_installer).to receive(:audit_installed).and_call_original | 
					
						
							|  |  |  |       formula_installer.caveats | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-02-27 13:43:03 +01:00
										 |  |  | end |