| 
									
										
										
										
											2014-06-19 17:57:36 -05:00
										 |  |  | require "extend/ENV" | 
					
						
							| 
									
										
										
										
											2015-01-13 12:33:50 -05:00
										 |  |  | require "formula_assertions" | 
					
						
							| 
									
										
										
										
											2015-04-13 18:05:41 +08:00
										 |  |  | require "sandbox" | 
					
						
							| 
									
										
										
										
											2015-04-21 16:59:23 +08:00
										 |  |  | require "timeout" | 
					
						
							| 
									
										
										
										
											2012-03-12 21:21:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |   def test | 
					
						
							| 
									
										
										
										
											2012-04-20 13:56:51 -05:00
										 |  |  |     raise FormulaUnspecifiedError if ARGV.named.empty? | 
					
						
							| 
									
										
										
										
											2012-02-04 00:01:29 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 21:13:09 +08:00
										 |  |  |     ARGV.resolved_formulae.each do |f| | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |       # Cannot test uninstalled formulae | 
					
						
							|  |  |  |       unless f.installed? | 
					
						
							| 
									
										
										
										
											2015-05-27 21:14:35 +08:00
										 |  |  |         ofail "Testing requires the latest version of #{f.full_name}" | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       # Cannot test formulae without a test method | 
					
						
							| 
									
										
										
										
											2013-01-07 17:34:56 -06:00
										 |  |  |       unless f.test_defined? | 
					
						
							| 
									
										
										
										
											2015-05-27 21:14:35 +08:00
										 |  |  |         ofail "#{f.full_name} defines no test" | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-27 21:14:35 +08:00
										 |  |  |       puts "Testing #{f.full_name}" | 
					
						
							| 
									
										
										
										
											2014-06-18 23:17:49 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-01-13 12:19:56 -05:00
										 |  |  |       env = ENV.to_hash | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |       begin | 
					
						
							| 
									
										
										
										
											2015-04-13 18:05:41 +08:00
										 |  |  |         args = %W[
 | 
					
						
							|  |  |  |           #{RUBY_PATH} | 
					
						
							|  |  |  |           -W0 | 
					
						
							| 
									
										
										
										
											2015-04-28 22:37:27 -04:00
										 |  |  |           -I #{HOMEBREW_LOAD_PATH} | 
					
						
							| 
									
										
										
										
											2015-04-13 18:05:41 +08:00
										 |  |  |           -- | 
					
						
							|  |  |  |           #{HOMEBREW_LIBRARY_PATH}/test.rb | 
					
						
							|  |  |  |           #{f.path} | 
					
						
							|  |  |  |         ].concat(ARGV.options_only) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-31 17:53:42 +08:00
										 |  |  |         if Sandbox.available? && ARGV.sandbox? | 
					
						
							|  |  |  |           if Sandbox.auto_disable? | 
					
						
							|  |  |  |             Sandbox.print_autodisable_warning | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             Sandbox.print_sandbox_message | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2015-07-21 14:47:37 +08:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-13 18:05:41 +08:00
										 |  |  |         Utils.safe_fork do | 
					
						
							| 
									
										
										
										
											2015-07-21 14:47:37 +08:00
										 |  |  |           if Sandbox.available? && ARGV.sandbox? && !Sandbox.auto_disable? | 
					
						
							| 
									
										
										
										
											2015-04-13 18:05:41 +08:00
										 |  |  |             sandbox = Sandbox.new | 
					
						
							| 
									
										
										
										
											2015-04-26 21:59:47 -04:00
										 |  |  |             f.logs.mkpath | 
					
						
							| 
									
										
										
										
											2015-04-26 21:56:06 -04:00
										 |  |  |             sandbox.record_log(f.logs/"sandbox.test.log") | 
					
						
							| 
									
										
										
										
											2015-04-13 18:05:41 +08:00
										 |  |  |             sandbox.allow_write_temp_and_cache | 
					
						
							|  |  |  |             sandbox.allow_write_log(f) | 
					
						
							|  |  |  |             sandbox.exec(*args) | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             exec(*args) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2013-06-04 20:34:34 +01:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2015-01-13 12:33:50 -05:00
										 |  |  |       rescue Assertions::FailedAssertion => e | 
					
						
							| 
									
										
										
										
											2015-05-27 21:14:35 +08:00
										 |  |  |         ofail "#{f.full_name}: failed" | 
					
						
							| 
									
										
										
										
											2013-06-08 21:26:16 -05:00
										 |  |  |         puts e.message | 
					
						
							| 
									
										
										
										
											2014-06-18 23:27:19 -05:00
										 |  |  |       rescue Exception => e | 
					
						
							| 
									
										
										
										
											2015-05-27 21:14:35 +08:00
										 |  |  |         ofail "#{f.full_name}: failed" | 
					
						
							| 
									
										
										
										
											2014-06-18 23:27:19 -05:00
										 |  |  |         puts e, e.backtrace | 
					
						
							| 
									
										
										
										
											2015-01-13 12:19:56 -05:00
										 |  |  |       ensure | 
					
						
							|  |  |  |         ENV.replace(env) | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |