tests: extract a common using_git_env method
This commit is contained in:
parent
6f305ad3dc
commit
6e0f1366b0
@ -157,18 +157,6 @@ class GitDownloadStrategyTests < Homebrew::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def using_git_env
|
||||
initial_env = ENV.to_hash
|
||||
%w[AUTHOR COMMITTER].each do |role|
|
||||
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
ENV.replace(initial_env)
|
||||
end
|
||||
|
||||
def setup_git_repo
|
||||
using_git_env do
|
||||
@cached_location.cd do
|
||||
|
||||
@ -526,8 +526,6 @@ class FormulaTests < Homebrew::TestCase
|
||||
end
|
||||
|
||||
def test_update_head_version
|
||||
initial_env = ENV.to_hash
|
||||
|
||||
f = formula do
|
||||
head "foo", using: :git
|
||||
end
|
||||
@ -535,12 +533,7 @@ class FormulaTests < Homebrew::TestCase
|
||||
cached_location = f.head.downloader.cached_location
|
||||
cached_location.mkpath
|
||||
|
||||
%w[AUTHOR COMMITTER].each do |role|
|
||||
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
||||
end
|
||||
|
||||
using_git_env do
|
||||
cached_location.cd do
|
||||
FileUtils.touch "LICENSE"
|
||||
shutup do
|
||||
@ -549,11 +542,10 @@ class FormulaTests < Homebrew::TestCase
|
||||
system "git", "commit", "-m", "Initial commit"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
f.update_head_version
|
||||
assert_equal Version.create("HEAD-5658946"), f.head.version
|
||||
ensure
|
||||
ENV.replace(initial_env)
|
||||
end
|
||||
|
||||
def test_legacy_options
|
||||
@ -1104,7 +1096,6 @@ class OutdatedVersionsTests < Homebrew::TestCase
|
||||
tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
|
||||
setup_tab_for_prefix(head_prefix_b)
|
||||
|
||||
initial_env = ENV.to_hash
|
||||
testball_repo = HOMEBREW_PREFIX.join("testball_repo")
|
||||
testball_repo.mkdir
|
||||
|
||||
@ -1114,12 +1105,7 @@ class OutdatedVersionsTests < Homebrew::TestCase
|
||||
head "file://#{testball_repo}", using: :git
|
||||
end
|
||||
|
||||
%w[AUTHOR COMMITTER].each do |role|
|
||||
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
||||
end
|
||||
|
||||
using_git_env do
|
||||
testball_repo.cd do
|
||||
FileUtils.touch "LICENSE"
|
||||
shutup do
|
||||
@ -1128,6 +1114,7 @@ class OutdatedVersionsTests < Homebrew::TestCase
|
||||
system "git", "commit", "-m", "Initial commit"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
refute_predicate f.outdated_kegs(fetch_head: true), :empty?
|
||||
|
||||
@ -1144,7 +1131,6 @@ class OutdatedVersionsTests < Homebrew::TestCase
|
||||
reset_outdated_kegs
|
||||
assert_predicate f.outdated_kegs(fetch_head: true), :empty?
|
||||
ensure
|
||||
ENV.replace(initial_env)
|
||||
testball_repo.rmtree if testball_repo.exist?
|
||||
end
|
||||
|
||||
|
||||
@ -73,16 +73,10 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase
|
||||
end
|
||||
|
||||
def test_install_head_installed
|
||||
initial_env = ENV.to_hash
|
||||
%w[AUTHOR COMMITTER].each do |role|
|
||||
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
||||
end
|
||||
|
||||
repo_path = HOMEBREW_CACHE.join("repo")
|
||||
repo_path.join("bin").mkpath
|
||||
|
||||
using_git_env do
|
||||
repo_path.cd do
|
||||
shutup do
|
||||
system "git", "init"
|
||||
@ -93,6 +87,7 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase
|
||||
system "git", "commit", "-m", "Initial repo commit"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
setup_test_formula "testball1", <<-EOS.undent
|
||||
version "1.0"
|
||||
@ -110,9 +105,6 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase
|
||||
cmd("install", "testball1", "--HEAD", "--ignore-dependencies")
|
||||
assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-2ccdf4f", cmd("unlink", "testball1")
|
||||
assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1")
|
||||
|
||||
ensure
|
||||
ENV.replace(initial_env)
|
||||
end
|
||||
|
||||
def test_install_with_invalid_option
|
||||
|
||||
@ -1,14 +1,32 @@
|
||||
module Test
|
||||
module Helper
|
||||
module Env
|
||||
def copy_env
|
||||
ENV.to_hash
|
||||
end
|
||||
|
||||
def restore_env(env)
|
||||
ENV.replace(env)
|
||||
end
|
||||
|
||||
def with_environment(partial_env)
|
||||
old = ENV.to_hash
|
||||
old = copy_env
|
||||
ENV.update partial_env
|
||||
begin
|
||||
yield
|
||||
ensure
|
||||
ENV.replace old
|
||||
end
|
||||
restore_env old
|
||||
end
|
||||
|
||||
def using_git_env
|
||||
initial_env = copy_env
|
||||
%w[AUTHOR COMMITTER].each do |role|
|
||||
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
||||
end
|
||||
yield
|
||||
ensure
|
||||
restore_env initial_env
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -66,13 +66,7 @@ class TapTest < Homebrew::TestCase
|
||||
end
|
||||
|
||||
def setup_git_repo
|
||||
env = ENV.to_hash
|
||||
%w[AUTHOR COMMITTER].each do |role|
|
||||
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||
ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100"
|
||||
end
|
||||
|
||||
using_git_env do
|
||||
@path.cd do
|
||||
shutup do
|
||||
system "git", "init"
|
||||
@ -81,8 +75,7 @@ class TapTest < Homebrew::TestCase
|
||||
system "git", "commit", "-m", "init"
|
||||
end
|
||||
end
|
||||
ensure
|
||||
ENV.replace(env)
|
||||
end
|
||||
end
|
||||
|
||||
def test_fetch
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user