Skip to content

Commit

Permalink
Merge pull request #1888 from alyssais/tests_enforce_lifecycle
Browse files Browse the repository at this point in the history
tests: enforce `super` in lifecycle hooks
  • Loading branch information
alyssais authored Jan 21, 2017
2 parents d7c463a + 70a381a commit ab9d8df
Show file tree
Hide file tree
Showing 51 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions Library/Homebrew/test/ARGV_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class ArgvExtensionTests < Homebrew::TestCase
def setup
super
@argv = [].extend(HomebrewArgvExtension)
end

Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/ENV_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def test_env_plain

module SharedEnvTests
def setup
super
@env = {}.extend(EnvActivation)
end

Expand Down
4 changes: 4 additions & 0 deletions Library/Homebrew/test/audit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand Down Expand Up @@ -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 = {})
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/bottle_collector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class BottleCollectorTests < Homebrew::TestCase
def setup
super
@collector = Utils::Bottles::Collector.new
end

Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/bottle_hooks_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def some_random_method
end

def setup
super
@fi = FormulaInstaller.new FormulaDouble.new
end

Expand All @@ -43,5 +44,6 @@ def test_pour_formula_bottle

def teardown
Homebrew::Hooks::Bottles.reset_hooks
super
end
end
1 change: 1 addition & 0 deletions Library/Homebrew/test/build_environment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class BuildEnvironmentTests < Homebrew::TestCase
def setup
super
@env = BuildEnvironment.new
end

Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/build_options_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/caveats_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

class CaveatsTests < Homebrew::TestCase
def setup
super
@f = formula { url "foo-1.0" }
@c = Caveats.new @f
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/checksum_verification_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def formula(&block)

def teardown
@_f.clear_cache
super
end

def test_good_sha256
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/cleaner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/cleanup_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,7 @@ def teardown
FileUtils.rm_f @ds_store
ARGV.delete "--dry-run"
ARGV.delete "--prune=all"
super
end

def test_cleanup
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/commands_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def test_commands

class CommandsTests < Homebrew::TestCase
def setup
super
@cmds = [
# internal commands
HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb",
Expand All @@ -28,6 +29,7 @@ def setup

def teardown
@cmds.each(&:unlink)
super
end

def test_internal_commands
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/compiler_selector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def non_apple_gcc_version(name)
end

def setup
super
@f = Double.new
@cc = :clang
@versions = CompilerVersions.new
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/dependencies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

class DependenciesTests < Homebrew::TestCase
def setup
super
@deps = Dependencies.new
end

Expand Down Expand Up @@ -89,6 +90,7 @@ def test_inspect

class RequirementsTests < Homebrew::TestCase
def setup
super
@reqs = Requirements.new
end

Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/dependency_collector_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/dependency_expansion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/test/dependency_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class DependableTests < Homebrew::TestCase
def setup
super
@tags = ["foo", "bar", :build]
@dep = Struct.new(:tags).new(@tags).extend(Dependable)
end
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/test/descriptions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

class DescriptionsTest < Homebrew::TestCase
def setup
super

@descriptions_hash = {}
@descriptions = Descriptions.new(@descriptions_hash)

Expand All @@ -12,6 +14,7 @@ def setup

def teardown
$stdout = @old_stdout
super
end

def test_single_core_formula
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/diagnostic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/test/download_strategies_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class AbstractDownloadStrategyTests < Homebrew::TestCase
include FileUtils

def setup
super
@name = "foo"
@resource = ResourceDouble.new
@strategy = AbstractDownloadStrategy.new(@name, @resource)
Expand Down Expand Up @@ -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 {}
Expand All @@ -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 {}
Expand Down Expand Up @@ -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)
Expand All @@ -147,6 +151,7 @@ def setup

def teardown
rmtree @cached_location
super
end

def git_commit_all
Expand Down Expand Up @@ -236,6 +241,7 @@ def test_fetch_last_commit

class DownloadStrategyDetectorTests < Homebrew::TestCase
def setup
super
@d = DownloadStrategyDetector.new
end

Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/formula_lock_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

class FormulaLockTests < Homebrew::TestCase
def setup
super
@lock = FormulaLock.new("foo")
@lock.lock
end

def teardown
@lock.unlock
HOMEBREW_LOCK_DIR.children.each(&:unlink)
super
end

def test_locking_file_with_existing_lock_raises_error
Expand Down
2 changes: 2 additions & 0 deletions Library/Homebrew/test/formula_pin_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def installed_kegs
end

def setup
super
@f = FormulaDouble.new
@pin = FormulaPin.new(@f)
@f.rack.mkpath
Expand Down Expand Up @@ -50,5 +51,6 @@ def test_unpin

def teardown
@f.rack.rmtree
super
end
end
5 changes: 5 additions & 0 deletions Library/Homebrew/test/formula_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,8 @@ def make_formula(name, version)
end

def setup
super

alias_name = "bar"
@alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}"

Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/test/formulary_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -41,6 +42,7 @@ def install

def teardown
@path.unlink
super
end

def test_factory
Expand Down Expand Up @@ -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"
Expand All @@ -142,6 +145,7 @@ class #{Formulary.class_s(@name)} < Formula

def teardown
@tap.path.rmtree
super
end

def test_factory_tap_formula
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
Loading

0 comments on commit ab9d8df

Please sign in to comment.