| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +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 23:27:49 +01:00
										 |  |  | require "test/support/fixtures/testball" | 
					
						
							|  |  |  | require "test/support/fixtures/testball_bottle" | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  | require "test/support/fixtures/testball_bottle_cellar" | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe FormulaInstaller do | 
					
						
							| 
									
										
										
										
											2017-05-09 23:00:51 +02:00
										 |  |  |   alias_matcher :pour_bottle, :be_pour_bottle | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  |   matcher :be_poured_from_bottle do | 
					
						
							|  |  |  |     match(&:poured_from_bottle) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def temporarily_install_bottle(formula) | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |     expect(formula).not_to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  |     expect(formula).to be_bottled | 
					
						
							|  |  |  |     expect(formula).to pour_bottle | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-01 16:36:03 -07:00
										 |  |  |     stub_formula_loader formula("gcc") { url "gcc-1.0" } | 
					
						
							| 
									
										
										
										
											2022-11-09 14:45:43 +00:00
										 |  |  |     stub_formula_loader formula("glibc") { url "glibc-1.0" } | 
					
						
							|  |  |  |     stub_formula_loader formula | 
					
						
							| 
									
										
										
										
											2020-03-04 17:48:17 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     fi = FormulaInstaller.new(formula) | 
					
						
							|  |  |  |     fi.fetch | 
					
						
							|  |  |  |     fi.install | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +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 23:27:49 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       expect(Tab.for_keg(keg)).to be_poured_from_bottle | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       yield formula | 
					
						
							|  |  |  |     ensure | 
					
						
							|  |  |  |       keg.unlink | 
					
						
							|  |  |  |       keg.uninstall | 
					
						
							|  |  |  |       formula.clear_cache | 
					
						
							|  |  |  |       formula.bottle.clear_cache | 
					
						
							|  |  |  |     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 23:27:49 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |   def test_basic_formula_setup(formula) | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |     # Test that things made it into the Keg | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     expect(formula.bin).to be_a_directory | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     expect(formula.libexec).to be_a_directory | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     expect(formula.prefix/"main.c").not_to exist | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Test that things made it into the Cellar | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     keg = Keg.new formula.prefix | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |     keg.link | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     bin = HOMEBREW_PREFIX/"bin" | 
					
						
							|  |  |  |     expect(bin).to be_a_directory | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-10 23:46:07 +00:00
										 |  |  |     expect(formula.libexec).to be_a_directory | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-01-24 20:30:29 -08:00
										 |  |  |   # This test wraps expect() calls in `test_basic_formula_setup` | 
					
						
							|  |  |  |   # rubocop:disable RSpec/NoExpectationExample | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  |   specify "basic bottle install" do | 
					
						
							|  |  |  |     allow(DevelopmentTools).to receive(:installed?).and_return(false) | 
					
						
							| 
									
										
										
										
											2020-07-30 18:40:10 +02:00
										 |  |  |     Homebrew.install_args.parse(["testball_bottle"]) | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  |     temporarily_install_bottle(TestballBottle.new) do |f| | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |       test_basic_formula_setup(f) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-01-24 20:30:29 -08:00
										 |  |  |   # rubocop:enable RSpec/NoExpectationExample | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |   specify "basic bottle install with cellar information on sha256 line" do | 
					
						
							|  |  |  |     allow(DevelopmentTools).to receive(:installed?).and_return(false) | 
					
						
							|  |  |  |     Homebrew.install_args.parse(["testball_bottle_cellar"]) | 
					
						
							|  |  |  |     temporarily_install_bottle(TestballBottleCellar.new) do |f| | 
					
						
							|  |  |  |       test_basic_formula_setup(f) | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |       # skip_relocation is always false on Linux but can be true on macOS. | 
					
						
							|  |  |  |       # see: extend/os/linux/software_spec.rb | 
					
						
							|  |  |  |       skip_relocation = !OS.linux? | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-29 17:51:47 +01:00
										 |  |  |       expect(f.bottle_specification.skip_relocation?).to eq(skip_relocation) | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   specify "build tools error" do | 
					
						
							|  |  |  |     allow(DevelopmentTools).to receive(:installed?).and_return(false) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Testball doesn't have a bottle block, so use it to test this behavior | 
					
						
							|  |  |  |     formula = Testball.new | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |     expect(formula).not_to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  |     expect(formula).not_to be_bottled | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     expect do | 
					
						
							| 
									
										
										
										
											2018-03-25 13:30:37 +01:00
										 |  |  |       described_class.new(formula).install | 
					
						
							| 
									
										
										
										
											2023-03-08 23:14:46 +00:00
										 |  |  |     end.to raise_error(UnbottledError) | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-03 11:42:09 +00:00
										 |  |  |     expect(formula).not_to be_latest_version_installed | 
					
						
							| 
									
										
										
										
											2017-02-27 23:27:49 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |