62 lines
1.4 KiB
Ruby
Raw Normal View History

2014-06-19 17:57:36 -05:00
require "extend/ENV"
require "formula_assertions"
2015-04-13 18:05:41 +08:00
require "sandbox"
require "timeout"
module Homebrew
2013-06-04 20:34:34 +01:00
2011-03-10 21:28:49 -08:00
def test
raise FormulaUnspecifiedError if ARGV.named.empty?
2011-03-10 21:28:49 -08:00
ARGV.formulae.each do |f|
# Cannot test uninstalled formulae
unless f.installed?
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?
ofail "#{f.name} defines no test"
2011-03-10 21:28:49 -08:00
next
end
puts "Testing #{f.name}"
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
-I #{HOMEBREW_LOAD_PATH}
2015-04-13 18:05:41 +08:00
--
#{HOMEBREW_LIBRARY_PATH}/test.rb
#{f.path}
].concat(ARGV.options_only)
Utils.safe_fork do
if Sandbox.available? && ARGV.sandbox?
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
rescue Assertions::FailedAssertion => e
ofail "#{f.name}: failed"
puts e.message
rescue Exception => e
ofail "#{f.name}: failed"
puts e, e.backtrace
ensure
ENV.replace(env)
2011-03-10 21:28:49 -08:00
end
end
end
end