Merge pull request #1890 from alyssais/global_teardown_env
tests: automatically restore ENV in teardown
This commit is contained in:
commit
2c1fbe1693
@ -39,17 +39,17 @@ describe Hbc::CLI do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "respects the env variable when choosing what appdir to create" do
|
it "respects the env variable when choosing what appdir to create" do
|
||||||
with_environment "HOMEBREW_CASK_OPTS" => "--appdir=/custom/appdir" do
|
allow(ENV).to receive(:[])
|
||||||
expect(Hbc).to receive(:appdir=).with(Pathname("/custom/appdir"))
|
allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--appdir=/custom/appdir")
|
||||||
described_class.process("noop")
|
expect(Hbc).to receive(:appdir=).with(Pathname.new("/custom/appdir"))
|
||||||
end
|
described_class.process("noop")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "respects the env variable when choosing a non-default Caskroom location" do
|
it "respects the env variable when choosing a non-default Caskroom location" do
|
||||||
with_environment "HOMEBREW_CASK_OPTS" => "--caskroom=/custom/caskdir" do
|
allow(ENV).to receive(:[])
|
||||||
expect(Hbc).to receive(:caskroom=).with(Pathname("/custom/caskdir"))
|
allow(ENV).to receive(:[]).with("HOMEBREW_CASK_OPTS").and_return("--caskroom=/custom/caskdir")
|
||||||
described_class.process("noop")
|
expect(Hbc).to receive(:caskroom=).with(Pathname.new("/custom/caskdir"))
|
||||||
end
|
described_class.process("noop")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "exits with a status of 1 when something goes wrong" do
|
it "exits with a status of 1 when something goes wrong" do
|
||||||
|
|||||||
@ -15,7 +15,6 @@ require "global"
|
|||||||
# add Homebrew-Cask to load path
|
# add Homebrew-Cask to load path
|
||||||
$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
|
$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
|
||||||
|
|
||||||
require "test/support/helper/env"
|
|
||||||
require "test/support/helper/shutup"
|
require "test/support/helper/shutup"
|
||||||
|
|
||||||
Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "*.rb")).each(&method(:require))
|
Pathname.glob(HOMEBREW_LIBRARY_PATH.join("cask", "spec", "support", "*.rb")).each(&method(:require))
|
||||||
@ -38,6 +37,5 @@ end
|
|||||||
|
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.order = :random
|
config.order = :random
|
||||||
config.include(Test::Helper::Env)
|
|
||||||
config.include(Test::Helper::Shutup)
|
config.include(Test::Helper::Shutup)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -69,7 +69,11 @@ describe Hbc::DSL do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "may use deprecated DSL version hash syntax" do
|
it "may use deprecated DSL version hash syntax" do
|
||||||
with_environment "HOMEBREW_DEVELOPER" => nil do
|
stub = proc do |arg|
|
||||||
|
arg == "HOMEBREW_DEVELOPER" ? nil : ENV[arg]
|
||||||
|
end
|
||||||
|
|
||||||
|
ENV.stub :[], stub do
|
||||||
shutup do
|
shutup do
|
||||||
test_cask = Hbc.load("with-dsl-version")
|
test_cask = Hbc.load("with-dsl-version")
|
||||||
test_cask.token.must_equal "with-dsl-version"
|
test_cask.token.must_equal "with-dsl-version"
|
||||||
|
|||||||
@ -13,9 +13,7 @@ require "global"
|
|||||||
# add Homebrew-Cask to load path
|
# add Homebrew-Cask to load path
|
||||||
$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
|
$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.join("cask", "lib").to_s)
|
||||||
|
|
||||||
require "test/support/helper/env"
|
|
||||||
require "test/support/helper/shutup"
|
require "test/support/helper/shutup"
|
||||||
include Test::Helper::Env
|
|
||||||
include Test::Helper::Shutup
|
include Test::Helper::Shutup
|
||||||
|
|
||||||
def sudo(*args)
|
def sudo(*args)
|
||||||
|
|||||||
@ -34,6 +34,7 @@ module Homebrew
|
|||||||
%w[AUTHOR COMMITTER].each do |role|
|
%w[AUTHOR COMMITTER].each do |role|
|
||||||
ENV["GIT_#{role}_NAME"] = "brew tests"
|
ENV["GIT_#{role}_NAME"] = "brew tests"
|
||||||
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost"
|
||||||
|
ENV["GIT_#{role}_DATE"] = "Sun Jan 22 19:59:13 2017 +0000"
|
||||||
end
|
end
|
||||||
|
|
||||||
Homebrew.install_gem_setup_path! "bundler"
|
Homebrew.install_gem_setup_path! "bundler"
|
||||||
|
|||||||
@ -243,7 +243,7 @@ class FormulaAuditorTests < Homebrew::TestCase
|
|||||||
needs_compat
|
needs_compat
|
||||||
require "compat/formula_specialties"
|
require "compat/formula_specialties"
|
||||||
|
|
||||||
ARGV.stubs(:homebrew_developer?).returns false
|
ENV.delete("HOMEBREW_DEVELOPER")
|
||||||
fa = shutup do
|
fa = shutup do
|
||||||
formula_auditor "foo", <<-EOS.undent
|
formula_auditor "foo", <<-EOS.undent
|
||||||
class Foo < GithubGistFormula
|
class Foo < GithubGistFormula
|
||||||
@ -260,7 +260,7 @@ class FormulaAuditorTests < Homebrew::TestCase
|
|||||||
needs_compat
|
needs_compat
|
||||||
require "compat/formula_specialties"
|
require "compat/formula_specialties"
|
||||||
|
|
||||||
ARGV.stubs(:homebrew_developer?).returns false
|
ENV.delete("HOMEBREW_DEVELOPER")
|
||||||
fa = formula_auditor "foo", <<-EOS.undent
|
fa = formula_auditor "foo", <<-EOS.undent
|
||||||
class Foo < ScriptFileFormula
|
class Foo < ScriptFileFormula
|
||||||
url "http://example.com/foo-1.0.tgz"
|
url "http://example.com/foo-1.0.tgz"
|
||||||
@ -275,7 +275,7 @@ class FormulaAuditorTests < Homebrew::TestCase
|
|||||||
needs_compat
|
needs_compat
|
||||||
require "compat/formula_specialties"
|
require "compat/formula_specialties"
|
||||||
|
|
||||||
ARGV.stubs(:homebrew_developer?).returns false
|
ENV.delete("HOMEBREW_DEVELOPER")
|
||||||
fa = formula_auditor "foo", <<-EOS.undent
|
fa = formula_auditor "foo", <<-EOS.undent
|
||||||
class Foo < AmazonWebServicesFormula
|
class Foo < AmazonWebServicesFormula
|
||||||
url "http://example.com/foo-1.0.tgz"
|
url "http://example.com/foo-1.0.tgz"
|
||||||
@ -361,13 +361,10 @@ class FormulaAuditorTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
original_value = ENV["HOMEBREW_NO_GITHUB_API"]
|
|
||||||
ENV["HOMEBREW_NO_GITHUB_API"] = "1"
|
ENV["HOMEBREW_NO_GITHUB_API"] = "1"
|
||||||
|
|
||||||
fa.audit_github_repository
|
fa.audit_github_repository
|
||||||
assert_equal [], fa.problems
|
assert_equal [], fa.problems
|
||||||
ensure
|
|
||||||
ENV["HOMEBREW_NO_GITHUB_API"] = original_value
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_audit_caveats
|
def test_audit_caveats
|
||||||
|
|||||||
@ -47,8 +47,6 @@ class CommandsTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_external_commands
|
def test_external_commands
|
||||||
env = ENV.to_hash
|
|
||||||
|
|
||||||
mktmpdir do |dir|
|
mktmpdir do |dir|
|
||||||
%w[brew-t1 brew-t2.rb brew-t3.py].each do |file|
|
%w[brew-t1 brew-t2.rb brew-t3.py].each do |file|
|
||||||
path = "#{dir}/#{file}"
|
path = "#{dir}/#{file}"
|
||||||
@ -67,8 +65,6 @@ class CommandsTests < Homebrew::TestCase
|
|||||||
"Executable files with a non Ruby extension shoudn't be included"
|
"Executable files with a non Ruby extension shoudn't be included"
|
||||||
refute cmds.include?("t4"), "Non-executable files shouldn't be included"
|
refute cmds.include?("t4"), "Non-executable files shouldn't be included"
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
ENV.replace(env)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_internal_command_path
|
def test_internal_command_path
|
||||||
|
|||||||
@ -6,15 +6,9 @@ require "diagnostic"
|
|||||||
class DiagnosticChecksTest < Homebrew::TestCase
|
class DiagnosticChecksTest < Homebrew::TestCase
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@env = ENV.to_hash
|
|
||||||
@checks = Homebrew::Diagnostic::Checks.new
|
@checks = Homebrew::Diagnostic::Checks.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
|
||||||
ENV.replace(@env)
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_inject_file_list
|
def test_inject_file_list
|
||||||
assert_equal "foo:\n",
|
assert_equal "foo:\n",
|
||||||
@checks.inject_file_list([], "foo:\n")
|
@checks.inject_file_list([], "foo:\n")
|
||||||
|
|||||||
@ -157,28 +157,14 @@ class GitDownloadStrategyTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
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
|
def setup_git_repo
|
||||||
using_git_env do
|
@cached_location.cd do
|
||||||
@cached_location.cd do
|
shutup do
|
||||||
shutup do
|
system "git", "init"
|
||||||
system "git", "init"
|
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
|
||||||
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
|
|
||||||
end
|
|
||||||
touch "README"
|
|
||||||
git_commit_all
|
|
||||||
end
|
end
|
||||||
|
touch "README"
|
||||||
|
git_commit_all
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -192,18 +178,16 @@ class GitDownloadStrategyTests < Homebrew::TestCase
|
|||||||
|
|
||||||
def test_source_modified_time
|
def test_source_modified_time
|
||||||
setup_git_repo
|
setup_git_repo
|
||||||
assert_equal 1_242_860_651, @strategy.source_modified_time.to_i
|
assert_equal 1_485_115_153, @strategy.source_modified_time.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_last_commit
|
def test_last_commit
|
||||||
setup_git_repo
|
setup_git_repo
|
||||||
using_git_env do
|
@cached_location.cd do
|
||||||
@cached_location.cd do
|
touch "LICENSE"
|
||||||
touch "LICENSE"
|
git_commit_all
|
||||||
git_commit_all
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
assert_equal "c50c79b", @strategy.last_commit
|
assert_equal "f68266e", @strategy.last_commit
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fetch_last_commit
|
def test_fetch_last_commit
|
||||||
@ -214,21 +198,19 @@ class GitDownloadStrategyTests < Homebrew::TestCase
|
|||||||
resource.instance_variable_set(:@version, Version.create("HEAD"))
|
resource.instance_variable_set(:@version, Version.create("HEAD"))
|
||||||
@strategy = GitDownloadStrategy.new("baz", resource)
|
@strategy = GitDownloadStrategy.new("baz", resource)
|
||||||
|
|
||||||
using_git_env do
|
remote_repo.cd do
|
||||||
remote_repo.cd do
|
shutup do
|
||||||
shutup do
|
system "git", "init"
|
||||||
system "git", "init"
|
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
|
||||||
system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo"
|
|
||||||
end
|
|
||||||
touch "README"
|
|
||||||
git_commit_all
|
|
||||||
touch "LICENSE"
|
|
||||||
git_commit_all
|
|
||||||
end
|
end
|
||||||
|
touch "README"
|
||||||
|
git_commit_all
|
||||||
|
touch "LICENSE"
|
||||||
|
git_commit_all
|
||||||
end
|
end
|
||||||
|
|
||||||
@strategy.shutup!
|
@strategy.shutup!
|
||||||
assert_equal "c50c79b", @strategy.fetch_last_commit
|
assert_equal "f68266e", @strategy.fetch_last_commit
|
||||||
ensure
|
ensure
|
||||||
remote_repo.rmtree if remote_repo.directory?
|
remote_repo.rmtree if remote_repo.directory?
|
||||||
end
|
end
|
||||||
|
|||||||
@ -526,8 +526,6 @@ class FormulaTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_update_head_version
|
def test_update_head_version
|
||||||
initial_env = ENV.to_hash
|
|
||||||
|
|
||||||
f = formula do
|
f = formula do
|
||||||
head "foo", using: :git
|
head "foo", using: :git
|
||||||
end
|
end
|
||||||
@ -535,12 +533,6 @@ class FormulaTests < Homebrew::TestCase
|
|||||||
cached_location = f.head.downloader.cached_location
|
cached_location = f.head.downloader.cached_location
|
||||||
cached_location.mkpath
|
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
|
cached_location.cd do
|
||||||
FileUtils.touch "LICENSE"
|
FileUtils.touch "LICENSE"
|
||||||
shutup do
|
shutup do
|
||||||
@ -552,8 +544,6 @@ class FormulaTests < Homebrew::TestCase
|
|||||||
|
|
||||||
f.update_head_version
|
f.update_head_version
|
||||||
assert_equal Version.create("HEAD-5658946"), f.head.version
|
assert_equal Version.create("HEAD-5658946"), f.head.version
|
||||||
ensure
|
|
||||||
ENV.replace(initial_env)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_legacy_options
|
def test_legacy_options
|
||||||
@ -1098,13 +1088,12 @@ class OutdatedVersionsTests < Homebrew::TestCase
|
|||||||
outdated_stable_prefix = HOMEBREW_CELLAR.join("testball/1.0")
|
outdated_stable_prefix = HOMEBREW_CELLAR.join("testball/1.0")
|
||||||
head_prefix_a = HOMEBREW_CELLAR.join("testball/HEAD")
|
head_prefix_a = HOMEBREW_CELLAR.join("testball/HEAD")
|
||||||
head_prefix_b = HOMEBREW_CELLAR.join("testball/HEAD-aaaaaaa_1")
|
head_prefix_b = HOMEBREW_CELLAR.join("testball/HEAD-aaaaaaa_1")
|
||||||
head_prefix_c = HOMEBREW_CELLAR.join("testball/HEAD-5658946")
|
head_prefix_c = HOMEBREW_CELLAR.join("testball/HEAD-18a7103")
|
||||||
|
|
||||||
setup_tab_for_prefix(outdated_stable_prefix)
|
setup_tab_for_prefix(outdated_stable_prefix)
|
||||||
tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
|
tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" })
|
||||||
setup_tab_for_prefix(head_prefix_b)
|
setup_tab_for_prefix(head_prefix_b)
|
||||||
|
|
||||||
initial_env = ENV.to_hash
|
|
||||||
testball_repo = HOMEBREW_PREFIX.join("testball_repo")
|
testball_repo = HOMEBREW_PREFIX.join("testball_repo")
|
||||||
testball_repo.mkdir
|
testball_repo.mkdir
|
||||||
|
|
||||||
@ -1114,12 +1103,6 @@ class OutdatedVersionsTests < Homebrew::TestCase
|
|||||||
head "file://#{testball_repo}", using: :git
|
head "file://#{testball_repo}", using: :git
|
||||||
end
|
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
|
testball_repo.cd do
|
||||||
FileUtils.touch "LICENSE"
|
FileUtils.touch "LICENSE"
|
||||||
shutup do
|
shutup do
|
||||||
@ -1144,7 +1127,6 @@ class OutdatedVersionsTests < Homebrew::TestCase
|
|||||||
reset_outdated_kegs
|
reset_outdated_kegs
|
||||||
assert_predicate f.outdated_kegs(fetch_head: true), :empty?
|
assert_predicate f.outdated_kegs(fetch_head: true), :empty?
|
||||||
ensure
|
ensure
|
||||||
ENV.replace(initial_env)
|
|
||||||
testball_repo.rmtree if testball_repo.exist?
|
testball_repo.rmtree if testball_repo.exist?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,7 @@ class GPG2RequirementTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_satisfied
|
def test_satisfied
|
||||||
with_environment("PATH" => @dir/"bin") do
|
ENV["PATH"] = @dir/"bin"
|
||||||
assert_predicate GPG2Requirement.new, :satisfied?
|
assert_predicate GPG2Requirement.new, :satisfied?
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -10,10 +10,9 @@ class GpgTest < Homebrew::TestCase
|
|||||||
|
|
||||||
def test_create_test_key
|
def test_create_test_key
|
||||||
Dir.chdir(@dir) do
|
Dir.chdir(@dir) do
|
||||||
with_environment("HOME" => @dir) do
|
ENV["HOME"] = @dir
|
||||||
shutup { Gpg.create_test_key(@dir) }
|
shutup { Gpg.create_test_key(@dir) }
|
||||||
assert_predicate @dir/".gnupg/secring.gpg", :exist?
|
assert_predicate @dir/".gnupg/secring.gpg", :exist?
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -73,13 +73,6 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_install_head_installed
|
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 = HOMEBREW_CACHE.join("repo")
|
||||||
repo_path.join("bin").mkpath
|
repo_path.join("bin").mkpath
|
||||||
|
|
||||||
@ -105,14 +98,11 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase
|
|||||||
# Ignore dependencies, because we'll try to resolve requirements in build.rb
|
# Ignore dependencies, because we'll try to resolve requirements in build.rb
|
||||||
# and there will be the git requirement, but we cannot instantiate git
|
# and there will be the git requirement, but we cannot instantiate git
|
||||||
# formula since we only have testball1 formula.
|
# formula since we only have testball1 formula.
|
||||||
assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-2ccdf4f", cmd("install", "testball1", "--HEAD", "--ignore-dependencies")
|
assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689", cmd("install", "testball1", "--HEAD", "--ignore-dependencies")
|
||||||
assert_match "testball1-HEAD-2ccdf4f already installed",
|
assert_match "testball1-HEAD-d5eb689 already installed",
|
||||||
cmd("install", "testball1", "--HEAD", "--ignore-dependencies")
|
cmd("install", "testball1", "--HEAD", "--ignore-dependencies")
|
||||||
assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-2ccdf4f", cmd("unlink", "testball1")
|
assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689", cmd("unlink", "testball1")
|
||||||
assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1")
|
assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1")
|
||||||
|
|
||||||
ensure
|
|
||||||
ENV.replace(initial_env)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_install_with_invalid_option
|
def test_install_with_invalid_option
|
||||||
|
|||||||
@ -6,15 +6,9 @@ require "diagnostic"
|
|||||||
class OSMacDiagnosticChecksTest < Homebrew::TestCase
|
class OSMacDiagnosticChecksTest < Homebrew::TestCase
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@env = ENV.to_hash
|
|
||||||
@checks = Homebrew::Diagnostic::Checks.new
|
@checks = Homebrew::Diagnostic::Checks.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
|
||||||
ENV.replace(@env)
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_check_for_other_package_managers
|
def test_check_for_other_package_managers
|
||||||
MacOS.stubs(:macports_or_fink).returns ["fink"]
|
MacOS.stubs(:macports_or_fink).returns ["fink"]
|
||||||
assert_match "You have MacPorts or Fink installed:",
|
assert_match "You have MacPorts or Fink installed:",
|
||||||
@ -22,7 +16,7 @@ class OSMacDiagnosticChecksTest < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_check_for_unsupported_macos
|
def test_check_for_unsupported_macos
|
||||||
ARGV.stubs(:homebrew_developer?).returns false
|
ENV.delete("HOMEBREW_DEVELOPER")
|
||||||
OS::Mac.stubs(:prerelease?).returns true
|
OS::Mac.stubs(:prerelease?).returns true
|
||||||
assert_match "We do not provide support for this pre-release version.",
|
assert_match "We do not provide support for this pre-release version.",
|
||||||
@checks.check_for_unsupported_macos
|
@checks.check_for_unsupported_macos
|
||||||
|
|||||||
@ -15,11 +15,11 @@ class SandboxTest < Homebrew::TestCase
|
|||||||
f2 = formula { url "bar-1.0" }
|
f2 = formula { url "bar-1.0" }
|
||||||
f2.stubs(:tap).returns(Tap.fetch("test/tap"))
|
f2.stubs(:tap).returns(Tap.fetch("test/tap"))
|
||||||
|
|
||||||
ARGV.stubs(:sandbox?).returns true
|
ENV["HOMEBREW_SANDBOX"] = "1"
|
||||||
assert Sandbox.formula?(f),
|
assert Sandbox.formula?(f),
|
||||||
"Formulae should be sandboxed if --sandbox was passed."
|
"Formulae should be sandboxed if --sandbox was passed."
|
||||||
|
|
||||||
ARGV.stubs(:sandbox?).returns false
|
ENV.delete("HOMEBREW_SANDBOX")
|
||||||
assert Sandbox.formula?(f),
|
assert Sandbox.formula?(f),
|
||||||
"Formulae should be sandboxed if in a sandboxed tap."
|
"Formulae should be sandboxed if in a sandboxed tap."
|
||||||
refute Sandbox.formula?(f2),
|
refute Sandbox.formula?(f2),
|
||||||
@ -27,7 +27,7 @@ class SandboxTest < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_test?
|
def test_test?
|
||||||
ARGV.stubs(:no_sandbox?).returns false
|
ENV.delete("HOMEBREW_NO_SANDBOX")
|
||||||
assert Sandbox.test?,
|
assert Sandbox.test?,
|
||||||
"Tests should be sandboxed unless --no-sandbox was passed."
|
"Tests should be sandboxed unless --no-sandbox was passed."
|
||||||
end
|
end
|
||||||
@ -47,7 +47,7 @@ class SandboxTest < Homebrew::TestCase
|
|||||||
|
|
||||||
def test_complains_on_failure
|
def test_complains_on_failure
|
||||||
Utils.expects(popen_read: "foo")
|
Utils.expects(popen_read: "foo")
|
||||||
ARGV.stubs(verbose?: true)
|
ENV["HOMEBREW_VERBOSE"] = "1"
|
||||||
out, _err = capture_io do
|
out, _err = capture_io do
|
||||||
assert_raises(ErrorDuringExecution) { @sandbox.exec "false" }
|
assert_raises(ErrorDuringExecution) { @sandbox.exec "false" }
|
||||||
end
|
end
|
||||||
@ -61,7 +61,7 @@ class SandboxTest < Homebrew::TestCase
|
|||||||
bar
|
bar
|
||||||
EOS
|
EOS
|
||||||
Utils.expects(popen_read: with_bogus_error)
|
Utils.expects(popen_read: with_bogus_error)
|
||||||
ARGV.stubs(verbose?: true)
|
ENV["HOMEBREW_VERBOSE"] = "1"
|
||||||
out, _err = capture_io do
|
out, _err = capture_io do
|
||||||
assert_raises(ErrorDuringExecution) { @sandbox.exec "false" }
|
assert_raises(ErrorDuringExecution) { @sandbox.exec "false" }
|
||||||
end
|
end
|
||||||
|
|||||||
@ -37,7 +37,6 @@ class ShellSmokeTest < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def prepend_path_shell(shell, path, fragment)
|
def prepend_path_shell(shell, path, fragment)
|
||||||
original_shell = ENV["SHELL"]
|
|
||||||
ENV["SHELL"] = shell
|
ENV["SHELL"] = shell
|
||||||
|
|
||||||
prepend_message = Utils::Shell.prepend_path_in_shell_profile(path)
|
prepend_message = Utils::Shell.prepend_path_in_shell_profile(path)
|
||||||
@ -45,8 +44,6 @@ class ShellSmokeTest < Homebrew::TestCase
|
|||||||
prepend_message.start_with?(fragment),
|
prepend_message.start_with?(fragment),
|
||||||
"#{shell}: expected #{prepend_message} to match #{fragment}"
|
"#{shell}: expected #{prepend_message} to match #{fragment}"
|
||||||
)
|
)
|
||||||
|
|
||||||
ENV["SHELL"] = original_shell
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_prepend_path_in_shell_profile
|
def test_prepend_path_in_shell_profile
|
||||||
|
|||||||
@ -1,15 +0,0 @@
|
|||||||
module Test
|
|
||||||
module Helper
|
|
||||||
module Env
|
|
||||||
def with_environment(partial_env)
|
|
||||||
old = ENV.to_hash
|
|
||||||
ENV.update partial_env
|
|
||||||
begin
|
|
||||||
yield
|
|
||||||
ensure
|
|
||||||
ENV.replace old
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,11 +1,9 @@
|
|||||||
module Homebrew
|
module Homebrew
|
||||||
class TestCase < ::Minitest::Test
|
class TestCase < ::Minitest::Test
|
||||||
require "test/support/helper/env"
|
|
||||||
require "test/support/helper/fs_leak_logger"
|
require "test/support/helper/fs_leak_logger"
|
||||||
require "test/support/helper/lifecycle_enforcer"
|
require "test/support/helper/lifecycle_enforcer"
|
||||||
require "test/support/helper/shutup"
|
require "test/support/helper/shutup"
|
||||||
require "test/support/helper/version_assertions"
|
require "test/support/helper/version_assertions"
|
||||||
include Test::Helper::Env
|
|
||||||
include Test::Helper::FSLeakLogger
|
include Test::Helper::FSLeakLogger
|
||||||
include Test::Helper::LifecycleEnforcer
|
include Test::Helper::LifecycleEnforcer
|
||||||
include Test::Helper::Shutup
|
include Test::Helper::Shutup
|
||||||
@ -16,11 +14,14 @@ module Homebrew
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
|
|
||||||
@__argv = ARGV.dup
|
@__argv = ARGV.dup
|
||||||
|
@__env = ENV.to_hash # dup doesn't work on ENV
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
ARGV.replace(@__argv)
|
ARGV.replace(@__argv)
|
||||||
|
ENV.replace(@__env)
|
||||||
|
|
||||||
Tab.clear_cache
|
Tab.clear_cache
|
||||||
|
|
||||||
|
|||||||
@ -66,13 +66,6 @@ class TapTest < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def setup_git_repo
|
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
|
@path.cd do
|
||||||
shutup do
|
shutup do
|
||||||
system "git", "init"
|
system "git", "init"
|
||||||
@ -81,8 +74,6 @@ class TapTest < Homebrew::TestCase
|
|||||||
system "git", "commit", "-m", "init"
|
system "git", "commit", "-m", "init"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ensure
|
|
||||||
ENV.replace(env)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fetch
|
def test_fetch
|
||||||
@ -184,10 +175,10 @@ class TapTest < Homebrew::TestCase
|
|||||||
touch @path/"README"
|
touch @path/"README"
|
||||||
setup_git_repo
|
setup_git_repo
|
||||||
|
|
||||||
assert_equal "e1893a6bd191ba895c71b652ff8376a6114c7fa7", @tap.git_head
|
assert_equal "0453e16c8e3fac73104da50927a86221ca0740c2", @tap.git_head
|
||||||
assert_equal "e189", @tap.git_short_head
|
assert_equal "0453", @tap.git_short_head
|
||||||
assert_match "years ago", @tap.git_last_commit
|
assert_match(/\A\d+ .+ ago\Z/, @tap.git_last_commit)
|
||||||
assert_equal "2009-05-21", @tap.git_last_commit_date
|
assert_equal "2017-01-22", @tap.git_last_commit_date
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_private_remote
|
def test_private_remote
|
||||||
|
|||||||
@ -7,12 +7,6 @@ class UtilTests < Homebrew::TestCase
|
|||||||
def setup
|
def setup
|
||||||
super
|
super
|
||||||
@dir = Pathname.new(mktmpdir)
|
@dir = Pathname.new(mktmpdir)
|
||||||
@env = ENV.to_hash
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
ENV.replace @env
|
|
||||||
super
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_ofail
|
def test_ofail
|
||||||
@ -213,7 +207,7 @@ class UtilTests < Homebrew::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_odeprecated
|
def test_odeprecated
|
||||||
ARGV.stubs(:homebrew_developer?).returns false
|
ENV.delete("HOMEBREW_DEVELOPER")
|
||||||
e = assert_raises(MethodDeprecatedError) do
|
e = assert_raises(MethodDeprecatedError) do
|
||||||
odeprecated("method", "replacement",
|
odeprecated("method", "replacement",
|
||||||
caller: ["#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/"],
|
caller: ["#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/"],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user