tests: enforce super in lifecycle hooks

This will allow us to have global setup and teardown for tests.

For example, we can automatically clear caches after each test, to avoid
annoying intermittent failures like #1879 and #1886.
This commit is contained in:
Alyssa Ross 2017-01-21 11:21:30 +00:00
parent d7c463ad2c
commit 70a381a00f
51 changed files with 132 additions and 0 deletions

View File

@ -3,6 +3,7 @@ require "extend/ARGV"
class ArgvExtensionTests < Homebrew::TestCase class ArgvExtensionTests < Homebrew::TestCase
def setup def setup
super
@argv = [].extend(HomebrewArgvExtension) @argv = [].extend(HomebrewArgvExtension)
end end

View File

@ -31,6 +31,7 @@ end
module SharedEnvTests module SharedEnvTests
def setup def setup
super
@env = {}.extend(EnvActivation) @env = {}.extend(EnvActivation)
end end

View File

@ -6,11 +6,13 @@ require "dev-cmd/audit"
class FormulaTextTests < Homebrew::TestCase class FormulaTextTests < Homebrew::TestCase
def setup def setup
super
@dir = mktmpdir @dir = mktmpdir
end end
def teardown def teardown
FileUtils.rm_rf @dir FileUtils.rm_rf @dir
super
end end
def formula_text(name, body = nil, options = {}) def formula_text(name, body = nil, options = {})
@ -58,11 +60,13 @@ end
class FormulaAuditorTests < Homebrew::TestCase class FormulaAuditorTests < Homebrew::TestCase
def setup def setup
super
@dir = mktmpdir @dir = mktmpdir
end end
def teardown def teardown
FileUtils.rm_rf @dir FileUtils.rm_rf @dir
super
end end
def formula_auditor(name, text, options = {}) def formula_auditor(name, text, options = {})

View File

@ -3,6 +3,7 @@ require "utils/bottles"
class BottleCollectorTests < Homebrew::TestCase class BottleCollectorTests < Homebrew::TestCase
def setup def setup
super
@collector = Utils::Bottles::Collector.new @collector = Utils::Bottles::Collector.new
end end

View File

@ -17,6 +17,7 @@ class BottleHookTests < Homebrew::TestCase
end end
def setup def setup
super
@fi = FormulaInstaller.new FormulaDouble.new @fi = FormulaInstaller.new FormulaDouble.new
end end
@ -43,5 +44,6 @@ class BottleHookTests < Homebrew::TestCase
def teardown def teardown
Homebrew::Hooks::Bottles.reset_hooks Homebrew::Hooks::Bottles.reset_hooks
super
end end
end end

View File

@ -3,6 +3,7 @@ require "build_environment"
class BuildEnvironmentTests < Homebrew::TestCase class BuildEnvironmentTests < Homebrew::TestCase
def setup def setup
super
@env = BuildEnvironment.new @env = BuildEnvironment.new
end end

View File

@ -4,6 +4,7 @@ require "options"
class BuildOptionsTests < Homebrew::TestCase class BuildOptionsTests < Homebrew::TestCase
def setup def setup
super
args = Options.create(%w[--with-foo --with-bar --without-qux]) args = Options.create(%w[--with-foo --with-bar --without-qux])
opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux]) opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux])
@build = BuildOptions.new(args, opts) @build = BuildOptions.new(args, opts)

View File

@ -4,6 +4,7 @@ require "caveats"
class CaveatsTests < Homebrew::TestCase class CaveatsTests < Homebrew::TestCase
def setup def setup
super
@f = formula { url "foo-1.0" } @f = formula { url "foo-1.0" }
@c = Caveats.new @f @c = Caveats.new @f
end end

View File

@ -19,6 +19,7 @@ class ChecksumVerificationTests < Homebrew::TestCase
def teardown def teardown
@_f.clear_cache @_f.clear_cache
super
end end
def test_good_sha256 def test_good_sha256

View File

@ -6,12 +6,14 @@ class CleanerTests < Homebrew::TestCase
include FileUtils include FileUtils
def setup def setup
super
@f = formula("cleaner_test") { url "foo-1.0" } @f = formula("cleaner_test") { url "foo-1.0" }
@f.prefix.mkpath @f.prefix.mkpath
end end
def teardown def teardown
@f.rack.rmtree if @f.rack.exist? @f.rack.rmtree if @f.rack.exist?
super
end end
def test_clean_file def test_clean_file

View File

@ -14,6 +14,7 @@ end
class CleanupTests < Homebrew::TestCase class CleanupTests < Homebrew::TestCase
def setup def setup
super
@ds_store = Pathname.new "#{HOMEBREW_PREFIX}/Library/.DS_Store" @ds_store = Pathname.new "#{HOMEBREW_PREFIX}/Library/.DS_Store"
FileUtils.touch @ds_store FileUtils.touch @ds_store
end end
@ -22,6 +23,7 @@ class CleanupTests < Homebrew::TestCase
FileUtils.rm_f @ds_store FileUtils.rm_f @ds_store
ARGV.delete "--dry-run" ARGV.delete "--dry-run"
ARGV.delete "--prune=all" ARGV.delete "--prune=all"
super
end end
def test_cleanup def test_cleanup

View File

@ -13,6 +13,7 @@ end
class CommandsTests < Homebrew::TestCase class CommandsTests < Homebrew::TestCase
def setup def setup
super
@cmds = [ @cmds = [
# internal commands # internal commands
HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb",
@ -28,6 +29,7 @@ class CommandsTests < Homebrew::TestCase
def teardown def teardown
@cmds.each(&:unlink) @cmds.each(&:unlink)
super
end end
def test_internal_commands def test_internal_commands

View File

@ -31,6 +31,7 @@ class CompilerSelectorTests < Homebrew::TestCase
end end
def setup def setup
super
@f = Double.new @f = Double.new
@cc = :clang @cc = :clang
@versions = CompilerVersions.new @versions = CompilerVersions.new

View File

@ -5,6 +5,7 @@ require "requirements"
class DependenciesTests < Homebrew::TestCase class DependenciesTests < Homebrew::TestCase
def setup def setup
super
@deps = Dependencies.new @deps = Dependencies.new
end end
@ -89,6 +90,7 @@ end
class RequirementsTests < Homebrew::TestCase class RequirementsTests < Homebrew::TestCase
def setup def setup
super
@reqs = Requirements.new @reqs = Requirements.new
end end

View File

@ -11,11 +11,13 @@ class DependencyCollectorTests < Homebrew::TestCase
end end
def setup def setup
super
@d = DependencyCollector.new @d = DependencyCollector.new
end end
def teardown def teardown
DependencyCollector.clear_cache DependencyCollector.clear_cache
super
end end
def test_dependency_creation def test_dependency_creation

View File

@ -9,6 +9,7 @@ class DependencyExpansionTests < Homebrew::TestCase
end end
def setup def setup
super
@foo = build_dep(:foo) @foo = build_dep(:foo)
@bar = build_dep(:bar) @bar = build_dep(:bar)
@baz = build_dep(:baz) @baz = build_dep(:baz)

View File

@ -3,6 +3,7 @@ require "dependency"
class DependableTests < Homebrew::TestCase class DependableTests < Homebrew::TestCase
def setup def setup
super
@tags = ["foo", "bar", :build] @tags = ["foo", "bar", :build]
@dep = Struct.new(:tags).new(@tags).extend(Dependable) @dep = Struct.new(:tags).new(@tags).extend(Dependable)
end end

View File

@ -3,6 +3,8 @@ require "descriptions"
class DescriptionsTest < Homebrew::TestCase class DescriptionsTest < Homebrew::TestCase
def setup def setup
super
@descriptions_hash = {} @descriptions_hash = {}
@descriptions = Descriptions.new(@descriptions_hash) @descriptions = Descriptions.new(@descriptions_hash)
@ -12,6 +14,7 @@ class DescriptionsTest < Homebrew::TestCase
def teardown def teardown
$stdout = @old_stdout $stdout = @old_stdout
super
end end
def test_single_core_formula def test_single_core_formula

View File

@ -5,12 +5,14 @@ require "diagnostic"
class DiagnosticChecksTest < Homebrew::TestCase class DiagnosticChecksTest < Homebrew::TestCase
def setup def setup
super
@env = ENV.to_hash @env = ENV.to_hash
@checks = Homebrew::Diagnostic::Checks.new @checks = Homebrew::Diagnostic::Checks.new
end end
def teardown def teardown
ENV.replace(@env) ENV.replace(@env)
super
end end
def test_inject_file_list def test_inject_file_list

View File

@ -15,6 +15,7 @@ class AbstractDownloadStrategyTests < Homebrew::TestCase
include FileUtils include FileUtils
def setup def setup
super
@name = "foo" @name = "foo"
@resource = ResourceDouble.new @resource = ResourceDouble.new
@strategy = AbstractDownloadStrategy.new(@name, @resource) @strategy = AbstractDownloadStrategy.new(@name, @resource)
@ -63,6 +64,7 @@ end
class GitHubPrivateRepositoryDownloadStrategyTests < Homebrew::TestCase class GitHubPrivateRepositoryDownloadStrategyTests < Homebrew::TestCase
def setup def setup
super
resource = ResourceDouble.new("https://github.com/owner/repo/archive/1.1.5.tar.gz") resource = ResourceDouble.new("https://github.com/owner/repo/archive/1.1.5.tar.gz")
ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token" ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token"
GitHub.stubs(:repository).returns {} GitHub.stubs(:repository).returns {}
@ -87,6 +89,7 @@ end
class GitHubPrivateRepositoryReleaseDownloadStrategyTests < Homebrew::TestCase class GitHubPrivateRepositoryReleaseDownloadStrategyTests < Homebrew::TestCase
def setup def setup
super
resource = ResourceDouble.new("https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz") resource = ResourceDouble.new("https://github.com/owner/repo/releases/download/tag/foo_v0.1.0_darwin_amd64.tar.gz")
ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token" ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token"
GitHub.stubs(:repository).returns {} GitHub.stubs(:repository).returns {}
@ -138,6 +141,7 @@ class GitDownloadStrategyTests < Homebrew::TestCase
include FileUtils include FileUtils
def setup def setup
super
resource = ResourceDouble.new("https://github.com/homebrew/foo") resource = ResourceDouble.new("https://github.com/homebrew/foo")
@commit_id = 1 @commit_id = 1
@strategy = GitDownloadStrategy.new("baz", resource) @strategy = GitDownloadStrategy.new("baz", resource)
@ -147,6 +151,7 @@ class GitDownloadStrategyTests < Homebrew::TestCase
def teardown def teardown
rmtree @cached_location rmtree @cached_location
super
end end
def git_commit_all def git_commit_all
@ -236,6 +241,7 @@ end
class DownloadStrategyDetectorTests < Homebrew::TestCase class DownloadStrategyDetectorTests < Homebrew::TestCase
def setup def setup
super
@d = DownloadStrategyDetector.new @d = DownloadStrategyDetector.new
end end

View File

@ -3,6 +3,7 @@ require "formula_lock"
class FormulaLockTests < Homebrew::TestCase class FormulaLockTests < Homebrew::TestCase
def setup def setup
super
@lock = FormulaLock.new("foo") @lock = FormulaLock.new("foo")
@lock.lock @lock.lock
end end
@ -10,6 +11,7 @@ class FormulaLockTests < Homebrew::TestCase
def teardown def teardown
@lock.unlock @lock.unlock
HOMEBREW_LOCK_DIR.children.each(&:unlink) HOMEBREW_LOCK_DIR.children.each(&:unlink)
super
end end
def test_locking_file_with_existing_lock_raises_error def test_locking_file_with_existing_lock_raises_error

View File

@ -21,6 +21,7 @@ class FormulaPinTests < Homebrew::TestCase
end end
def setup def setup
super
@f = FormulaDouble.new @f = FormulaDouble.new
@pin = FormulaPin.new(@f) @pin = FormulaPin.new(@f)
@f.rack.mkpath @f.rack.mkpath
@ -50,5 +51,6 @@ class FormulaPinTests < Homebrew::TestCase
def teardown def teardown
@f.rack.rmtree @f.rack.rmtree
super
end end
end end

View File

@ -874,6 +874,8 @@ class AliasChangeTests < Homebrew::TestCase
end end
def setup def setup
super
alias_name = "bar" alias_name = "bar"
@alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}" @alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"
@ -942,6 +944,8 @@ class OutdatedVersionsTests < Homebrew::TestCase
attr_reader :f, :old_formula, :new_formula attr_reader :f, :old_formula, :new_formula
def setup def setup
super
@f = formula do @f = formula do
url "foo" url "foo"
version "1.20" version "1.20"
@ -960,6 +964,7 @@ class OutdatedVersionsTests < Homebrew::TestCase
def teardown def teardown
formulae = [@f, @old_formula, @new_formula] formulae = [@f, @old_formula, @new_formula]
formulae.map(&:rack).select(&:exist?).each(&:rmtree) formulae.map(&:rack).select(&:exist?).each(&:rmtree)
super
end end
def alias_path def alias_path

View File

@ -16,6 +16,7 @@ end
class FormularyFactoryTest < Homebrew::TestCase class FormularyFactoryTest < Homebrew::TestCase
def setup def setup
super
@name = "testball_bottle" @name = "testball_bottle"
@path = CoreTap.new.formula_dir/"#{@name}.rb" @path = CoreTap.new.formula_dir/"#{@name}.rb"
@bottle_dir = Pathname.new("#{TEST_FIXTURE_DIR}/bottles") @bottle_dir = Pathname.new("#{TEST_FIXTURE_DIR}/bottles")
@ -41,6 +42,7 @@ class FormularyFactoryTest < Homebrew::TestCase
def teardown def teardown
@path.unlink @path.unlink
super
end end
def test_factory def test_factory
@ -129,6 +131,7 @@ end
class FormularyTapFactoryTest < Homebrew::TestCase class FormularyTapFactoryTest < Homebrew::TestCase
def setup def setup
super
@name = "foo" @name = "foo"
@tap = Tap.new "homebrew", "foo" @tap = Tap.new "homebrew", "foo"
@path = @tap.path/"#{@name}.rb" @path = @tap.path/"#{@name}.rb"
@ -142,6 +145,7 @@ class FormularyTapFactoryTest < Homebrew::TestCase
def teardown def teardown
@tap.path.rmtree @tap.path.rmtree
super
end end
def test_factory_tap_formula def test_factory_tap_formula
@ -174,6 +178,7 @@ end
class FormularyTapPriorityTest < Homebrew::TestCase class FormularyTapPriorityTest < Homebrew::TestCase
def setup def setup
super
@name = "foo" @name = "foo"
@core_path = CoreTap.new.formula_dir/"#{@name}.rb" @core_path = CoreTap.new.formula_dir/"#{@name}.rb"
@tap = Tap.new "homebrew", "foo" @tap = Tap.new "homebrew", "foo"
@ -190,6 +195,7 @@ class FormularyTapPriorityTest < Homebrew::TestCase
def teardown def teardown
@core_path.unlink @core_path.unlink
@tap.path.rmtree @tap.path.rmtree
super
end end
def test_find_with_priority_core_formula def test_find_with_priority_core_formula

View File

@ -4,6 +4,7 @@ require "fileutils"
class GPG2RequirementTests < Homebrew::TestCase class GPG2RequirementTests < Homebrew::TestCase
def setup def setup
super
@dir = Pathname.new(mktmpdir) @dir = Pathname.new(mktmpdir)
(@dir/"bin/gpg").write <<-EOS.undent (@dir/"bin/gpg").write <<-EOS.undent
#!/bin/bash #!/bin/bash
@ -14,6 +15,7 @@ class GPG2RequirementTests < Homebrew::TestCase
def teardown def teardown
FileUtils.rm_rf @dir FileUtils.rm_rf @dir
super
end end
def test_satisfied def test_satisfied

View File

@ -3,6 +3,7 @@ require "gpg"
class GpgTest < Homebrew::TestCase class GpgTest < Homebrew::TestCase
def setup def setup
super
skip "GPG Unavailable" unless Gpg.available? skip "GPG Unavailable" unless Gpg.available?
@dir = Pathname.new(mktmpdir) @dir = Pathname.new(mktmpdir)
end end

View File

@ -20,6 +20,8 @@ class LinkTestCase < Homebrew::TestCase
end end
def setup def setup
super
@keg = setup_test_keg("foo", "1.0") @keg = setup_test_keg("foo", "1.0")
@dst = HOMEBREW_PREFIX.join("bin", "helloworld") @dst = HOMEBREW_PREFIX.join("bin", "helloworld")
@nonexistent = Pathname.new("/some/nonexistent/path") @nonexistent = Pathname.new("/some/nonexistent/path")
@ -43,6 +45,8 @@ class LinkTestCase < Homebrew::TestCase
rmtree HOMEBREW_PREFIX/"bin" rmtree HOMEBREW_PREFIX/"bin"
rmtree HOMEBREW_PREFIX/"lib" rmtree HOMEBREW_PREFIX/"lib"
super
end end
end end

View File

@ -4,6 +4,7 @@ require "resource"
class LanguagePythonTests < Homebrew::TestCase class LanguagePythonTests < Homebrew::TestCase
def setup def setup
super
@dir = Pathname.new(mktmpdir) @dir = Pathname.new(mktmpdir)
resource = stub("resource", stage: true) resource = stub("resource", stage: true)
formula_bin = @dir/"formula_bin" formula_bin = @dir/"formula_bin"
@ -16,6 +17,7 @@ class LanguagePythonTests < Homebrew::TestCase
def teardown def teardown
FileUtils.rm_rf @dir FileUtils.rm_rf @dir
super
end end
def test_virtualenv_creation def test_virtualenv_creation

View File

@ -10,6 +10,7 @@ end
class MigratorErrorsTests < Homebrew::TestCase class MigratorErrorsTests < Homebrew::TestCase
def setup def setup
super
@new_f = Testball.new("newname") @new_f = Testball.new("newname")
@new_f.oldname = "oldname" @new_f.oldname = "oldname"
@old_f = Testball.new("oldname") @old_f = Testball.new("oldname")
@ -40,6 +41,8 @@ class MigratorTests < Homebrew::TestCase
include FileUtils include FileUtils
def setup def setup
super
@new_f = Testball.new("newname") @new_f = Testball.new("newname")
@new_f.oldname = "oldname" @new_f.oldname = "oldname"
@ -93,6 +96,8 @@ class MigratorTests < Homebrew::TestCase
@new_f.unpin @new_f.unpin
HOMEBREW_LOCK_DIR.children.each(&:unlink) HOMEBREW_LOCK_DIR.children.each(&:unlink)
super
end end
def test_move_cellar def test_move_cellar

View File

@ -15,6 +15,7 @@ end
class OptionTests < Homebrew::TestCase class OptionTests < Homebrew::TestCase
def setup def setup
super
@option = Option.new("foo") @option = Option.new("foo")
end end
@ -43,6 +44,7 @@ end
class DeprecatedOptionTests < Homebrew::TestCase class DeprecatedOptionTests < Homebrew::TestCase
def setup def setup
super
@deprecated_option = DeprecatedOption.new("foo", "bar") @deprecated_option = DeprecatedOption.new("foo", "bar")
end end
@ -68,6 +70,7 @@ end
class OptionsTests < Homebrew::TestCase class OptionsTests < Homebrew::TestCase
def setup def setup
super
@options = Options.new @options = Options.new
end end

View File

@ -3,6 +3,7 @@ require "utils/bottles"
class OSMacBottleCollectorTests < Homebrew::TestCase class OSMacBottleCollectorTests < Homebrew::TestCase
def setup def setup
super
@collector = Utils::Bottles::Collector.new @collector = Utils::Bottles::Collector.new
end end

View File

@ -7,11 +7,13 @@ class OSMacDependencyCollectorTests < Homebrew::TestCase
end end
def setup def setup
super
@d = DependencyCollector.new @d = DependencyCollector.new
end end
def teardown def teardown
DependencyCollector.clear_cache DependencyCollector.clear_cache
super
end end
def test_tar_needs_xz_dependency def test_tar_needs_xz_dependency

View File

@ -5,12 +5,14 @@ require "diagnostic"
class OSMacDiagnosticChecksTest < Homebrew::TestCase class OSMacDiagnosticChecksTest < Homebrew::TestCase
def setup def setup
super
@env = ENV.to_hash @env = ENV.to_hash
@checks = Homebrew::Diagnostic::Checks.new @checks = Homebrew::Diagnostic::Checks.new
end end
def teardown def teardown
ENV.replace(@env) ENV.replace(@env)
super
end end
def test_check_for_other_package_managers def test_check_for_other_package_managers

View File

@ -6,6 +6,8 @@ class OSMacLinkTests < Homebrew::TestCase
include FileUtils include FileUtils
def setup def setup
super
keg = HOMEBREW_CELLAR.join("foo", "1.0") keg = HOMEBREW_CELLAR.join("foo", "1.0")
keg.join("bin").mkpath keg.join("bin").mkpath
@ -34,6 +36,8 @@ class OSMacLinkTests < Homebrew::TestCase
rmtree HOMEBREW_PREFIX/"bin" rmtree HOMEBREW_PREFIX/"bin"
rmtree HOMEBREW_PREFIX/"lib" rmtree HOMEBREW_PREFIX/"lib"
super
end end
def test_mach_o_files_skips_hardlinks def test_mach_o_files_skips_hardlinks

View File

@ -109,6 +109,7 @@ end
class ArchitectureListExtensionTests < MachOPathnameTests class ArchitectureListExtensionTests < MachOPathnameTests
def setup def setup
super
@archs = [:i386, :x86_64, :ppc7400, :ppc64].extend(ArchitectureListExtension) @archs = [:i386, :x86_64, :ppc7400, :ppc64].extend(ArchitectureListExtension)
end end
@ -157,11 +158,13 @@ class TextExecutableTests < Homebrew::TestCase
attr_reader :pn attr_reader :pn
def setup def setup
super
@pn = HOMEBREW_PREFIX.join("an_executable") @pn = HOMEBREW_PREFIX.join("an_executable")
end end
def teardown def teardown
HOMEBREW_PREFIX.join("an_executable").unlink HOMEBREW_PREFIX.join("an_executable").unlink
super
end end
def test_simple_shebang def test_simple_shebang

View File

@ -4,6 +4,7 @@ require "os/mac/version"
class OSMacVersionTests < Homebrew::TestCase class OSMacVersionTests < Homebrew::TestCase
def setup def setup
super
@v = MacOS::Version.new("10.7") @v = MacOS::Version.new("10.7")
end end

View File

@ -111,6 +111,7 @@ end
class ExternalPatchTests < Homebrew::TestCase class ExternalPatchTests < Homebrew::TestCase
def setup def setup
super
@p = ExternalPatch.new(:p1) { url "file:///my.patch" } @p = ExternalPatch.new(:p1) { url "file:///my.patch" }
end end

View File

@ -23,6 +23,7 @@ class PatchingTests < Homebrew::TestCase
def teardown def teardown
@_f.clear_cache @_f.clear_cache
@_f.patchlist.each { |p| p.clear_cache if p.external? } @_f.patchlist.each { |p| p.clear_cache if p.external? }
super
end end
def assert_patched(formula) def assert_patched(formula)

View File

@ -7,6 +7,7 @@ module PathnameTestExtension
include FileUtils include FileUtils
def setup def setup
super
@src = Pathname.new(mktmpdir) @src = Pathname.new(mktmpdir)
@dst = Pathname.new(mktmpdir) @dst = Pathname.new(mktmpdir)
@file = @src/"foo" @file = @src/"foo"
@ -16,6 +17,7 @@ module PathnameTestExtension
def teardown def teardown
rmtree(@src) rmtree(@src)
rmtree(@dst) rmtree(@dst)
super
end end
end end

View File

@ -3,6 +3,7 @@ require "resource"
class ResourceTests < Homebrew::TestCase class ResourceTests < Homebrew::TestCase
def setup def setup
super
@resource = Resource.new("test") @resource = Resource.new("test")
end end

View File

@ -3,6 +3,7 @@ require "sandbox"
class SandboxTest < Homebrew::TestCase class SandboxTest < Homebrew::TestCase
def setup def setup
super
skip "sandbox not implemented" unless Sandbox.available? skip "sandbox not implemented" unless Sandbox.available?
@sandbox = Sandbox.new @sandbox = Sandbox.new
@dir = Pathname.new(mktmpdir) @dir = Pathname.new(mktmpdir)
@ -11,6 +12,7 @@ class SandboxTest < Homebrew::TestCase
def teardown def teardown
@dir.rmtree @dir.rmtree
super
end end
def test_formula? def test_formula?

View File

@ -3,6 +3,7 @@ require "software_spec"
class SoftwareSpecTests < Homebrew::TestCase class SoftwareSpecTests < Homebrew::TestCase
def setup def setup
super
@spec = SoftwareSpec.new @spec = SoftwareSpec.new
end end
@ -136,6 +137,7 @@ end
class HeadSoftwareSpecTests < Homebrew::TestCase class HeadSoftwareSpecTests < Homebrew::TestCase
def setup def setup
super
@spec = HeadSoftwareSpec.new @spec = HeadSoftwareSpec.new
end end
@ -150,6 +152,7 @@ end
class BottleSpecificationTests < Homebrew::TestCase class BottleSpecificationTests < Homebrew::TestCase
def setup def setup
super
@spec = BottleSpecification.new @spec = BottleSpecification.new
end end

View File

@ -4,6 +4,7 @@ require "cxxstdlib"
class CxxStdlibTests < Homebrew::TestCase class CxxStdlibTests < Homebrew::TestCase
def setup def setup
super
@clang = CxxStdlib.create(:libstdcxx, :clang) @clang = CxxStdlib.create(:libstdcxx, :clang)
@gcc = CxxStdlib.create(:libstdcxx, :gcc) @gcc = CxxStdlib.create(:libstdcxx, :gcc)
@gcc40 = CxxStdlib.create(:libstdcxx, :gcc_4_0) @gcc40 = CxxStdlib.create(:libstdcxx, :gcc_4_0)

View File

@ -6,6 +6,7 @@ require "test/support/helper/test_case"
class IntegrationCommandTestCase < Homebrew::TestCase class IntegrationCommandTestCase < Homebrew::TestCase
def setup def setup
super
@cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`. @cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`.
(HOMEBREW_PREFIX/"bin").mkpath (HOMEBREW_PREFIX/"bin").mkpath
FileUtils.touch HOMEBREW_PREFIX/"bin/brew" FileUtils.touch HOMEBREW_PREFIX/"bin/brew"
@ -38,6 +39,7 @@ class IntegrationCommandTestCase < Homebrew::TestCase
coretap.path/"formula_renames.json", coretap.path/"formula_renames.json",
].flatten ].flatten
FileUtils.rm_rf paths_to_delete FileUtils.rm_rf paths_to_delete
super
end end
def needs_test_cmd_taps def needs_test_cmd_taps

View File

@ -0,0 +1,22 @@
module Test
module Helper
module LifecycleEnforcer
def setup
@__setup_called = true
super
end
def teardown
@__teardown_called = true
super
end
def after_teardown
assert @__setup_called, "Expected setup to call `super` but didn't"
assert @__teardown_called, "Expected teardown to call `super` but didn't"
super
end
end
end
end

View File

@ -2,10 +2,12 @@ module Homebrew
class TestCase < ::Minitest::Test class TestCase < ::Minitest::Test
require "test/support/helper/env" 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/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::Env
include Test::Helper::FSLeakLogger include Test::Helper::FSLeakLogger
include Test::Helper::LifecycleEnforcer
include Test::Helper::Shutup include Test::Helper::Shutup
include Test::Helper::VersionAssertions include Test::Helper::VersionAssertions

View File

@ -4,6 +4,8 @@ require "formula"
class TabTests < Homebrew::TestCase class TabTests < Homebrew::TestCase
def setup def setup
super
@used = Options.create(%w[--with-foo --without-bar]) @used = Options.create(%w[--with-foo --without-bar])
@unused = Options.create(%w[--with-baz --without-qux]) @unused = Options.create(%w[--with-baz --without-qux])
@ -260,6 +262,7 @@ end
class TabLoadingTests < Homebrew::TestCase class TabLoadingTests < Homebrew::TestCase
def setup def setup
super
@f = formula { url "foo-1.0" } @f = formula { url "foo-1.0" }
@f.prefix.mkpath @f.prefix.mkpath
@path = @f.prefix.join(Tab::FILENAME) @path = @f.prefix.join(Tab::FILENAME)
@ -268,6 +271,7 @@ class TabLoadingTests < Homebrew::TestCase
def teardown def teardown
@f.rack.rmtree @f.rack.rmtree
super
end end
def test_for_keg def test_for_keg

View File

@ -34,6 +34,7 @@ class TapTest < Homebrew::TestCase
include FileUtils include FileUtils
def setup def setup
super
@path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo"
@path.mkpath @path.mkpath
@tap = Tap.new("Homebrew", "foo") @tap = Tap.new("Homebrew", "foo")
@ -86,6 +87,7 @@ class TapTest < Homebrew::TestCase
def teardown def teardown
@path.rmtree @path.rmtree
super
end end
def test_fetch def test_fetch
@ -285,6 +287,7 @@ class CoreTapTest < Homebrew::TestCase
include FileUtils include FileUtils
def setup def setup
super
@repo = CoreTap.new @repo = CoreTap.new
end end

View File

@ -3,6 +3,8 @@ require "cmd/uninstall"
class UninstallTests < Homebrew::TestCase class UninstallTests < Homebrew::TestCase
def setup def setup
super
@dependency = formula("dependency") { url "f-1" } @dependency = formula("dependency") { url "f-1" }
@dependent = formula("dependent") do @dependent = formula("dependent") do
url "f-1" url "f-1"
@ -32,6 +34,7 @@ class UninstallTests < Homebrew::TestCase
f.installed_kegs.each(&:remove_opt_record) f.installed_kegs.each(&:remove_opt_record)
f.rack.rmtree f.rack.rmtree
end end
super
end end
def handle_unsatisfied_dependents def handle_unsatisfied_dependents

View File

@ -24,6 +24,7 @@ class ReportTests < Homebrew::TestCase
end end
def setup def setup
super
@tap = CoreTap.new @tap = CoreTap.new
@reporter = ReporterMock.new(@tap) @reporter = ReporterMock.new(@tap)
@hub = ReporterHub.new @hub = ReporterHub.new

View File

@ -5,6 +5,7 @@ require "utils/shell"
class UtilTests < Homebrew::TestCase class UtilTests < Homebrew::TestCase
def setup def setup
super
@dir = Pathname.new(mktmpdir) @dir = Pathname.new(mktmpdir)
@env = ENV.to_hash @env = ENV.to_hash
end end
@ -12,6 +13,7 @@ class UtilTests < Homebrew::TestCase
def teardown def teardown
@dir.rmtree @dir.rmtree
ENV.replace @env ENV.replace @env
super
end end
def test_ofail def test_ofail