From fed96385acc2ee10909870997950f2e48a86026f Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sun, 14 Aug 2016 17:33:05 +0100 Subject: [PATCH] sandbox: add test? method. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Simplify checking if we’re going to sandbox a test with `Sandbox.test?`. --- Library/Homebrew/sandbox.rb | 5 +++++ Library/Homebrew/test/test_sandbox.rb | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index 4823baf7f8..c299d2f457 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -8,6 +8,11 @@ class Sandbox OS.mac? && File.executable?(SANDBOX_EXEC) end + def self.test? + return false unless available? + !ARGV.no_sandbox? + end + def self.print_sandbox_message unless @printed_sandbox_message ohai "Using the sandbox" diff --git a/Library/Homebrew/test/test_sandbox.rb b/Library/Homebrew/test/test_sandbox.rb index dc907d428d..de60551d1d 100644 --- a/Library/Homebrew/test/test_sandbox.rb +++ b/Library/Homebrew/test/test_sandbox.rb @@ -13,6 +13,12 @@ class SandboxTest < Homebrew::TestCase @dir.rmtree end + def test_test? + ARGV.stubs(:no_sandbox?).returns false + assert Sandbox.test?, + "Tests should be sandboxed unless --no-sandbox was passed." + end + def test_allow_write @sandbox.allow_write @file @sandbox.exec "touch", @file