Skip to content
Snippets Groups Projects
Commit 6e0f1366 authored by Alyssa Ross's avatar Alyssa Ross
Browse files

tests: extract a common using_git_env method

parent 6f305ad3
No related branches found
No related tags found
No related merge requests found
......@@ -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,25 +533,19 @@ 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
cached_location.cd do
FileUtils.touch "LICENSE"
shutup do
system "git", "init"
system "git", "add", "--all"
system "git", "commit", "-m", "Initial commit"
using_git_env do
cached_location.cd do
FileUtils.touch "LICENSE"
shutup do
system "git", "init"
system "git", "add", "--all"
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,18 +1105,14 @@ 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
testball_repo.cd do
FileUtils.touch "LICENSE"
shutup do
system "git", "init"
system "git", "add", "--all"
system "git", "commit", "-m", "Initial commit"
using_git_env do
testball_repo.cd do
FileUtils.touch "LICENSE"
shutup do
system "git", "init"
system "git", "add", "--all"
system "git", "commit", "-m", "Initial commit"
end
end
end
......@@ -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,24 +73,19 @@ 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
repo_path.cd do
shutup do
system "git", "init"
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
FileUtils.touch "bin/something.bin"
FileUtils.touch "README"
system "git", "add", "--all"
system "git", "commit", "-m", "Initial repo commit"
using_git_env do
repo_path.cd do
shutup do
system "git", "init"
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
FileUtils.touch "bin/something.bin"
FileUtils.touch "README"
system "git", "add", "--all"
system "git", "commit", "-m", "Initial repo commit"
end
end
end
......@@ -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
......
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
yield
ensure
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,23 +66,16 @@ 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
@path.cd do
shutup do
system "git", "init"
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
system "git", "add", "--all"
system "git", "commit", "-m", "init"
using_git_env do
@path.cd do
shutup do
system "git", "init"
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
system "git", "add", "--all"
system "git", "commit", "-m", "init"
end
end
end
ensure
ENV.replace(env)
end
def test_fetch
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment