From 70a381a00ff1e354e059aa07d55ebab90c5f874a Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sat, 21 Jan 2017 11:21:30 +0000 Subject: [PATCH] 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. --- Library/Homebrew/test/ARGV_test.rb | 1 + Library/Homebrew/test/ENV_test.rb | 1 + Library/Homebrew/test/audit_test.rb | 4 ++++ .../Homebrew/test/bottle_collector_test.rb | 1 + Library/Homebrew/test/bottle_hooks_test.rb | 2 ++ .../Homebrew/test/build_environment_test.rb | 1 + Library/Homebrew/test/build_options_test.rb | 1 + Library/Homebrew/test/caveats_test.rb | 1 + .../test/checksum_verification_test.rb | 1 + Library/Homebrew/test/cleaner_test.rb | 2 ++ Library/Homebrew/test/cleanup_test.rb | 2 ++ Library/Homebrew/test/commands_test.rb | 2 ++ .../Homebrew/test/compiler_selector_test.rb | 1 + Library/Homebrew/test/dependencies_test.rb | 2 ++ .../test/dependency_collector_test.rb | 2 ++ .../test/dependency_expansion_test.rb | 1 + Library/Homebrew/test/dependency_test.rb | 1 + Library/Homebrew/test/descriptions_test.rb | 3 +++ Library/Homebrew/test/diagnostic_test.rb | 2 ++ .../Homebrew/test/download_strategies_test.rb | 6 +++++ Library/Homebrew/test/formula_lock_test.rb | 2 ++ Library/Homebrew/test/formula_pin_test.rb | 2 ++ Library/Homebrew/test/formula_test.rb | 5 +++++ Library/Homebrew/test/formulary_test.rb | 6 +++++ .../Homebrew/test/gpg2_requirement_test.rb | 2 ++ Library/Homebrew/test/gpg_test.rb | 1 + Library/Homebrew/test/keg_test.rb | 4 ++++ Library/Homebrew/test/language_python_test.rb | 2 ++ Library/Homebrew/test/migrator_test.rb | 5 +++++ Library/Homebrew/test/options_test.rb | 3 +++ .../test/os/mac/bottle_collector_test.rb | 1 + .../test/os/mac/dependency_collector_test.rb | 2 ++ .../Homebrew/test/os/mac/diagnostic_test.rb | 2 ++ Library/Homebrew/test/os/mac/keg_test.rb | 4 ++++ Library/Homebrew/test/os/mac/mach_test.rb | 3 +++ Library/Homebrew/test/os/mac/version_test.rb | 1 + Library/Homebrew/test/patch_test.rb | 1 + Library/Homebrew/test/patching_test.rb | 1 + Library/Homebrew/test/pathname_test.rb | 2 ++ Library/Homebrew/test/resource_test.rb | 1 + Library/Homebrew/test/sandbox_test.rb | 2 ++ Library/Homebrew/test/software_spec_test.rb | 3 +++ Library/Homebrew/test/stdlib_test.rb | 1 + .../helper/integration_command_test_case.rb | 2 ++ .../test/support/helper/lifecycle_enforcer.rb | 22 +++++++++++++++++++ .../Homebrew/test/support/helper/test_case.rb | 2 ++ Library/Homebrew/test/tab_test.rb | 4 ++++ Library/Homebrew/test/tap_test.rb | 3 +++ Library/Homebrew/test/uninstall_test.rb | 3 +++ Library/Homebrew/test/update_report_test.rb | 1 + Library/Homebrew/test/utils_test.rb | 2 ++ 51 files changed, 132 insertions(+) create mode 100644 Library/Homebrew/test/support/helper/lifecycle_enforcer.rb diff --git a/Library/Homebrew/test/ARGV_test.rb b/Library/Homebrew/test/ARGV_test.rb index 6805e0c62054e..06660defc3503 100644 --- a/Library/Homebrew/test/ARGV_test.rb +++ b/Library/Homebrew/test/ARGV_test.rb @@ -3,6 +3,7 @@ class ArgvExtensionTests < Homebrew::TestCase def setup + super @argv = [].extend(HomebrewArgvExtension) end diff --git a/Library/Homebrew/test/ENV_test.rb b/Library/Homebrew/test/ENV_test.rb index dd60250842148..cbfd01e2512ba 100644 --- a/Library/Homebrew/test/ENV_test.rb +++ b/Library/Homebrew/test/ENV_test.rb @@ -31,6 +31,7 @@ def test_env_plain module SharedEnvTests def setup + super @env = {}.extend(EnvActivation) end diff --git a/Library/Homebrew/test/audit_test.rb b/Library/Homebrew/test/audit_test.rb index dace4dc2ba97b..0b13d3c2b2896 100644 --- a/Library/Homebrew/test/audit_test.rb +++ b/Library/Homebrew/test/audit_test.rb @@ -6,11 +6,13 @@ class FormulaTextTests < Homebrew::TestCase def setup + super @dir = mktmpdir end def teardown FileUtils.rm_rf @dir + super end def formula_text(name, body = nil, options = {}) @@ -58,11 +60,13 @@ def test_has_end class FormulaAuditorTests < Homebrew::TestCase def setup + super @dir = mktmpdir end def teardown FileUtils.rm_rf @dir + super end def formula_auditor(name, text, options = {}) diff --git a/Library/Homebrew/test/bottle_collector_test.rb b/Library/Homebrew/test/bottle_collector_test.rb index d75e29ec86097..5879da92c023b 100644 --- a/Library/Homebrew/test/bottle_collector_test.rb +++ b/Library/Homebrew/test/bottle_collector_test.rb @@ -3,6 +3,7 @@ class BottleCollectorTests < Homebrew::TestCase def setup + super @collector = Utils::Bottles::Collector.new end diff --git a/Library/Homebrew/test/bottle_hooks_test.rb b/Library/Homebrew/test/bottle_hooks_test.rb index 3535d80efd920..fd890192fbb3a 100644 --- a/Library/Homebrew/test/bottle_hooks_test.rb +++ b/Library/Homebrew/test/bottle_hooks_test.rb @@ -17,6 +17,7 @@ def some_random_method end def setup + super @fi = FormulaInstaller.new FormulaDouble.new end @@ -43,5 +44,6 @@ def test_pour_formula_bottle def teardown Homebrew::Hooks::Bottles.reset_hooks + super end end diff --git a/Library/Homebrew/test/build_environment_test.rb b/Library/Homebrew/test/build_environment_test.rb index 73a1c95f7358c..54b9cb2b178ae 100644 --- a/Library/Homebrew/test/build_environment_test.rb +++ b/Library/Homebrew/test/build_environment_test.rb @@ -3,6 +3,7 @@ class BuildEnvironmentTests < Homebrew::TestCase def setup + super @env = BuildEnvironment.new end diff --git a/Library/Homebrew/test/build_options_test.rb b/Library/Homebrew/test/build_options_test.rb index e460d25ccb644..05e7ccd9477dc 100644 --- a/Library/Homebrew/test/build_options_test.rb +++ b/Library/Homebrew/test/build_options_test.rb @@ -4,6 +4,7 @@ class BuildOptionsTests < Homebrew::TestCase def setup + super args = Options.create(%w[--with-foo --with-bar --without-qux]) opts = Options.create(%w[--with-foo --with-bar --without-baz --without-qux]) @build = BuildOptions.new(args, opts) diff --git a/Library/Homebrew/test/caveats_test.rb b/Library/Homebrew/test/caveats_test.rb index 9eaac5792707c..3a582b907fbb5 100644 --- a/Library/Homebrew/test/caveats_test.rb +++ b/Library/Homebrew/test/caveats_test.rb @@ -4,6 +4,7 @@ class CaveatsTests < Homebrew::TestCase def setup + super @f = formula { url "foo-1.0" } @c = Caveats.new @f end diff --git a/Library/Homebrew/test/checksum_verification_test.rb b/Library/Homebrew/test/checksum_verification_test.rb index 9017b528d01dc..ad7dfb46280ca 100644 --- a/Library/Homebrew/test/checksum_verification_test.rb +++ b/Library/Homebrew/test/checksum_verification_test.rb @@ -19,6 +19,7 @@ def formula(&block) def teardown @_f.clear_cache + super end def test_good_sha256 diff --git a/Library/Homebrew/test/cleaner_test.rb b/Library/Homebrew/test/cleaner_test.rb index ac108421c8bd1..413925dfa6fb8 100644 --- a/Library/Homebrew/test/cleaner_test.rb +++ b/Library/Homebrew/test/cleaner_test.rb @@ -6,12 +6,14 @@ class CleanerTests < Homebrew::TestCase include FileUtils def setup + super @f = formula("cleaner_test") { url "foo-1.0" } @f.prefix.mkpath end def teardown @f.rack.rmtree if @f.rack.exist? + super end def test_clean_file diff --git a/Library/Homebrew/test/cleanup_test.rb b/Library/Homebrew/test/cleanup_test.rb index bb8e1cdc612d6..e27439e0713ef 100644 --- a/Library/Homebrew/test/cleanup_test.rb +++ b/Library/Homebrew/test/cleanup_test.rb @@ -14,6 +14,7 @@ def test_cleanup class CleanupTests < Homebrew::TestCase def setup + super @ds_store = Pathname.new "#{HOMEBREW_PREFIX}/Library/.DS_Store" FileUtils.touch @ds_store end @@ -22,6 +23,7 @@ def teardown FileUtils.rm_f @ds_store ARGV.delete "--dry-run" ARGV.delete "--prune=all" + super end def test_cleanup diff --git a/Library/Homebrew/test/commands_test.rb b/Library/Homebrew/test/commands_test.rb index d44d2da0e7f0f..3d7c16e58fbe2 100644 --- a/Library/Homebrew/test/commands_test.rb +++ b/Library/Homebrew/test/commands_test.rb @@ -13,6 +13,7 @@ def test_commands class CommandsTests < Homebrew::TestCase def setup + super @cmds = [ # internal commands HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", @@ -28,6 +29,7 @@ def setup def teardown @cmds.each(&:unlink) + super end def test_internal_commands diff --git a/Library/Homebrew/test/compiler_selector_test.rb b/Library/Homebrew/test/compiler_selector_test.rb index b1591bdbec54c..aa1a6f97ec44e 100644 --- a/Library/Homebrew/test/compiler_selector_test.rb +++ b/Library/Homebrew/test/compiler_selector_test.rb @@ -31,6 +31,7 @@ def non_apple_gcc_version(name) end def setup + super @f = Double.new @cc = :clang @versions = CompilerVersions.new diff --git a/Library/Homebrew/test/dependencies_test.rb b/Library/Homebrew/test/dependencies_test.rb index db3b78226554f..c5444fcbcc0e0 100644 --- a/Library/Homebrew/test/dependencies_test.rb +++ b/Library/Homebrew/test/dependencies_test.rb @@ -5,6 +5,7 @@ class DependenciesTests < Homebrew::TestCase def setup + super @deps = Dependencies.new end @@ -89,6 +90,7 @@ def test_inspect class RequirementsTests < Homebrew::TestCase def setup + super @reqs = Requirements.new end diff --git a/Library/Homebrew/test/dependency_collector_test.rb b/Library/Homebrew/test/dependency_collector_test.rb index 1c7f70118b71e..c63d046370441 100644 --- a/Library/Homebrew/test/dependency_collector_test.rb +++ b/Library/Homebrew/test/dependency_collector_test.rb @@ -11,11 +11,13 @@ def find_requirement(klass) end def setup + super @d = DependencyCollector.new end def teardown DependencyCollector.clear_cache + super end def test_dependency_creation diff --git a/Library/Homebrew/test/dependency_expansion_test.rb b/Library/Homebrew/test/dependency_expansion_test.rb index 9d6de35e2fc69..de743ce0355e8 100644 --- a/Library/Homebrew/test/dependency_expansion_test.rb +++ b/Library/Homebrew/test/dependency_expansion_test.rb @@ -9,6 +9,7 @@ def build_dep(name, tags = [], deps = []) end def setup + super @foo = build_dep(:foo) @bar = build_dep(:bar) @baz = build_dep(:baz) diff --git a/Library/Homebrew/test/dependency_test.rb b/Library/Homebrew/test/dependency_test.rb index 134e91d1306ed..404f26d79c013 100644 --- a/Library/Homebrew/test/dependency_test.rb +++ b/Library/Homebrew/test/dependency_test.rb @@ -3,6 +3,7 @@ class DependableTests < Homebrew::TestCase def setup + super @tags = ["foo", "bar", :build] @dep = Struct.new(:tags).new(@tags).extend(Dependable) end diff --git a/Library/Homebrew/test/descriptions_test.rb b/Library/Homebrew/test/descriptions_test.rb index de38fdbd13163..baeeb7b1924cc 100644 --- a/Library/Homebrew/test/descriptions_test.rb +++ b/Library/Homebrew/test/descriptions_test.rb @@ -3,6 +3,8 @@ class DescriptionsTest < Homebrew::TestCase def setup + super + @descriptions_hash = {} @descriptions = Descriptions.new(@descriptions_hash) @@ -12,6 +14,7 @@ def setup def teardown $stdout = @old_stdout + super end def test_single_core_formula diff --git a/Library/Homebrew/test/diagnostic_test.rb b/Library/Homebrew/test/diagnostic_test.rb index c9bb524b0d7e8..608dda09930b9 100644 --- a/Library/Homebrew/test/diagnostic_test.rb +++ b/Library/Homebrew/test/diagnostic_test.rb @@ -5,12 +5,14 @@ class DiagnosticChecksTest < Homebrew::TestCase def setup + super @env = ENV.to_hash @checks = Homebrew::Diagnostic::Checks.new end def teardown ENV.replace(@env) + super end def test_inject_file_list diff --git a/Library/Homebrew/test/download_strategies_test.rb b/Library/Homebrew/test/download_strategies_test.rb index 2b64abbf95d99..fa69ec64ecb79 100644 --- a/Library/Homebrew/test/download_strategies_test.rb +++ b/Library/Homebrew/test/download_strategies_test.rb @@ -15,6 +15,7 @@ class AbstractDownloadStrategyTests < Homebrew::TestCase include FileUtils def setup + super @name = "foo" @resource = ResourceDouble.new @strategy = AbstractDownloadStrategy.new(@name, @resource) @@ -63,6 +64,7 @@ def cache_tag class GitHubPrivateRepositoryDownloadStrategyTests < Homebrew::TestCase def setup + super resource = ResourceDouble.new("https://github.com/owner/repo/archive/1.1.5.tar.gz") ENV["HOMEBREW_GITHUB_API_TOKEN"] = "token" GitHub.stubs(:repository).returns {} @@ -87,6 +89,7 @@ def test_download_url class GitHubPrivateRepositoryReleaseDownloadStrategyTests < Homebrew::TestCase def setup + super 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" GitHub.stubs(:repository).returns {} @@ -138,6 +141,7 @@ class GitDownloadStrategyTests < Homebrew::TestCase include FileUtils def setup + super resource = ResourceDouble.new("https://github.com/homebrew/foo") @commit_id = 1 @strategy = GitDownloadStrategy.new("baz", resource) @@ -147,6 +151,7 @@ def setup def teardown rmtree @cached_location + super end def git_commit_all @@ -236,6 +241,7 @@ def test_fetch_last_commit class DownloadStrategyDetectorTests < Homebrew::TestCase def setup + super @d = DownloadStrategyDetector.new end diff --git a/Library/Homebrew/test/formula_lock_test.rb b/Library/Homebrew/test/formula_lock_test.rb index 80ee9dd258bd3..d5bd0d07c5c3b 100644 --- a/Library/Homebrew/test/formula_lock_test.rb +++ b/Library/Homebrew/test/formula_lock_test.rb @@ -3,6 +3,7 @@ class FormulaLockTests < Homebrew::TestCase def setup + super @lock = FormulaLock.new("foo") @lock.lock end @@ -10,6 +11,7 @@ def setup def teardown @lock.unlock HOMEBREW_LOCK_DIR.children.each(&:unlink) + super end def test_locking_file_with_existing_lock_raises_error diff --git a/Library/Homebrew/test/formula_pin_test.rb b/Library/Homebrew/test/formula_pin_test.rb index 297d7703e3119..5dd2bd29e0199 100644 --- a/Library/Homebrew/test/formula_pin_test.rb +++ b/Library/Homebrew/test/formula_pin_test.rb @@ -21,6 +21,7 @@ def installed_kegs end def setup + super @f = FormulaDouble.new @pin = FormulaPin.new(@f) @f.rack.mkpath @@ -50,5 +51,6 @@ def test_unpin def teardown @f.rack.rmtree + super end end diff --git a/Library/Homebrew/test/formula_test.rb b/Library/Homebrew/test/formula_test.rb index 2d2136a05bd22..8293768fe0891 100644 --- a/Library/Homebrew/test/formula_test.rb +++ b/Library/Homebrew/test/formula_test.rb @@ -874,6 +874,8 @@ def make_formula(name, version) end def setup + super + alias_name = "bar" @alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}" @@ -942,6 +944,8 @@ class OutdatedVersionsTests < Homebrew::TestCase attr_reader :f, :old_formula, :new_formula def setup + super + @f = formula do url "foo" version "1.20" @@ -960,6 +964,7 @@ def setup def teardown formulae = [@f, @old_formula, @new_formula] formulae.map(&:rack).select(&:exist?).each(&:rmtree) + super end def alias_path diff --git a/Library/Homebrew/test/formulary_test.rb b/Library/Homebrew/test/formulary_test.rb index a306c43df996b..360c44a0dd791 100644 --- a/Library/Homebrew/test/formulary_test.rb +++ b/Library/Homebrew/test/formulary_test.rb @@ -16,6 +16,7 @@ def test_class_naming class FormularyFactoryTest < Homebrew::TestCase def setup + super @name = "testball_bottle" @path = CoreTap.new.formula_dir/"#{@name}.rb" @bottle_dir = Pathname.new("#{TEST_FIXTURE_DIR}/bottles") @@ -41,6 +42,7 @@ def install def teardown @path.unlink + super end def test_factory @@ -129,6 +131,7 @@ def test_to_rack class FormularyTapFactoryTest < Homebrew::TestCase def setup + super @name = "foo" @tap = Tap.new "homebrew", "foo" @path = @tap.path/"#{@name}.rb" @@ -142,6 +145,7 @@ class #{Formulary.class_s(@name)} < Formula def teardown @tap.path.rmtree + super end def test_factory_tap_formula @@ -174,6 +178,7 @@ def test_factory_ambiguity_tap_formulae class FormularyTapPriorityTest < Homebrew::TestCase def setup + super @name = "foo" @core_path = CoreTap.new.formula_dir/"#{@name}.rb" @tap = Tap.new "homebrew", "foo" @@ -190,6 +195,7 @@ class #{Formulary.class_s(@name)} < Formula def teardown @core_path.unlink @tap.path.rmtree + super end def test_find_with_priority_core_formula diff --git a/Library/Homebrew/test/gpg2_requirement_test.rb b/Library/Homebrew/test/gpg2_requirement_test.rb index fa7fc9ea41d33..b45798b420aab 100644 --- a/Library/Homebrew/test/gpg2_requirement_test.rb +++ b/Library/Homebrew/test/gpg2_requirement_test.rb @@ -4,6 +4,7 @@ class GPG2RequirementTests < Homebrew::TestCase def setup + super @dir = Pathname.new(mktmpdir) (@dir/"bin/gpg").write <<-EOS.undent #!/bin/bash @@ -14,6 +15,7 @@ def setup def teardown FileUtils.rm_rf @dir + super end def test_satisfied diff --git a/Library/Homebrew/test/gpg_test.rb b/Library/Homebrew/test/gpg_test.rb index 0374bdab4bd15..881468ad2738b 100644 --- a/Library/Homebrew/test/gpg_test.rb +++ b/Library/Homebrew/test/gpg_test.rb @@ -3,6 +3,7 @@ class GpgTest < Homebrew::TestCase def setup + super skip "GPG Unavailable" unless Gpg.available? @dir = Pathname.new(mktmpdir) end diff --git a/Library/Homebrew/test/keg_test.rb b/Library/Homebrew/test/keg_test.rb index 40b47b5e9d0cb..08bda4699ad84 100644 --- a/Library/Homebrew/test/keg_test.rb +++ b/Library/Homebrew/test/keg_test.rb @@ -20,6 +20,8 @@ def setup_test_keg(name, version) end def setup + super + @keg = setup_test_keg("foo", "1.0") @dst = HOMEBREW_PREFIX.join("bin", "helloworld") @nonexistent = Pathname.new("/some/nonexistent/path") @@ -43,6 +45,8 @@ def teardown rmtree HOMEBREW_PREFIX/"bin" rmtree HOMEBREW_PREFIX/"lib" + + super end end diff --git a/Library/Homebrew/test/language_python_test.rb b/Library/Homebrew/test/language_python_test.rb index d1e3867f735a1..0a6d1eeaaf82f 100644 --- a/Library/Homebrew/test/language_python_test.rb +++ b/Library/Homebrew/test/language_python_test.rb @@ -4,6 +4,7 @@ class LanguagePythonTests < Homebrew::TestCase def setup + super @dir = Pathname.new(mktmpdir) resource = stub("resource", stage: true) formula_bin = @dir/"formula_bin" @@ -16,6 +17,7 @@ def setup def teardown FileUtils.rm_rf @dir + super end def test_virtualenv_creation diff --git a/Library/Homebrew/test/migrator_test.rb b/Library/Homebrew/test/migrator_test.rb index 8a2b6ad63ea64..53151f3e32bf4 100644 --- a/Library/Homebrew/test/migrator_test.rb +++ b/Library/Homebrew/test/migrator_test.rb @@ -10,6 +10,7 @@ class Formula class MigratorErrorsTests < Homebrew::TestCase def setup + super @new_f = Testball.new("newname") @new_f.oldname = "oldname" @old_f = Testball.new("oldname") @@ -40,6 +41,8 @@ class MigratorTests < Homebrew::TestCase include FileUtils def setup + super + @new_f = Testball.new("newname") @new_f.oldname = "oldname" @@ -93,6 +96,8 @@ def teardown @new_f.unpin HOMEBREW_LOCK_DIR.children.each(&:unlink) + + super end def test_move_cellar diff --git a/Library/Homebrew/test/options_test.rb b/Library/Homebrew/test/options_test.rb index e7189a6042b15..f38ec441546e7 100644 --- a/Library/Homebrew/test/options_test.rb +++ b/Library/Homebrew/test/options_test.rb @@ -15,6 +15,7 @@ def test_options class OptionTests < Homebrew::TestCase def setup + super @option = Option.new("foo") end @@ -43,6 +44,7 @@ def test_inspect class DeprecatedOptionTests < Homebrew::TestCase def setup + super @deprecated_option = DeprecatedOption.new("foo", "bar") end @@ -68,6 +70,7 @@ def test_equality class OptionsTests < Homebrew::TestCase def setup + super @options = Options.new end diff --git a/Library/Homebrew/test/os/mac/bottle_collector_test.rb b/Library/Homebrew/test/os/mac/bottle_collector_test.rb index 2f88050aed647..e9ae9b7537567 100644 --- a/Library/Homebrew/test/os/mac/bottle_collector_test.rb +++ b/Library/Homebrew/test/os/mac/bottle_collector_test.rb @@ -3,6 +3,7 @@ class OSMacBottleCollectorTests < Homebrew::TestCase def setup + super @collector = Utils::Bottles::Collector.new end diff --git a/Library/Homebrew/test/os/mac/dependency_collector_test.rb b/Library/Homebrew/test/os/mac/dependency_collector_test.rb index 4fdf3ebe423af..1033df9ab57a7 100644 --- a/Library/Homebrew/test/os/mac/dependency_collector_test.rb +++ b/Library/Homebrew/test/os/mac/dependency_collector_test.rb @@ -7,11 +7,13 @@ def find_dependency(name) end def setup + super @d = DependencyCollector.new end def teardown DependencyCollector.clear_cache + super end def test_tar_needs_xz_dependency diff --git a/Library/Homebrew/test/os/mac/diagnostic_test.rb b/Library/Homebrew/test/os/mac/diagnostic_test.rb index 655aa1d46b5a6..284d293ca939c 100644 --- a/Library/Homebrew/test/os/mac/diagnostic_test.rb +++ b/Library/Homebrew/test/os/mac/diagnostic_test.rb @@ -5,12 +5,14 @@ class OSMacDiagnosticChecksTest < Homebrew::TestCase def setup + super @env = ENV.to_hash @checks = Homebrew::Diagnostic::Checks.new end def teardown ENV.replace(@env) + super end def test_check_for_other_package_managers diff --git a/Library/Homebrew/test/os/mac/keg_test.rb b/Library/Homebrew/test/os/mac/keg_test.rb index e79cbc9217cd8..5f215bd06fdd6 100644 --- a/Library/Homebrew/test/os/mac/keg_test.rb +++ b/Library/Homebrew/test/os/mac/keg_test.rb @@ -6,6 +6,8 @@ class OSMacLinkTests < Homebrew::TestCase include FileUtils def setup + super + keg = HOMEBREW_CELLAR.join("foo", "1.0") keg.join("bin").mkpath @@ -34,6 +36,8 @@ def teardown rmtree HOMEBREW_PREFIX/"bin" rmtree HOMEBREW_PREFIX/"lib" + + super end def test_mach_o_files_skips_hardlinks diff --git a/Library/Homebrew/test/os/mac/mach_test.rb b/Library/Homebrew/test/os/mac/mach_test.rb index a42f7316b15da..ed0424be6595f 100644 --- a/Library/Homebrew/test/os/mac/mach_test.rb +++ b/Library/Homebrew/test/os/mac/mach_test.rb @@ -109,6 +109,7 @@ def test_non_mach_o class ArchitectureListExtensionTests < MachOPathnameTests def setup + super @archs = [:i386, :x86_64, :ppc7400, :ppc64].extend(ArchitectureListExtension) end @@ -157,11 +158,13 @@ class TextExecutableTests < Homebrew::TestCase attr_reader :pn def setup + super @pn = HOMEBREW_PREFIX.join("an_executable") end def teardown HOMEBREW_PREFIX.join("an_executable").unlink + super end def test_simple_shebang diff --git a/Library/Homebrew/test/os/mac/version_test.rb b/Library/Homebrew/test/os/mac/version_test.rb index f702c7097a671..ba42176917a71 100644 --- a/Library/Homebrew/test/os/mac/version_test.rb +++ b/Library/Homebrew/test/os/mac/version_test.rb @@ -4,6 +4,7 @@ class OSMacVersionTests < Homebrew::TestCase def setup + super @v = MacOS::Version.new("10.7") end diff --git a/Library/Homebrew/test/patch_test.rb b/Library/Homebrew/test/patch_test.rb index 62624720e8467..f5a61398aa0ec 100644 --- a/Library/Homebrew/test/patch_test.rb +++ b/Library/Homebrew/test/patch_test.rb @@ -111,6 +111,7 @@ def test_inspect class ExternalPatchTests < Homebrew::TestCase def setup + super @p = ExternalPatch.new(:p1) { url "file:///my.patch" } end diff --git a/Library/Homebrew/test/patching_test.rb b/Library/Homebrew/test/patching_test.rb index ac14c8e1e7a15..eadab15dc13f0 100644 --- a/Library/Homebrew/test/patching_test.rb +++ b/Library/Homebrew/test/patching_test.rb @@ -23,6 +23,7 @@ def formula(*args, &block) def teardown @_f.clear_cache @_f.patchlist.each { |p| p.clear_cache if p.external? } + super end def assert_patched(formula) diff --git a/Library/Homebrew/test/pathname_test.rb b/Library/Homebrew/test/pathname_test.rb index 2f6360719b030..2f4002b0054f9 100644 --- a/Library/Homebrew/test/pathname_test.rb +++ b/Library/Homebrew/test/pathname_test.rb @@ -7,6 +7,7 @@ module PathnameTestExtension include FileUtils def setup + super @src = Pathname.new(mktmpdir) @dst = Pathname.new(mktmpdir) @file = @src/"foo" @@ -16,6 +17,7 @@ def setup def teardown rmtree(@src) rmtree(@dst) + super end end diff --git a/Library/Homebrew/test/resource_test.rb b/Library/Homebrew/test/resource_test.rb index c1b526cb2c11e..d982a7c3373f4 100644 --- a/Library/Homebrew/test/resource_test.rb +++ b/Library/Homebrew/test/resource_test.rb @@ -3,6 +3,7 @@ class ResourceTests < Homebrew::TestCase def setup + super @resource = Resource.new("test") end diff --git a/Library/Homebrew/test/sandbox_test.rb b/Library/Homebrew/test/sandbox_test.rb index 2a062cb10fa87..96558afa4e0e3 100644 --- a/Library/Homebrew/test/sandbox_test.rb +++ b/Library/Homebrew/test/sandbox_test.rb @@ -3,6 +3,7 @@ class SandboxTest < Homebrew::TestCase def setup + super skip "sandbox not implemented" unless Sandbox.available? @sandbox = Sandbox.new @dir = Pathname.new(mktmpdir) @@ -11,6 +12,7 @@ def setup def teardown @dir.rmtree + super end def test_formula? diff --git a/Library/Homebrew/test/software_spec_test.rb b/Library/Homebrew/test/software_spec_test.rb index d9226f8c34288..026265a4a1237 100644 --- a/Library/Homebrew/test/software_spec_test.rb +++ b/Library/Homebrew/test/software_spec_test.rb @@ -3,6 +3,7 @@ class SoftwareSpecTests < Homebrew::TestCase def setup + super @spec = SoftwareSpec.new end @@ -136,6 +137,7 @@ def test_patch class HeadSoftwareSpecTests < Homebrew::TestCase def setup + super @spec = HeadSoftwareSpec.new end @@ -150,6 +152,7 @@ def test_verify_download_integrity class BottleSpecificationTests < Homebrew::TestCase def setup + super @spec = BottleSpecification.new end diff --git a/Library/Homebrew/test/stdlib_test.rb b/Library/Homebrew/test/stdlib_test.rb index 3babfd58af005..f193ae71e996c 100644 --- a/Library/Homebrew/test/stdlib_test.rb +++ b/Library/Homebrew/test/stdlib_test.rb @@ -4,6 +4,7 @@ class CxxStdlibTests < Homebrew::TestCase def setup + super @clang = CxxStdlib.create(:libstdcxx, :clang) @gcc = CxxStdlib.create(:libstdcxx, :gcc) @gcc40 = CxxStdlib.create(:libstdcxx, :gcc_4_0) diff --git a/Library/Homebrew/test/support/helper/integration_command_test_case.rb b/Library/Homebrew/test/support/helper/integration_command_test_case.rb index 6879f2f812ba4..86184ac51e753 100644 --- a/Library/Homebrew/test/support/helper/integration_command_test_case.rb +++ b/Library/Homebrew/test/support/helper/integration_command_test_case.rb @@ -6,6 +6,7 @@ class IntegrationCommandTestCase < Homebrew::TestCase def setup + super @cmd_id_index = 0 # Assign unique IDs to invocations of `cmd_output`. (HOMEBREW_PREFIX/"bin").mkpath FileUtils.touch HOMEBREW_PREFIX/"bin/brew" @@ -38,6 +39,7 @@ def teardown coretap.path/"formula_renames.json", ].flatten FileUtils.rm_rf paths_to_delete + super end def needs_test_cmd_taps diff --git a/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb b/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb new file mode 100644 index 0000000000000..413f8b11e7a38 --- /dev/null +++ b/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb @@ -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 diff --git a/Library/Homebrew/test/support/helper/test_case.rb b/Library/Homebrew/test/support/helper/test_case.rb index 60c91e7bb3699..5becfeef19e03 100644 --- a/Library/Homebrew/test/support/helper/test_case.rb +++ b/Library/Homebrew/test/support/helper/test_case.rb @@ -2,10 +2,12 @@ module Homebrew class TestCase < ::Minitest::Test require "test/support/helper/env" require "test/support/helper/fs_leak_logger" + require "test/support/helper/lifecycle_enforcer" require "test/support/helper/shutup" require "test/support/helper/version_assertions" include Test::Helper::Env include Test::Helper::FSLeakLogger + include Test::Helper::LifecycleEnforcer include Test::Helper::Shutup include Test::Helper::VersionAssertions diff --git a/Library/Homebrew/test/tab_test.rb b/Library/Homebrew/test/tab_test.rb index f9824ba2a87e5..5a354a908b7fb 100644 --- a/Library/Homebrew/test/tab_test.rb +++ b/Library/Homebrew/test/tab_test.rb @@ -4,6 +4,8 @@ class TabTests < Homebrew::TestCase def setup + super + @used = Options.create(%w[--with-foo --without-bar]) @unused = Options.create(%w[--with-baz --without-qux]) @@ -260,6 +262,7 @@ def test_remap_deprecated_options class TabLoadingTests < Homebrew::TestCase def setup + super @f = formula { url "foo-1.0" } @f.prefix.mkpath @path = @f.prefix.join(Tab::FILENAME) @@ -268,6 +271,7 @@ def setup def teardown @f.rack.rmtree + super end def test_for_keg diff --git a/Library/Homebrew/test/tap_test.rb b/Library/Homebrew/test/tap_test.rb index 7114cdf2288e5..4990bc6df3a66 100644 --- a/Library/Homebrew/test/tap_test.rb +++ b/Library/Homebrew/test/tap_test.rb @@ -34,6 +34,7 @@ class TapTest < Homebrew::TestCase include FileUtils def setup + super @path = Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" @path.mkpath @tap = Tap.new("Homebrew", "foo") @@ -86,6 +87,7 @@ def setup_git_repo def teardown @path.rmtree + super end def test_fetch @@ -285,6 +287,7 @@ class CoreTapTest < Homebrew::TestCase include FileUtils def setup + super @repo = CoreTap.new end diff --git a/Library/Homebrew/test/uninstall_test.rb b/Library/Homebrew/test/uninstall_test.rb index 597e77e40d0e8..4ab2f985edd4b 100644 --- a/Library/Homebrew/test/uninstall_test.rb +++ b/Library/Homebrew/test/uninstall_test.rb @@ -3,6 +3,8 @@ class UninstallTests < Homebrew::TestCase def setup + super + @dependency = formula("dependency") { url "f-1" } @dependent = formula("dependent") do url "f-1" @@ -32,6 +34,7 @@ def teardown f.installed_kegs.each(&:remove_opt_record) f.rack.rmtree end + super end def handle_unsatisfied_dependents diff --git a/Library/Homebrew/test/update_report_test.rb b/Library/Homebrew/test/update_report_test.rb index 6b6cec6ce04ab..32c3e36d0ae68 100644 --- a/Library/Homebrew/test/update_report_test.rb +++ b/Library/Homebrew/test/update_report_test.rb @@ -24,6 +24,7 @@ def self.fixture_data end def setup + super @tap = CoreTap.new @reporter = ReporterMock.new(@tap) @hub = ReporterHub.new diff --git a/Library/Homebrew/test/utils_test.rb b/Library/Homebrew/test/utils_test.rb index d7c25683d7d95..310bfb135137f 100644 --- a/Library/Homebrew/test/utils_test.rb +++ b/Library/Homebrew/test/utils_test.rb @@ -5,6 +5,7 @@ class UtilTests < Homebrew::TestCase def setup + super @dir = Pathname.new(mktmpdir) @env = ENV.to_hash end @@ -12,6 +13,7 @@ def setup def teardown @dir.rmtree ENV.replace @env + super end def test_ofail