| 
									
										
										
										
											2016-07-04 17:05:37 +01:00
										 |  |  | #:  * `tests` [`-v`] [`--coverage`] [`--generic`] [`--no-compat`] [`--only=`<test_script/test_method>] [`--seed` <seed>] [`--trace`] [`--online`] [`--official-cmd-taps`]: | 
					
						
							| 
									
										
										
										
											2016-06-26 23:00:10 -07:00
										 |  |  | #:    Run Homebrew's unit and integration tests. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-18 15:33:59 +01:00
										 |  |  | require "fileutils" | 
					
						
							| 
									
										
										
										
											2016-07-04 17:05:37 +01:00
										 |  |  | require "tap" | 
					
						
							| 
									
										
										
										
											2016-01-18 15:33:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2012-04-16 16:44:11 -05:00
										 |  |  |   def tests | 
					
						
							| 
									
										
										
										
											2015-01-02 12:42:02 +00:00
										 |  |  |     (HOMEBREW_LIBRARY/"Homebrew/test").cd do | 
					
						
							| 
									
										
										
										
											2016-07-04 18:26:44 +01:00
										 |  |  |       ENV["HOMEBREW_NO_ANALYTICS_THIS_RUN"] = "1" | 
					
						
							| 
									
										
										
										
											2016-09-10 09:50:40 +01:00
										 |  |  |       ENV["HOMEBREW_DEVELOPER"] = "1" | 
					
						
							| 
									
										
										
										
											2015-01-02 12:42:02 +00:00
										 |  |  |       ENV["TESTOPTS"] = "-v" if ARGV.verbose? | 
					
						
							| 
									
										
										
										
											2015-07-22 17:09:23 +08:00
										 |  |  |       ENV["HOMEBREW_NO_COMPAT"] = "1" if ARGV.include? "--no-compat" | 
					
						
							| 
									
										
										
										
											2016-05-08 17:12:14 +01:00
										 |  |  |       ENV["HOMEBREW_TEST_GENERIC_OS"] = "1" if ARGV.include? "--generic" | 
					
						
							| 
									
										
										
										
											2016-07-04 13:32:58 +01:00
										 |  |  |       ENV["HOMEBREW_NO_GITHUB_API"] = "1" unless ARGV.include? "--online" | 
					
						
							| 
									
										
										
										
											2016-07-04 18:26:44 +01:00
										 |  |  |       if ARGV.include? "--official-cmd-taps" | 
					
						
							|  |  |  |         ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] = "1" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-18 15:33:59 +01:00
										 |  |  |       if ARGV.include? "--coverage" | 
					
						
							|  |  |  |         ENV["HOMEBREW_TESTS_COVERAGE"] = "1" | 
					
						
							|  |  |  |         FileUtils.rm_f "coverage/.resultset.json" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-12-23 00:34:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-04 14:54:09 +01:00
										 |  |  |       # Override author/committer as global settings might be invalid and thus | 
					
						
							|  |  |  |       # will cause silent failure during the setup of dummy Git repositories. | 
					
						
							|  |  |  |       %w[AUTHOR COMMITTER].each do |role| | 
					
						
							|  |  |  |         ENV["GIT_#{role}_NAME"] = "brew tests" | 
					
						
							|  |  |  |         ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 12:42:02 +00:00
										 |  |  |       Homebrew.install_gem_setup_path! "bundler" | 
					
						
							| 
									
										
										
										
											2015-12-23 00:34:19 +01:00
										 |  |  |       unless quiet_system("bundle", "check") | 
					
						
							|  |  |  |         system "bundle", "install", "--path", "vendor/bundle" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-20 06:39:57 +01:00
										 |  |  |       # Make it easier to reproduce test runs. | 
					
						
							|  |  |  |       ENV["SEED"] = ARGV.next if ARGV.include? "--seed" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-23 00:34:19 +01:00
										 |  |  |       args = [] | 
					
						
							|  |  |  |       args << "--trace" if ARGV.include? "--trace" | 
					
						
							| 
									
										
										
										
											2016-01-20 07:06:09 +01:00
										 |  |  |       if ARGV.value("only") | 
					
						
							| 
									
										
										
										
											2016-05-30 10:49:03 +01:00
										 |  |  |         ENV["HOMEBREW_TESTS_ONLY"] = "1" | 
					
						
							| 
									
										
										
										
											2016-01-20 07:06:09 +01:00
										 |  |  |         test_name, test_method = ARGV.value("only").split("/", 2) | 
					
						
							|  |  |  |         args << "TEST=test_#{test_name}.rb" | 
					
						
							|  |  |  |         args << "TESTOPTS=--name=test_#{test_method}" if test_method | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-01-20 06:39:57 +01:00
										 |  |  |       args += ARGV.named.select { |v| v[/^TEST(OPTS)?=/] } | 
					
						
							| 
									
										
										
										
											2015-12-23 00:34:19 +01:00
										 |  |  |       system "bundle", "exec", "rake", "test", *args | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-02 13:36:01 +00:00
										 |  |  |       Homebrew.failed = !$?.success? | 
					
						
							| 
									
										
										
										
											2015-12-23 00:34:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-22 16:04:59 +08:00
										 |  |  |       if (fs_leak_log = HOMEBREW_LIBRARY/"Homebrew/test/fs_leak_log").file? | 
					
						
							|  |  |  |         fs_leak_log_content = fs_leak_log.read | 
					
						
							|  |  |  |         unless fs_leak_log_content.empty? | 
					
						
							|  |  |  |           opoo "File leak is detected" | 
					
						
							|  |  |  |           puts fs_leak_log_content | 
					
						
							|  |  |  |           Homebrew.failed = true | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-04-16 16:44:11 -05:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-03-25 00:49:18 +11:00
										 |  |  | end |