| 
									
										
										
										
											2012-03-12 21:21:33 -07:00
										 |  |  | require 'extend/ENV' | 
					
						
							|  |  |  | require 'hardware' | 
					
						
							|  |  |  | require 'keg' | 
					
						
							| 
									
										
										
										
											2013-06-04 20:34:34 +01:00
										 |  |  | require 'timeout' | 
					
						
							| 
									
										
										
										
											2013-06-08 21:26:16 -05:00
										 |  |  | require 'test/unit/assertions' | 
					
						
							| 
									
										
										
										
											2012-03-12 21:21:33 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  | module Homebrew extend self | 
					
						
							| 
									
										
										
										
											2013-06-04 20:34:34 +01:00
										 |  |  |   TEST_TIMEOUT_SECONDS = 5*60
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:59 -05:00
										 |  |  |     ENV.extend(Stdenv) | 
					
						
							| 
									
										
										
										
											2012-09-11 14:47:06 -05:00
										 |  |  |     ENV.setup_build_environment | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |     ARGV.formulae.each do |f| | 
					
						
							|  |  |  |       # Cannot test uninstalled formulae | 
					
						
							|  |  |  |       unless f.installed? | 
					
						
							| 
									
										
										
										
											2012-04-30 14:08:59 +10:00
										 |  |  |         ofail "Testing requires the latest version of #{f.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? | 
					
						
							| 
									
										
										
										
											2012-04-30 14:08:59 +10:00
										 |  |  |         ofail "#{f.name} defines no test" | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       puts "Testing #{f.name}" | 
					
						
							|  |  |  |       begin | 
					
						
							| 
									
										
										
										
											2012-02-18 21:32:31 -06:00
										 |  |  |         # tests can also return false to indicate failure | 
					
						
							| 
									
										
										
										
											2013-06-04 20:34:34 +01:00
										 |  |  |         Timeout::timeout TEST_TIMEOUT_SECONDS do | 
					
						
							|  |  |  |           raise if f.test == false | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2013-06-08 21:26:16 -05:00
										 |  |  |       rescue Test::Unit::AssertionFailedError => e | 
					
						
							|  |  |  |         ofail "#{f.name}: failed" | 
					
						
							|  |  |  |         puts e.message | 
					
						
							| 
									
										
										
										
											2013-06-04 20:34:34 +01:00
										 |  |  |       rescue Exception | 
					
						
							| 
									
										
										
										
											2012-04-30 14:08:59 +10:00
										 |  |  |         ofail "#{f.name}: failed" | 
					
						
							| 
									
										
										
										
											2011-03-10 21:28:49 -08:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |