Separate Homebrew::TestCase from testing_env.
This commit is contained in:
parent
7b9fd538fa
commit
9d82acbf30
@ -90,7 +90,7 @@ Style/ClassVars:
|
|||||||
Exclude:
|
Exclude:
|
||||||
- 'dev-cmd/audit.rb'
|
- 'dev-cmd/audit.rb'
|
||||||
- 'formula_installer.rb'
|
- 'formula_installer.rb'
|
||||||
- 'test/testing_env.rb'
|
- 'test/support/helper/fs_leak_logger.rb'
|
||||||
|
|
||||||
# Offense count: 13
|
# Offense count: 13
|
||||||
# Configuration parameters: AllowedVariables.
|
# Configuration parameters: AllowedVariables.
|
||||||
|
|||||||
27
Library/Homebrew/test/support/helper/fs_leak_logger.rb
Normal file
27
Library/Homebrew/test/support/helper/fs_leak_logger.rb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
module Test
|
||||||
|
module Helper
|
||||||
|
module FSLeakLogger
|
||||||
|
def self.included(klass)
|
||||||
|
require "find"
|
||||||
|
logdir = HOMEBREW_LIBRARY_PATH.join("tmp")
|
||||||
|
logdir.mkdir unless logdir.directory?
|
||||||
|
@@log = File.open(logdir.join("fs_leak.log"), "w")
|
||||||
|
klass.make_my_diffs_pretty!
|
||||||
|
end
|
||||||
|
|
||||||
|
def before_setup
|
||||||
|
@__files_before_test = []
|
||||||
|
Find.find(TEST_TMPDIR) { |f| @__files_before_test << f.sub(TEST_TMPDIR, "") }
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def after_teardown
|
||||||
|
super
|
||||||
|
files_after_test = []
|
||||||
|
Find.find(TEST_TMPDIR) { |f| files_after_test << f.sub(TEST_TMPDIR, "") }
|
||||||
|
return if @__files_before_test == files_after_test
|
||||||
|
@@log.puts location, diff(@__files_before_test, files_after_test)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
64
Library/Homebrew/test/support/helper/test_case.rb
Normal file
64
Library/Homebrew/test/support/helper/test_case.rb
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
module Homebrew
|
||||||
|
class TestCase < ::Minitest::Test
|
||||||
|
require "test/support/helper/env"
|
||||||
|
require "test/support/helper/fs_leak_logger"
|
||||||
|
require "test/support/helper/shutup"
|
||||||
|
require "test/support/helper/version_assertions"
|
||||||
|
include Test::Helper::Env
|
||||||
|
include Test::Helper::FSLeakLogger
|
||||||
|
include Test::Helper::Shutup
|
||||||
|
include Test::Helper::VersionAssertions
|
||||||
|
|
||||||
|
TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
|
||||||
|
TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
|
||||||
|
|
||||||
|
def formula(name = "formula_name", path = Formulary.core_path(name), spec = :stable, alias_path: nil, &block)
|
||||||
|
@_f = Class.new(Formula, &block).new(name, path, spec, alias_path: alias_path)
|
||||||
|
end
|
||||||
|
|
||||||
|
def mktmpdir(prefix_suffix = nil, &block)
|
||||||
|
Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def needs_compat
|
||||||
|
skip "Requires compat/ code" if ENV["HOMEBREW_NO_COMPAT"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def needs_python
|
||||||
|
skip "Requires Python" unless which("python")
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_nothing_raised
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_eql(exp, act, msg = nil)
|
||||||
|
msg = message(msg, "") { diff exp, act }
|
||||||
|
assert exp.eql?(act), msg
|
||||||
|
end
|
||||||
|
|
||||||
|
def refute_eql(exp, act, msg = nil)
|
||||||
|
msg = message(msg) do
|
||||||
|
"Expected #{mu_pp(act)} to not be eql to #{mu_pp(exp)}"
|
||||||
|
end
|
||||||
|
refute exp.eql?(act), msg
|
||||||
|
end
|
||||||
|
|
||||||
|
def dylib_path(name)
|
||||||
|
Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.dylib")
|
||||||
|
end
|
||||||
|
|
||||||
|
def bundle_path(name)
|
||||||
|
Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.bundle")
|
||||||
|
end
|
||||||
|
|
||||||
|
# Use a stubbed {Formulary::FormulaLoader} to make a given formula be found
|
||||||
|
# when loading from {Formulary} with `ref`.
|
||||||
|
def stub_formula_loader(formula, ref = formula.full_name)
|
||||||
|
loader = mock
|
||||||
|
loader.stubs(:get_formula).returns(formula)
|
||||||
|
Formulary.stubs(:loader_for).with(ref, from: :keg).returns(loader)
|
||||||
|
Formulary.stubs(:loader_for).with(ref, from: nil).returns(loader)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
23
Library/Homebrew/test/support/helper/version_assertions.rb
Normal file
23
Library/Homebrew/test/support/helper/version_assertions.rb
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
require "rubygems"
|
||||||
|
|
||||||
|
module Test
|
||||||
|
module Helper
|
||||||
|
module VersionAssertions
|
||||||
|
def version(v)
|
||||||
|
Version.create(v)
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_version_equal(expected, actual)
|
||||||
|
assert_equal Version.create(expected), actual
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_version_detected(expected, url, specs = {})
|
||||||
|
assert_equal expected, Version.detect(url, specs).to_s
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_version_nil(url)
|
||||||
|
assert Version.parse(url).null?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -10,7 +10,6 @@ require "formulary"
|
|||||||
%w[cache formula_cache locks cellar logs temp].each { |d| HOMEBREW_PREFIX.parent.join(d).mkpath }
|
%w[cache formula_cache locks cellar logs temp].each { |d| HOMEBREW_PREFIX.parent.join(d).mkpath }
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require "rubygems"
|
|
||||||
require "minitest/autorun"
|
require "minitest/autorun"
|
||||||
require "parallel_tests/test/runtime_logger"
|
require "parallel_tests/test/runtime_logger"
|
||||||
require "mocha/setup"
|
require "mocha/setup"
|
||||||
@ -18,108 +17,4 @@ rescue LoadError
|
|||||||
abort "Run `bundle install` or install the mocha and minitest gems before running the tests"
|
abort "Run `bundle install` or install the mocha and minitest gems before running the tests"
|
||||||
end
|
end
|
||||||
|
|
||||||
module Homebrew
|
require "test/support/helper/test_case"
|
||||||
module VersionAssertions
|
|
||||||
def version(v)
|
|
||||||
Version.create(v)
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_version_equal(expected, actual)
|
|
||||||
assert_equal Version.create(expected), actual
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_version_detected(expected, url, specs = {})
|
|
||||||
assert_equal expected, Version.detect(url, specs).to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_version_nil(url)
|
|
||||||
assert Version.parse(url).null?
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
module FSLeakLogger
|
|
||||||
def self.included(klass)
|
|
||||||
require "find"
|
|
||||||
logdir = HOMEBREW_LIBRARY_PATH.join("tmp")
|
|
||||||
logdir.mkdir unless logdir.directory?
|
|
||||||
@@log = File.open(logdir.join("fs_leak.log"), "w")
|
|
||||||
klass.make_my_diffs_pretty!
|
|
||||||
end
|
|
||||||
|
|
||||||
def before_setup
|
|
||||||
@__files_before_test = []
|
|
||||||
Find.find(TEST_TMPDIR) { |f| @__files_before_test << f.sub(TEST_TMPDIR, "") }
|
|
||||||
super
|
|
||||||
end
|
|
||||||
|
|
||||||
def after_teardown
|
|
||||||
super
|
|
||||||
files_after_test = []
|
|
||||||
Find.find(TEST_TMPDIR) { |f| files_after_test << f.sub(TEST_TMPDIR, "") }
|
|
||||||
return if @__files_before_test == files_after_test
|
|
||||||
@@log.puts location, diff(@__files_before_test, files_after_test)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
class TestCase < ::Minitest::Test
|
|
||||||
require "test/support/helper/env"
|
|
||||||
require "test/support/helper/shutup"
|
|
||||||
include Test::Helper::Env
|
|
||||||
include Test::Helper::Shutup
|
|
||||||
|
|
||||||
include VersionAssertions
|
|
||||||
include FSLeakLogger
|
|
||||||
|
|
||||||
TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
|
|
||||||
TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze
|
|
||||||
|
|
||||||
def formula(name = "formula_name", path = Formulary.core_path(name), spec = :stable, alias_path: nil, &block)
|
|
||||||
@_f = Class.new(Formula, &block).new(name, path, spec, alias_path: alias_path)
|
|
||||||
end
|
|
||||||
|
|
||||||
def mktmpdir(prefix_suffix = nil, &block)
|
|
||||||
Dir.mktmpdir(prefix_suffix, HOMEBREW_TEMP, &block)
|
|
||||||
end
|
|
||||||
|
|
||||||
def needs_compat
|
|
||||||
skip "Requires compat/ code" if ENV["HOMEBREW_NO_COMPAT"]
|
|
||||||
end
|
|
||||||
|
|
||||||
def needs_python
|
|
||||||
skip "Requires Python" unless which("python")
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_nothing_raised
|
|
||||||
yield
|
|
||||||
end
|
|
||||||
|
|
||||||
def assert_eql(exp, act, msg = nil)
|
|
||||||
msg = message(msg, "") { diff exp, act }
|
|
||||||
assert exp.eql?(act), msg
|
|
||||||
end
|
|
||||||
|
|
||||||
def refute_eql(exp, act, msg = nil)
|
|
||||||
msg = message(msg) do
|
|
||||||
"Expected #{mu_pp(act)} to not be eql to #{mu_pp(exp)}"
|
|
||||||
end
|
|
||||||
refute exp.eql?(act), msg
|
|
||||||
end
|
|
||||||
|
|
||||||
def dylib_path(name)
|
|
||||||
Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.dylib")
|
|
||||||
end
|
|
||||||
|
|
||||||
def bundle_path(name)
|
|
||||||
Pathname.new("#{TEST_FIXTURE_DIR}/mach/#{name}.bundle")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Use a stubbed {Formulary::FormulaLoader} to make a given formula be found
|
|
||||||
# when loading from {Formulary} with `ref`.
|
|
||||||
def stub_formula_loader(formula, ref = formula.full_name)
|
|
||||||
loader = mock
|
|
||||||
loader.stubs(:get_formula).returns(formula)
|
|
||||||
Formulary.stubs(:loader_for).with(ref, from: :keg).returns(loader)
|
|
||||||
Formulary.stubs(:loader_for).with(ref, from: nil).returns(loader)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user