diff options
Diffstat (limited to 'Library/Homebrew/test/support')
5 files changed, 0 insertions, 317 deletions
diff --git a/Library/Homebrew/test/support/helper/fs_leak_logger.rb b/Library/Homebrew/test/support/helper/fs_leak_logger.rb deleted file mode 100644 index 3fbb148fa..000000000 --- a/Library/Homebrew/test/support/helper/fs_leak_logger.rb +++ /dev/null @@ -1,27 +0,0 @@ -module Test - module Helper - module FSLeakLogger - def self.included(klass) - require "find" - logdir = HOMEBREW_LIBRARY_PATH.join("tmp") - logdir.mkpath - @@log = File.open(logdir.join("fs_leak.log"), "w") - klass.make_my_diffs_pretty! - end - - def setup - @__files_before_test = [] - Find.find(TEST_TMPDIR) { |f| @__files_before_test << f.sub(TEST_TMPDIR, "") } - super - end - - def 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 diff --git a/Library/Homebrew/test/support/helper/integration_command_test_case.rb b/Library/Homebrew/test/support/helper/integration_command_test_case.rb deleted file mode 100644 index 7ba094645..000000000 --- a/Library/Homebrew/test/support/helper/integration_command_test_case.rb +++ /dev/null @@ -1,155 +0,0 @@ -require "bundler" -require "fileutils" -require "pathname" -require "formula" -require "test/support/helper/test_case" -require "open3" - -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" - end - - def needs_test_cmd_taps - return if ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] - skip "HOMEBREW_TEST_OFFICIAL_CMD_TAPS is not set" - end - - def needs_macos - skip "Not on MacOS" unless OS.mac? - end - - def cmd_id_from_args(args) - args_pretty = args.join(" ").gsub(TEST_TMPDIR, "@TMPDIR@") - test_pretty = "#{self.class.name}\##{name}.#{@cmd_id_index += 1}" - "[#{test_pretty}] brew #{args_pretty}" - end - - def cmd_output(*args) - env = args.last.is_a?(Hash) ? args.pop : {} - - env.merge!( - "HOMEBREW_BREW_FILE" => HOMEBREW_PREFIX/"bin/brew", - "HOMEBREW_INTEGRATION_TEST" => cmd_id_from_args(args), - "HOMEBREW_TEST_TMPDIR" => TEST_TMPDIR, - "HOMEBREW_DEVELOPER" => ENV["HOMEBREW_DEVELOPER"], - ) - - ruby_args = [ - "-W0", - "-I", "#{HOMEBREW_LIBRARY_PATH}/test/support/lib", - "-I", HOMEBREW_LIBRARY_PATH.to_s, - "-rconfig" - ] - ruby_args << "-rsimplecov" if ENV["HOMEBREW_TESTS_COVERAGE"] - ruby_args << "-rtest/support/helper/integration_mocks" - ruby_args << (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path.to_s - - Bundler.with_original_env do - output, status = Open3.capture2e(env, RUBY_PATH, *ruby_args, *args) - [output.chomp, status] - end - end - - def cmd(*args) - output, status = cmd_output(*args) - assert status.success?, <<-EOS.undent - `brew #{args.join " "}` exited with non-zero status! - #{output} - EOS - output - end - - def cmd_fail(*args) - output, status = cmd_output(*args) - refute status.success?, <<-EOS.undent - `brew #{args.join " "}` exited with zero status! - #{output} - EOS - output - end - - def setup_test_formula(name, content = nil) - formula_path = CoreTap.new.formula_dir/"#{name}.rb" - - case name - when /^testball/ - content = <<-EOS.undent - desc "Some test" - homepage "https://example.com/#{name}" - url "file://#{TEST_FIXTURE_DIR}/tarballs/testball-0.1.tbz" - sha256 "#{TESTBALL_SHA256}" - - option "with-foo", "Build with foo" - - def install - (prefix/"foo"/"test").write("test") if build.with? "foo" - prefix.install Dir["*"] - (buildpath/"test.c").write \ - "#include <stdio.h>\\nint main(){return printf(\\"test\\");}" - bin.mkpath - system ENV.cc, "test.c", "-o", bin/"test" - end - - #{content} - - # something here - EOS - when "foo" - content = <<-EOS.undent - url "https://example.com/#{name}-1.0" - EOS - when "bar" - content = <<-EOS.undent - url "https://example.com/#{name}-1.0" - depends_on "foo" - EOS - end - - formula_path.write <<-EOS.undent - class #{Formulary.class_s(name)} < Formula - #{content} - end - EOS - - formula_path - end - - def setup_remote_tap(name) - tap = Tap.fetch name - tap.install(full_clone: false, quiet: true) unless tap.installed? - tap - end - - def install_and_rename_coretap_formula(old_name, new_name) - core_tap = CoreTap.new - core_tap.path.cd do - shutup do - system "git", "init" - system "git", "add", "--all" - system "git", "commit", "-m", - "#{old_name.capitalize} has not yet been renamed" - end - end - - cmd("install", old_name) - (core_tap.path/"Formula/#{old_name}.rb").unlink - formula_renames = core_tap.path/"formula_renames.json" - formula_renames.write JSON.generate(old_name => new_name) - - core_tap.path.cd do - shutup do - system "git", "add", "--all" - system "git", "commit", "-m", - "#{old_name.capitalize} has been renamed to #{new_name.capitalize}" - end - end - end - - def testball - "#{TEST_FIXTURE_DIR}/testball.rb" - end -end diff --git a/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb b/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb deleted file mode 100644 index 413f8b11e..000000000 --- a/Library/Homebrew/test/support/helper/lifecycle_enforcer.rb +++ /dev/null @@ -1,22 +0,0 @@ -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/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 671ffe73c..a82098a0e 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -1,4 +1,3 @@ -require "rspec" require "open3" RSpec::Matchers.define_negated_matcher :not_to_output, :output diff --git a/Library/Homebrew/test/support/helper/test_case.rb b/Library/Homebrew/test/support/helper/test_case.rb deleted file mode 100644 index 5e72bb048..000000000 --- a/Library/Homebrew/test/support/helper/test_case.rb +++ /dev/null @@ -1,112 +0,0 @@ -require "formulary" -require "tap" - -module Homebrew - class TestCase < ::Minitest::Test - require "test/support/helper/fs_leak_logger" - require "test/support/helper/lifecycle_enforcer" - require "test/support/helper/shutup" - include Test::Helper::FSLeakLogger - include Test::Helper::LifecycleEnforcer - include Test::Helper::Shutup - - TEST_DIRECTORIES = [ - CoreTap.instance.path/"Formula", - HOMEBREW_CACHE, - HOMEBREW_CACHE_FORMULA, - HOMEBREW_CELLAR, - HOMEBREW_LOCK_DIR, - HOMEBREW_LOGS, - HOMEBREW_TEMP, - ].freeze - - def setup - # These directories need to be created before - # `FSLeakLogger` is called with `super`. - TEST_DIRECTORIES.each(&:mkpath) - - super - - @__argv = ARGV.dup - @__env = ENV.to_hash # dup doesn't work on ENV - end - - def teardown - ARGV.replace(@__argv) - ENV.replace(@__env) - - Tab.clear_cache - - FileUtils.rm_rf [ - TEST_DIRECTORIES.map(&:children), - HOMEBREW_LINKED_KEGS, - HOMEBREW_PINNED_KEGS, - HOMEBREW_PREFIX/".git", - HOMEBREW_PREFIX/"bin", - HOMEBREW_PREFIX/"share", - HOMEBREW_PREFIX/"opt", - HOMEBREW_PREFIX/"Caskroom", - HOMEBREW_LIBRARY/"Taps/caskroom", - HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-bundle", - HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-foo", - HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-services", - HOMEBREW_LIBRARY/"Taps/homebrew/homebrew-shallow", - HOMEBREW_REPOSITORY/".git", - CoreTap.instance.path/".git", - CoreTap.instance.alias_dir, - CoreTap.instance.path/"formula_renames.json", - ] - - super - end - - 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 |
