2014-06-19 17:57:36 -05:00
|
|
|
require "extend/ENV"
|
|
|
|
require "timeout"
|
2014-09-18 14:16:07 -05:00
|
|
|
require "debrew"
|
2015-01-13 12:33:50 -05:00
|
|
|
require "formula_assertions"
|
2012-03-12 21:21:33 -07:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
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}"
|
2014-06-18 23:17:49 -05:00
|
|
|
|
2015-01-13 12:33:50 -05:00
|
|
|
f.extend(Assertions)
|
2014-09-18 14:16:07 -05:00
|
|
|
f.extend(Debrew::Formula) if ARGV.debug?
|
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
|
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
|
2014-09-18 14:16:07 -05:00
|
|
|
raise if f.run_test == false
|
2013-06-04 20:34:34 +01:00
|
|
|
end
|
2015-01-13 12:33:50 -05:00
|
|
|
rescue Assertions::FailedAssertion => e
|
2013-06-08 21:26:16 -05:00
|
|
|
ofail "#{f.name}: failed"
|
|
|
|
puts e.message
|
2014-06-18 23:27:19 -05:00
|
|
|
rescue Exception => e
|
2012-04-30 14:08:59 +10:00
|
|
|
ofail "#{f.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
|