Ensure HOMEBREW_TEMP is respected in all tests

This commit is contained in:
Jack Nagel 2015-04-28 22:37:27 -04:00
parent 44ca2043d0
commit dc6af1a6ae
4 changed files with 10 additions and 5 deletions

View File

@ -1,7 +1,9 @@
require "tmpdir" require "tmpdir"
HOMEBREW_TEMP = Pathname.new(ENV["HOMEBREW_TEMP"] || "/tmp")
TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") { |k| TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") { |k|
dir = Dir.mktmpdir("homebrew_tests") dir = Dir.mktmpdir("homebrew_tests", HOMEBREW_TEMP)
at_exit { FileUtils.remove_entry(dir) } at_exit { FileUtils.remove_entry(dir) }
ENV[k] = dir ENV[k] = dir
} }
@ -13,4 +15,3 @@ HOMEBREW_CACHE = HOMEBREW_PREFIX.parent+"cache"
HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+"formula_cache" HOMEBREW_CACHE_FORMULA = HOMEBREW_PREFIX.parent+"formula_cache"
HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+"cellar" HOMEBREW_CELLAR = HOMEBREW_PREFIX.parent+"cellar"
HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+"logs" HOMEBREW_LOGS = HOMEBREW_PREFIX.parent+"logs"
HOMEBREW_TEMP = Pathname.new(ENV["HOMEBREW_TEMP"] || "/tmp")

View File

@ -7,8 +7,8 @@ module PathnameTestExtension
include FileUtils include FileUtils
def setup def setup
@src = Pathname.new(Dir.mktmpdir) @src = Pathname.new(mktmpdir)
@dst = Pathname.new(Dir.mktmpdir) @dst = Pathname.new(mktmpdir)
@file = @src+'foo' @file = @src+'foo'
@dir = @src+'bar' @dir = @src+'bar'
end end

View File

@ -5,7 +5,7 @@ class SandboxTest < Homebrew::TestCase
def setup def setup
skip "sandbox not implemented" unless Sandbox.available? skip "sandbox not implemented" unless Sandbox.available?
@sandbox = Sandbox.new @sandbox = Sandbox.new
@dir = Pathname.new(Dir.mktmpdir) @dir = Pathname.new(mktmpdir)
@file = @dir/"foo" @file = @dir/"foo"
end end

View File

@ -91,6 +91,10 @@ module Homebrew
end end
end end
def mktmpdir(prefix_suffix=nil, &block)
Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP, &block)
end
def assert_nothing_raised def assert_nothing_raised
yield yield
end end