| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | require "find" | 
					
						
							|  |  |  | require "pathname" | 
					
						
							|  |  |  | require "rspec/its" | 
					
						
							|  |  |  | require "rspec/wait" | 
					
						
							|  |  |  | require "set" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if ENV["HOMEBREW_TESTS_COVERAGE"] | 
					
						
							|  |  |  |   require "simplecov" | 
					
						
							| 
									
										
										
										
											2017-03-05 08:06:45 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   if ENV["CODECOV_TOKEN"] || ENV["TRAVIS"] | 
					
						
							|  |  |  |     require "codecov" | 
					
						
							| 
									
										
										
										
											2017-03-05 22:19:20 +01:00
										 |  |  |     SimpleCov.formatter = SimpleCov::Formatter::Codecov | 
					
						
							| 
									
										
										
										
											2017-03-05 08:06:45 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | $LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew")) | 
					
						
							|  |  |  | $LOAD_PATH.unshift(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/support/lib")) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "global" | 
					
						
							|  |  |  | require "tap" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "test/support/helper/shutup" | 
					
						
							| 
									
										
										
										
											2017-02-21 04:52:53 +01:00
										 |  |  | require "test/support/helper/fixtures" | 
					
						
							| 
									
										
										
										
											2017-02-25 13:26:50 +01:00
										 |  |  | require "test/support/helper/formula" | 
					
						
							| 
									
										
										
										
											2017-02-28 14:50:46 +01:00
										 |  |  | require "test/support/helper/mktmpdir" | 
					
						
							| 
									
										
										
										
											2017-06-08 15:13:06 +03:00
										 |  |  | require "test/support/helper/rubocop" | 
					
						
							| 
									
										
										
										
											2017-03-05 06:31:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | require "test/support/helper/spec/shared_context/homebrew_cask" if OS.mac? | 
					
						
							| 
									
										
										
										
											2017-02-15 19:20:38 +01:00
										 |  |  | require "test/support/helper/spec/shared_context/integration_test" | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | TEST_DIRECTORIES = [ | 
					
						
							|  |  |  |   CoreTap.instance.path/"Formula", | 
					
						
							|  |  |  |   HOMEBREW_CACHE, | 
					
						
							|  |  |  |   HOMEBREW_CACHE_FORMULA, | 
					
						
							|  |  |  |   HOMEBREW_CELLAR, | 
					
						
							|  |  |  |   HOMEBREW_LOCK_DIR, | 
					
						
							|  |  |  |   HOMEBREW_LOGS, | 
					
						
							|  |  |  |   HOMEBREW_TEMP, | 
					
						
							|  |  |  | ].freeze | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RSpec.configure do |config| | 
					
						
							|  |  |  |   config.order = :random | 
					
						
							| 
									
										
										
										
											2017-02-27 22:12:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-07 16:34:29 +01:00
										 |  |  |   config.filter_run_when_matching :focus | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |   config.include(Test::Helper::Shutup) | 
					
						
							| 
									
										
										
										
											2017-02-21 04:52:53 +01:00
										 |  |  |   config.include(Test::Helper::Fixtures) | 
					
						
							| 
									
										
										
										
											2017-02-25 13:26:50 +01:00
										 |  |  |   config.include(Test::Helper::Formula) | 
					
						
							| 
									
										
										
										
											2017-02-28 14:50:46 +01:00
										 |  |  |   config.include(Test::Helper::MkTmpDir) | 
					
						
							| 
									
										
										
										
											2017-06-08 15:13:06 +03:00
										 |  |  |   config.include(Test::Helper::RuboCop) | 
					
						
							| 
									
										
										
										
											2017-02-27 22:12:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-28 13:42:52 +01:00
										 |  |  |   config.before(:each, :needs_compat) do | 
					
						
							|  |  |  |     skip "Requires compatibility layer." if ENV["HOMEBREW_NO_COMPAT"] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-27 22:12:32 +01:00
										 |  |  |   config.before(:each, :needs_official_cmd_taps) do | 
					
						
							|  |  |  |     skip "Needs official command Taps." unless ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config.before(:each, :needs_macos) do | 
					
						
							|  |  |  |     skip "Not on macOS." unless OS.mac? | 
					
						
							| 
									
										
										
										
											2017-02-12 21:37:46 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-02-27 22:12:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   config.before(:each, :needs_python) do | 
					
						
							|  |  |  |     skip "Python not installed." unless which("python") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-22 12:26:18 +01:00
										 |  |  |   config.before(:each, :needs_network) do | 
					
						
							|  |  |  |     skip "Requires network connection." unless ENV["HOMEBREW_TEST_ONLINE"] | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |   config.around(:each) do |example| | 
					
						
							| 
									
										
										
										
											2017-06-24 07:01:35 +02:00
										 |  |  |     def find_files | 
					
						
							|  |  |  |       Find.find(TEST_TMPDIR) | 
					
						
							|  |  |  |           .reject { |f| File.basename(f) == ".DS_Store" } | 
					
						
							|  |  |  |           .map { |f| f.sub(TEST_TMPDIR, "") } | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |     begin | 
					
						
							|  |  |  |       TEST_DIRECTORIES.each(&:mkpath) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 16:52:36 +01:00
										 |  |  |       @__homebrew_failed = Homebrew.failed? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-24 07:01:35 +02:00
										 |  |  |       @__files_before_test = find_files | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       @__argv = ARGV.dup | 
					
						
							|  |  |  |       @__env = ENV.to_hash # dup doesn't work on ENV | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       example.run | 
					
						
							|  |  |  |     ensure | 
					
						
							|  |  |  |       ARGV.replace(@__argv) | 
					
						
							|  |  |  |       ENV.replace(@__env) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       Tab.clear_cache | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       FileUtils.rm_rf [ | 
					
						
							|  |  |  |         TEST_DIRECTORIES.map(&:children), | 
					
						
							|  |  |  |         HOMEBREW_LINKED_KEGS, | 
					
						
							|  |  |  |         HOMEBREW_PINNED_KEGS, | 
					
						
							|  |  |  |         HOMEBREW_PREFIX/".git", | 
					
						
							|  |  |  |         HOMEBREW_PREFIX/"bin", | 
					
						
							|  |  |  |         HOMEBREW_PREFIX/"share", | 
					
						
							|  |  |  |         HOMEBREW_PREFIX/"opt", | 
					
						
							|  |  |  |         HOMEBREW_PREFIX/"Caskroom", | 
					
						
							|  |  |  |         HOMEBREW_LIBRARY/"Taps/caskroom", | 
					
						
							| 
									
										
										
										
											2017-04-23 18:56:22 +01:00
										 |  |  |         HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bar", | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |         HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bundle", | 
					
						
							|  |  |  |         HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo", | 
					
						
							|  |  |  |         HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-services", | 
					
						
							|  |  |  |         HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-shallow", | 
					
						
							|  |  |  |         HOMEBREW_REPOSITORY/".git", | 
					
						
							|  |  |  |         CoreTap.instance.path/".git", | 
					
						
							|  |  |  |         CoreTap.instance.alias_dir, | 
					
						
							|  |  |  |         CoreTap.instance.path/"formula_renames.json", | 
					
						
							|  |  |  |       ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-24 07:01:35 +02:00
										 |  |  |       files_after_test = find_files | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-18 02:30:47 +01:00
										 |  |  |       diff = Set.new(@__files_before_test) ^ Set.new(files_after_test) | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |       expect(diff).to be_empty, <<-EOS.undent
 | 
					
						
							|  |  |  |         file leak detected: | 
					
						
							|  |  |  |         #{diff.map { |f| "  #{f}" }.join("\n")} | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2017-02-18 16:52:36 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       Homebrew.failed = @__homebrew_failed | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2017-02-18 16:52:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-08 15:49:37 +01:00
										 |  |  | RSpec::Matchers.define_negated_matcher :not_to_output, :output | 
					
						
							| 
									
										
										
										
											2017-02-18 16:52:36 +01:00
										 |  |  | RSpec::Matchers.alias_matcher :have_failed, :be_failed |