| 
									
										
										
										
											2015-04-28 22:37:26 -04:00
										 |  |  | $:.unshift File.expand_path("../..", __FILE__) | 
					
						
							|  |  |  | $:.unshift File.expand_path("../lib", __FILE__) | 
					
						
							| 
									
										
										
										
											2010-02-14 21:23:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-27 21:50:30 +01:00
										 |  |  | require "simplecov" if ENV["HOMEBREW_TESTS_COVERAGE"] | 
					
						
							| 
									
										
										
										
											2015-04-28 22:37:26 -04:00
										 |  |  | require "global" | 
					
						
							| 
									
										
										
										
											2016-01-08 23:35:58 +01:00
										 |  |  | require "formulary" | 
					
						
							| 
									
										
										
										
											2013-04-01 15:53:42 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Test environment setup | 
					
						
							| 
									
										
										
										
											2016-02-26 19:43:49 +08:00
										 |  |  | (HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-core/Formula").mkpath | 
					
						
							| 
									
										
										
										
											2016-07-19 08:23:44 -07:00
										 |  |  | %w[cache formula_cache locks cellar logs temp].each { |d| HOMEBREW_PREFIX.parent.join(d).mkpath } | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:58 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-14 21:23:38 -08:00
										 |  |  | # Test fixtures and files can be found relative to this path | 
					
						
							| 
									
										
										
										
											2014-06-10 21:49:41 -05:00
										 |  |  | TEST_DIRECTORY = File.dirname(File.expand_path(__FILE__)) | 
					
						
							| 
									
										
										
										
											2010-02-14 21:23:38 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:56 -06:00
										 |  |  | begin | 
					
						
							| 
									
										
										
										
											2014-06-10 22:43:47 -05:00
										 |  |  |   require "rubygems" | 
					
						
							|  |  |  |   require "minitest/autorun" | 
					
						
							|  |  |  |   require "mocha/setup" | 
					
						
							| 
									
										
										
										
											2013-01-19 20:45:56 -06:00
										 |  |  | rescue LoadError | 
					
						
							| 
									
										
										
										
											2015-07-22 15:37:34 +01:00
										 |  |  |   abort "Run `bundle install` or install the mocha and minitest gems before running the tests" | 
					
						
							| 
									
										
										
										
											2012-10-25 22:09:23 -05:00
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2013-05-25 17:19:18 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  |   module VersionAssertions | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     def version(v) | 
					
						
							| 
									
										
										
										
											2016-06-22 10:13:07 +03:00
										 |  |  |       Version.create(v) | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     def assert_version_equal(expected, actual) | 
					
						
							| 
									
										
										
										
											2016-07-11 16:09:35 +03:00
										 |  |  |       assert_equal Version.create(expected), actual | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-05 22:04:59 -07:00
										 |  |  |     def assert_version_detected(expected, url, specs = {}) | 
					
						
							| 
									
										
										
										
											2016-02-10 15:03:40 +01:00
										 |  |  |       assert_equal expected, Version.detect(url, specs).to_s | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     def assert_version_nil(url) | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  |       assert_nil Version.parse(url) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-23 19:38:28 -05:00
										 |  |  |   module FSLeakLogger | 
					
						
							|  |  |  |     def self.included(klass) | 
					
						
							|  |  |  |       require "find" | 
					
						
							|  |  |  |       @@log = File.open("fs_leak_log", "w") | 
					
						
							|  |  |  |       klass.make_my_diffs_pretty! | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def before_setup | 
					
						
							|  |  |  |       @__files_before_test = [] | 
					
						
							|  |  |  |       Find.find(TEST_TMPDIR) { |f| @__files_before_test << f.sub(TEST_TMPDIR, "") } | 
					
						
							|  |  |  |       super | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def after_teardown | 
					
						
							|  |  |  |       super | 
					
						
							|  |  |  |       files_after_test = [] | 
					
						
							|  |  |  |       Find.find(TEST_TMPDIR) { |f| files_after_test << f.sub(TEST_TMPDIR, "") } | 
					
						
							|  |  |  |       if @__files_before_test != files_after_test | 
					
						
							|  |  |  |         @@log.puts location, diff(@__files_before_test, files_after_test) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 22:43:47 -05:00
										 |  |  |   class TestCase < ::Minitest::Test | 
					
						
							| 
									
										
										
										
											2016-08-21 04:48:35 +02:00
										 |  |  |     require "test/helper/shutup" | 
					
						
							|  |  |  |     include Test::Helper::Shutup | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  |     include VersionAssertions | 
					
						
							| 
									
										
										
										
											2015-07-22 15:59:33 +08:00
										 |  |  |     include FSLeakLogger | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  |     TEST_SHA1   = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze | 
					
						
							|  |  |  |     TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze | 
					
						
							| 
									
										
										
										
											2013-12-09 15:57:50 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-07 22:52:25 +01:00
										 |  |  |     def formula(name = "formula_name", path = Formulary.core_path(name), spec = :stable, alias_path: nil, &block) | 
					
						
							| 
									
										
										
										
											2016-09-17 15:32:44 +01:00
										 |  |  |       @_f = Class.new(Formula, &block).new(name, path, spec, alias_path: alias_path) | 
					
						
							| 
									
										
										
										
											2014-06-18 20:32:51 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-06-10 22:43:47 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     def mktmpdir(prefix_suffix = nil, &block) | 
					
						
							| 
									
										
										
										
											2015-04-28 22:37:27 -04:00
										 |  |  |       Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP, &block) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-21 13:05:14 +01:00
										 |  |  |     def needs_compat | 
					
						
							|  |  |  |       skip "Requires compat/ code" if ENV["HOMEBREW_NO_COMPAT"] | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-29 15:54:12 -06:00
										 |  |  |     def needs_python | 
					
						
							|  |  |  |       skip "Requires Python" unless which("python") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-10 22:43:47 -05:00
										 |  |  |     def assert_nothing_raised | 
					
						
							|  |  |  |       yield | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-07-03 16:54:46 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     def assert_eql(exp, act, msg = nil) | 
					
						
							| 
									
										
										
										
											2014-07-03 16:54:46 -05:00
										 |  |  |       msg = message(msg, "") { diff exp, act } | 
					
						
							|  |  |  |       assert exp.eql?(act), msg | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     def refute_eql(exp, act, msg = nil) | 
					
						
							| 
									
										
										
										
											2016-08-05 22:04:59 -07:00
										 |  |  |       msg = message(msg) do | 
					
						
							| 
									
										
										
										
											2014-07-03 16:54:46 -05:00
										 |  |  |         "Expected #{mu_pp(act)} to not be eql to #{mu_pp(exp)}" | 
					
						
							| 
									
										
										
										
											2016-08-05 22:04:59 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2014-07-03 16:54:46 -05:00
										 |  |  |       refute exp.eql?(act), msg | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-06-27 19:02:40 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def dylib_path(name) | 
					
						
							|  |  |  |       Pathname.new("#{TEST_DIRECTORY}/mach/#{name}.dylib") | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def bundle_path(name) | 
					
						
							|  |  |  |       Pathname.new("#{TEST_DIRECTORY}/mach/#{name}.bundle") | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-06-29 10:33:08 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     def with_environment(partial_env) | 
					
						
							|  |  |  |       old = ENV.to_hash | 
					
						
							|  |  |  |       ENV.update partial_env | 
					
						
							|  |  |  |       begin | 
					
						
							|  |  |  |         yield | 
					
						
							|  |  |  |       ensure | 
					
						
							|  |  |  |         ENV.replace old | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-05-25 17:19:18 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | end |