sandbox test
This commit is contained in:
parent
a6be0b5bb8
commit
b621edf89d
@ -1,17 +1,12 @@
|
|||||||
require "extend/ENV"
|
require "extend/ENV"
|
||||||
require "timeout"
|
|
||||||
require "debrew"
|
|
||||||
require "formula_assertions"
|
require "formula_assertions"
|
||||||
|
require "sandbox"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
TEST_TIMEOUT_SECONDS = 5*60
|
|
||||||
|
|
||||||
def test
|
def test
|
||||||
raise FormulaUnspecifiedError if ARGV.named.empty?
|
raise FormulaUnspecifiedError if ARGV.named.empty?
|
||||||
|
|
||||||
ENV.extend(Stdenv)
|
|
||||||
ENV.setup_build_environment
|
|
||||||
|
|
||||||
ARGV.formulae.each do |f|
|
ARGV.formulae.each do |f|
|
||||||
# Cannot test uninstalled formulae
|
# Cannot test uninstalled formulae
|
||||||
unless f.installed?
|
unless f.installed?
|
||||||
@ -27,15 +22,27 @@ module Homebrew
|
|||||||
|
|
||||||
puts "Testing #{f.name}"
|
puts "Testing #{f.name}"
|
||||||
|
|
||||||
f.extend(Assertions)
|
|
||||||
f.extend(Debrew::Formula) if ARGV.debug?
|
|
||||||
|
|
||||||
env = ENV.to_hash
|
env = ENV.to_hash
|
||||||
|
|
||||||
begin
|
begin
|
||||||
# tests can also return false to indicate failure
|
args = %W[
|
||||||
Timeout::timeout TEST_TIMEOUT_SECONDS do
|
#{RUBY_PATH}
|
||||||
raise "test returned false" if f.run_test == false
|
-W0
|
||||||
|
-I #{HOMEBREW_LIBRARY_PATH}
|
||||||
|
--
|
||||||
|
#{HOMEBREW_LIBRARY_PATH}/test.rb
|
||||||
|
#{f.path}
|
||||||
|
].concat(ARGV.options_only)
|
||||||
|
|
||||||
|
Utils.safe_fork do
|
||||||
|
if Sandbox.available? && ARGV.sandbox?
|
||||||
|
sandbox = Sandbox.new
|
||||||
|
sandbox.allow_write_temp_and_cache
|
||||||
|
sandbox.allow_write_log(f)
|
||||||
|
sandbox.exec(*args)
|
||||||
|
else
|
||||||
|
exec(*args)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue Assertions::FailedAssertion => e
|
rescue Assertions::FailedAssertion => e
|
||||||
ofail "#{f.name}: failed"
|
ofail "#{f.name}: failed"
|
||||||
|
|||||||
34
Library/Homebrew/test.rb
Normal file
34
Library/Homebrew/test.rb
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
old_trap = trap("INT") { exit! 130 }
|
||||||
|
|
||||||
|
require "global"
|
||||||
|
require "extend/ENV"
|
||||||
|
require "timeout"
|
||||||
|
require "debrew"
|
||||||
|
require "formula_assertions"
|
||||||
|
require "fcntl"
|
||||||
|
require "socket"
|
||||||
|
|
||||||
|
TEST_TIMEOUT_SECONDS = 5*60
|
||||||
|
|
||||||
|
begin
|
||||||
|
error_pipe = UNIXSocket.open(ENV["HOMEBREW_ERROR_PIPE"], &:recv_io)
|
||||||
|
error_pipe.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
|
||||||
|
|
||||||
|
ENV.extend(Stdenv)
|
||||||
|
ENV.setup_build_environment
|
||||||
|
|
||||||
|
trap("INT", old_trap)
|
||||||
|
|
||||||
|
formula = ARGV.formulae.first
|
||||||
|
formula.extend(Homebrew::Assertions)
|
||||||
|
formula.extend(Debrew::Formula) if ARGV.debug?
|
||||||
|
|
||||||
|
# tests can also return false to indicate failure
|
||||||
|
Timeout::timeout TEST_TIMEOUT_SECONDS do
|
||||||
|
raise "test returned false" if formula.run_test == false
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
Marshal.dump(e, error_pipe)
|
||||||
|
error_pipe.close
|
||||||
|
exit! 1
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user