| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | if ENV["HOMEBREW_TESTS_COVERAGE"] | 
					
						
							|  |  |  |   require "simplecov" | 
					
						
							| 
									
										
										
										
											2017-03-05 08:06:45 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-19 14:45:06 +01:00
										 |  |  |   formatters = [SimpleCov::Formatter::HTMLFormatter] | 
					
						
							|  |  |  |   if ENV["HOMEBREW_CODECOV_TOKEN"] || ENV["HOMEBREW_TRAVIS_CI"] | 
					
						
							| 
									
										
										
										
											2017-03-05 08:06:45 +01:00
										 |  |  |     require "codecov" | 
					
						
							| 
									
										
										
										
											2018-09-19 14:45:06 +01:00
										 |  |  |     formatters << SimpleCov::Formatter::Codecov | 
					
						
							|  |  |  |     ENV["CODECOV_TOKEN"] = ENV["HOMEBREW_CODECOV_TOKEN"] | 
					
						
							| 
									
										
										
										
											2017-03-05 08:06:45 +01:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2018-09-19 14:45:06 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(formatters) | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  | require "rspec/its" | 
					
						
							|  |  |  | require "rspec/wait" | 
					
						
							|  |  |  | require "rspec/retry" | 
					
						
							|  |  |  | require "rubocop" | 
					
						
							|  |  |  | require "rubocop/rspec/support" | 
					
						
							|  |  |  | require "find" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 14:23:33 +02:00
										 |  |  | $LOAD_PATH.push(File.expand_path("#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/test/support/lib")) | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 14:23:33 +02:00
										 |  |  | require_relative "../global" | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-07 20:28:56 +01:00
										 |  |  | require "test/support/no_seed_progress_formatter" | 
					
						
							| 
									
										
										
										
											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-07-08 00:57:08 +02:00
										 |  |  | require "test/support/helper/output_as_tty" | 
					
						
							| 
									
										
										
										
											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, | 
					
						
							| 
									
										
										
										
											2018-09-06 18:38:43 +01:00
										 |  |  |   HOMEBREW_LOCKS, | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |   HOMEBREW_LOGS, | 
					
						
							|  |  |  |   HOMEBREW_TEMP, | 
					
						
							|  |  |  | ].freeze | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | RSpec.configure do |config| | 
					
						
							|  |  |  |   config.order = :random | 
					
						
							| 
									
										
										
										
											2017-02-27 22:12:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-25 23:19:13 +02:00
										 |  |  |   config.raise_errors_for_deprecations! | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-07 16:34:29 +01:00
										 |  |  |   config.filter_run_when_matching :focus | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-06 18:17:15 -04:00
										 |  |  |   config.silence_filter_announcements = true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-24 15:09:41 +01:00
										 |  |  |   # TODO: when https://github.com/rspec/rspec-expectations/pull/1056 | 
					
						
							|  |  |  |   #       makes it into a stable release: | 
					
						
							| 
									
										
										
										
											2018-05-24 14:28:20 +01:00
										 |  |  |   # config.expect_with :rspec do |c| | 
					
						
							|  |  |  |   #   c.max_formatted_output_length = 200 | 
					
						
							|  |  |  |   # end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   # Never truncate output objects. | 
					
						
							|  |  |  |   RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = nil | 
					
						
							| 
									
										
										
										
											2018-05-24 14:28:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 19:43:14 +02:00
										 |  |  |   config.include(FileUtils) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |   config.include(RuboCop::RSpec::ExpectOffense) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-07-08 00:57:08 +02:00
										 |  |  |   config.include(Test::Helper::OutputAsTTY) | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 16:56:23 +02:00
										 |  |  |   config.around(:each, :needs_network) do |example| | 
					
						
							|  |  |  |     example.run_with_retry retry: 3, retry_wait: 1
 | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-05 18:36:26 -08:00
										 |  |  |   config.before(:each, :needs_svn) do | 
					
						
							| 
									
										
										
										
											2018-08-13 10:04:32 -07:00
										 |  |  |     skip "subversion not installed." unless which "svn" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   config.before(:each, :needs_unzip) do | 
					
						
							|  |  |  |     skip "unzip not installed." unless which("unzip") | 
					
						
							| 
									
										
										
										
											2018-02-05 18:36:26 -08:00
										 |  |  |   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 | 
					
						
							| 
									
										
										
										
											2018-07-16 10:55:22 +02:00
										 |  |  |       Tap.clear_cache | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |       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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |       unless example.metadata.key?(:focus) || ENV.key?("VERBOSE_TESTS") | 
					
						
							|  |  |  |         @__stdout = $stdout.clone | 
					
						
							|  |  |  |         @__stderr = $stderr.clone | 
					
						
							|  |  |  |         $stdout.reopen(File::NULL) | 
					
						
							|  |  |  |         $stderr.reopen(File::NULL) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |       example.run | 
					
						
							|  |  |  |     ensure | 
					
						
							|  |  |  |       ARGV.replace(@__argv) | 
					
						
							|  |  |  |       ENV.replace(@__env) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-29 19:55:05 +02:00
										 |  |  |       unless example.metadata.key?(:focus) || ENV.key?("VERBOSE_TESTS") | 
					
						
							|  |  |  |         $stdout.reopen(@__stdout) | 
					
						
							|  |  |  |         $stderr.reopen(@__stderr) | 
					
						
							|  |  |  |         @__stdout.close | 
					
						
							|  |  |  |         @__stderr.close | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |       Tab.clear_cache | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       FileUtils.rm_rf [ | 
					
						
							|  |  |  |         TEST_DIRECTORIES.map(&:children), | 
					
						
							| 
									
										
										
										
											2018-09-25 22:03:29 +01:00
										 |  |  |         *Keg::MUST_EXIST_SUBDIRECTORIES, | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |         HOMEBREW_LINKED_KEGS, | 
					
						
							|  |  |  |         HOMEBREW_PINNED_KEGS, | 
					
						
							| 
									
										
										
										
											2018-09-25 22:03:29 +01:00
										 |  |  |         HOMEBREW_PREFIX/"var", | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |         HOMEBREW_PREFIX/"Caskroom", | 
					
						
							| 
									
										
										
										
											2018-05-25 17:28:43 +02:00
										 |  |  |         HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-cask", | 
					
						
							| 
									
										
										
										
											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", | 
					
						
							| 
									
										
										
										
											2018-04-13 16:40:08 +02:00
										 |  |  |         HOMEBREW_LIBRARY/"PinnedTaps", | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |         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-10-15 02:28:32 +02:00
										 |  |  |       expect(diff).to be_empty, <<~EOS | 
					
						
							| 
									
										
										
										
											2017-02-10 21:41:15 +01:00
										 |  |  |         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 | 
					
						
							| 
									
										
										
										
											2018-07-05 09:31:29 +02:00
										 |  |  | RSpec::Matchers.alias_matcher :a_string_containing, :include | 
					
						
							| 
									
										
										
										
											2018-09-17 20:49:43 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | RSpec::Matchers.define :a_json_string do | 
					
						
							|  |  |  |   match do |actual| | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       JSON.parse(actual) | 
					
						
							|  |  |  |       true | 
					
						
							|  |  |  |     rescue JSON::ParseError | 
					
						
							|  |  |  |       false | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |