| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-22 18:06:49 -08:00
										 |  |  | require "cli/named_args" | 
					
						
							| 
									
										
										
										
											2019-03-28 08:35:36 +00:00
										 |  |  | require "cmd/shared_examples/args_parse" | 
					
						
							| 
									
										
										
										
											2024-04-01 12:01:37 -07:00
										 |  |  | require "cmd/uses" | 
					
						
							|  |  |  | require "fileutils" | 
					
						
							| 
									
										
										
										
											2019-03-28 08:35:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-01 12:01:37 -07:00
										 |  |  | RSpec.describe Homebrew::Cmd::Uses do | 
					
						
							| 
									
										
										
										
											2024-03-30 19:10:56 -07:00
										 |  |  |   include FileUtils | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-03-28 08:35:36 +00:00
										 |  |  |   it_behaves_like "parseable arguments" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-10 14:37:21 +00:00
										 |  |  |   it "prints the Formulae a given Formula is used by", :integration_test, :no_api do | 
					
						
							| 
									
										
										
										
											2023-08-27 17:03:02 -07:00
										 |  |  |     # Included in output | 
					
						
							| 
									
										
										
										
											2017-02-23 06:05:56 +01:00
										 |  |  |     setup_test_formula "bar" | 
					
						
							| 
									
										
										
										
											2023-08-27 17:03:02 -07:00
										 |  |  |     setup_test_formula "optional", <<~RUBY | 
					
						
							|  |  |  |       url "https://brew.sh/optional-1.0" | 
					
						
							|  |  |  |       depends_on "bar" => :optional | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Excluded from output | 
					
						
							|  |  |  |     setup_test_formula "foo" | 
					
						
							|  |  |  |     setup_test_formula "test", <<~RUBY | 
					
						
							|  |  |  |       url "https://brew.sh/test-1.0" | 
					
						
							|  |  |  |       depends_on "foo" => :test | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |     RUBY | 
					
						
							| 
									
										
										
										
											2023-08-27 17:03:02 -07:00
										 |  |  |     setup_test_formula "build", <<~RUBY | 
					
						
							|  |  |  |       url "https://brew.sh/build-1.0" | 
					
						
							|  |  |  |       depends_on "foo" => :build | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |     setup_test_formula "installed", <<~RUBY | 
					
						
							|  |  |  |       url "https://brew.sh/installed-1.0" | 
					
						
							|  |  |  |       depends_on "foo" | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Mock `Formula#any_version_installed?` by creating the tab in a plausible keg directory | 
					
						
							|  |  |  |     %w[foo installed].each do |formula_name| | 
					
						
							|  |  |  |       keg_dir = HOMEBREW_CELLAR/formula_name/"1.0" | 
					
						
							|  |  |  |       keg_dir.mkpath | 
					
						
							| 
									
										
										
										
											2024-06-25 00:15:41 -04:00
										 |  |  |       touch keg_dir/AbstractTab::FILENAME | 
					
						
							| 
									
										
										
										
											2023-08-27 17:03:02 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-02-23 06:05:56 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-27 17:03:02 -07:00
										 |  |  |     expect { brew "uses", "foo", "--eval-all", "--include-optional", "--missing", "--recursive" } | 
					
						
							|  |  |  |       .to output(/^(bar\noptional|optional\nbar)$/).to_stdout | 
					
						
							| 
									
										
										
										
											2017-02-23 06:05:56 +01:00
										 |  |  |       .and not_to_output.to_stderr | 
					
						
							|  |  |  |       .and be_a_success | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2024-11-22 18:06:49 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-10 14:37:21 +00:00
										 |  |  |   it "handles unavailable formula", :integration_test, :no_api do | 
					
						
							| 
									
										
										
										
											2024-11-22 18:06:49 -08:00
										 |  |  |     setup_test_formula "foo" | 
					
						
							|  |  |  |     setup_test_formula "bar" | 
					
						
							|  |  |  |     setup_test_formula "optional", <<~RUBY | 
					
						
							|  |  |  |       url "https://brew.sh/optional-1.0" | 
					
						
							|  |  |  |       depends_on "bar" => :optional | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_any_instance_of(Homebrew::CLI::NamedArgs) | 
					
						
							|  |  |  |       .to receive(:to_formulae) | 
					
						
							|  |  |  |       .and_raise(FormulaUnavailableError, "foo") | 
					
						
							|  |  |  |     cmd = described_class.new(%w[foo --eval-all --include-optional --recursive]) | 
					
						
							|  |  |  |     expect { cmd.run } | 
					
						
							|  |  |  |       .to output(/^(bar\noptional|optional\nbar)$/).to_stdout | 
					
						
							|  |  |  |       .and output(/Error: Missing formulae should not have dependents!\n/).to_stderr | 
					
						
							|  |  |  |       .and raise_error SystemExit | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-02-23 06:05:56 +01:00
										 |  |  | end |