diff options
| author | David Broder-Rodgers | 2017-01-30 18:31:52 +0000 |
|---|---|---|
| committer | David Broder-Rodgers | 2017-01-30 18:31:52 +0000 |
| commit | 13a3a57fa86678e3a3cb9272fe04285cb538c55b (patch) | |
| tree | c345802d70ff32e2f787986b2f5392ac76f367fb /Library/Homebrew/test | |
| parent | 3c566399cf8dab3aff8c54381e7b83b0e6ef3995 (diff) | |
| parent | 35045b2934d94eabe302693a05b12fb530827454 (diff) | |
| download | brew-13a3a57fa86678e3a3cb9272fe04285cb538c55b.tar.bz2 | |
Merge remote-tracking branch 'origin/master' into insecure_audit
Diffstat (limited to 'Library/Homebrew/test')
59 files changed, 549 insertions, 385 deletions
diff --git a/Library/Homebrew/test/ARGV_test.rb b/Library/Homebrew/test/ARGV_test.rb index 6805e0c62..e93d09c39 100644 --- a/Library/Homebrew/test/ARGV_test.rb +++ b/Library/Homebrew/test/ARGV_test.rb @@ -3,6 +3,7 @@ require "extend/ARGV" class ArgvExtensionTests < Homebrew::TestCase def setup + super @argv = [].extend(HomebrewArgvExtension) end @@ -21,8 +22,6 @@ class ArgvExtensionTests < Homebrew::TestCase keg.mkpath @argv << "mxcl" assert_equal 1, @argv.kegs.length - ensure - keg.parent.rmtree end def test_argv_named diff --git a/Library/Homebrew/test/ENV_test.rb b/Library/Homebrew/test/ENV_test.rb index 6c0e68a9e..cbfd01e25 100644 --- a/Library/Homebrew/test/ENV_test.rb +++ b/Library/Homebrew/test/ENV_test.rb @@ -31,6 +31,7 @@ end module SharedEnvTests def setup + super @env = {}.extend(EnvActivation) end @@ -133,7 +134,7 @@ module SharedEnvTests end def test_switching_compilers_updates_compiler - [:clang, :gcc, :gcc_4_0].each do |compiler| + [:clang, :gcc_4_2, :gcc_4_0].each do |compiler| @env.send(compiler) assert_equal compiler, @env.compiler end diff --git a/Library/Homebrew/test/audit_test.rb b/Library/Homebrew/test/audit_test.rb index 2725f906e..60cf27610 100644 --- a/Library/Homebrew/test/audit_test.rb +++ b/Library/Homebrew/test/audit_test.rb @@ -6,13 +6,10 @@ require "dev-cmd/audit" class FormulaTextTests < Homebrew::TestCase def setup + super @dir = mktmpdir end - def teardown - FileUtils.rm_rf @dir - end - def formula_text(name, body = nil, options = {}) path = Pathname.new "#{@dir}/#{name}.rb" path.open("w") do |f| @@ -58,13 +55,10 @@ end class FormulaAuditorTests < Homebrew::TestCase def setup + super @dir = mktmpdir end - def teardown - FileUtils.rm_rf @dir - end - def formula_auditor(name, text, options = {}) path = Pathname.new "#{@dir}/#{name}.rb" path.open("w") do |f| @@ -249,7 +243,7 @@ class FormulaAuditorTests < Homebrew::TestCase needs_compat require "compat/formula_specialties" - ARGV.stubs(:homebrew_developer?).returns false + ENV.delete("HOMEBREW_DEVELOPER") fa = shutup do formula_auditor "foo", <<-EOS.undent class Foo < GithubGistFormula @@ -266,7 +260,7 @@ class FormulaAuditorTests < Homebrew::TestCase needs_compat require "compat/formula_specialties" - ARGV.stubs(:homebrew_developer?).returns false + ENV.delete("HOMEBREW_DEVELOPER") fa = formula_auditor "foo", <<-EOS.undent class Foo < ScriptFileFormula url "http://example.com/foo-1.0.tgz" @@ -281,7 +275,7 @@ class FormulaAuditorTests < Homebrew::TestCase needs_compat require "compat/formula_specialties" - ARGV.stubs(:homebrew_developer?).returns false + ENV.delete("HOMEBREW_DEVELOPER") fa = formula_auditor "foo", <<-EOS.undent class Foo < AmazonWebServicesFormula url "http://example.com/foo-1.0.tgz" @@ -367,13 +361,10 @@ class FormulaAuditorTests < Homebrew::TestCase end EOS - original_value = ENV["HOMEBREW_NO_GITHUB_API"] ENV["HOMEBREW_NO_GITHUB_API"] = "1" fa.audit_github_repository assert_equal [], fa.problems - ensure - ENV["HOMEBREW_NO_GITHUB_API"] = original_value end def test_audit_caveats @@ -429,8 +420,8 @@ class FormulaAuditorTests < Homebrew::TestCase fa.audit_homepage assert_equal ["The homepage should start with http or https " \ - "(URL is #{fa.formula.homepage}).", "The homepage is not reachable " \ - "(curl exit code #{$?.exitstatus})"], fa.problems + "(URL is #{fa.formula.homepage}).", "The homepage #{fa.formula.homepage} is not reachable " \ + "(HTTP status code 000)"], fa.problems formula_homepages = { "bar" => "http://www.freedesktop.org/wiki/bar", diff --git a/Library/Homebrew/test/bottle_collector_test.rb b/Library/Homebrew/test/bottle_collector_test.rb index d75e29ec8..5879da92c 100644 --- a/Library/Homebrew/test/bottle_collector_test.rb +++ b/Library/Homebrew/test/bottle_collector_test.rb @@ -3,6 +3,7 @@ require "utils/bottles" 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 3535d80ef..fd890192f 100644 --- a/Library/Homebrew/test/bottle_hooks_test.rb +++ b/Library/Homebrew/test/bottle_hooks_test.rb @@ -17,6 +17,7 @@ class BottleHookTests < Homebrew::TestCase end def setup + super @fi = FormulaInstaller.new FormulaDouble.new end @@ -43,5 +44,6 @@ class BottleHookTests < Homebrew::TestCase 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 73a1c95f7..54b9cb2b1 100644 --- a/Library/Homebrew/test/build_environment_test.rb +++ b/Library/Homebrew/test/build_environment_test.rb @@ -3,6 +3,7 @@ require "build_environment" 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 e460d25cc..05e7ccd94 100644 --- a/Library/Homebrew/test/build_options_test.rb +++ b/Library/Homebrew/test/build_options_test.rb @@ -4,6 +4,7 @@ require "options" 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 9eaac5792..3a582b907 100644 --- a/Library/Homebrew/test/caveats_test.rb +++ b/Library/Homebrew/test/caveats_test.rb @@ -4,6 +4,7 @@ require "caveats" 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 9017b528d..4c674edd2 100644 --- a/Library/Homebrew/test/checksum_verification_test.rb +++ b/Library/Homebrew/test/checksum_verification_test.rb @@ -17,10 +17,6 @@ class ChecksumVerificationTests < Homebrew::TestCase end end - def teardown - @_f.clear_cache - end - def test_good_sha256 formula do sha256 TESTBALL_SHA256 diff --git a/Library/Homebrew/test/cleaner_test.rb b/Library/Homebrew/test/cleaner_test.rb index ac108421c..05a91b90b 100644 --- a/Library/Homebrew/test/cleaner_test.rb +++ b/Library/Homebrew/test/cleaner_test.rb @@ -6,14 +6,11 @@ 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? - end - def test_clean_file @f.bin.mkpath @f.lib.mkpath diff --git a/Library/Homebrew/test/cleanup_test.rb b/Library/Homebrew/test/cleanup_test.rb index bb8e1cdc6..8a292933a 100644 --- a/Library/Homebrew/test/cleanup_test.rb +++ b/Library/Homebrew/test/cleanup_test.rb @@ -14,14 +14,14 @@ end class CleanupTests < Homebrew::TestCase def setup + super @ds_store = Pathname.new "#{HOMEBREW_PREFIX}/Library/.DS_Store" FileUtils.touch @ds_store end def teardown FileUtils.rm_f @ds_store - ARGV.delete "--dry-run" - ARGV.delete "--prune=all" + super end def test_cleanup @@ -55,9 +55,6 @@ class CleanupTests < Homebrew::TestCase refute_predicate f1, :installed? refute_predicate f2, :installed? assert_predicate f3, :installed? - ensure - [f1, f2, f3].each(&:clear_cache) - f3.rack.rmtree end def test_cleanup_logs diff --git a/Library/Homebrew/test/commands_test.rb b/Library/Homebrew/test/commands_test.rb index d44d2da0e..5f5dc9586 100644 --- a/Library/Homebrew/test/commands_test.rb +++ b/Library/Homebrew/test/commands_test.rb @@ -13,6 +13,7 @@ end class CommandsTests < Homebrew::TestCase def setup + super @cmds = [ # internal commands HOMEBREW_LIBRARY_PATH/"cmd/rbcmd.rb", @@ -28,6 +29,7 @@ class CommandsTests < Homebrew::TestCase def teardown @cmds.each(&:unlink) + super end def test_internal_commands @@ -45,8 +47,6 @@ class CommandsTests < Homebrew::TestCase end def test_external_commands - env = ENV.to_hash - mktmpdir do |dir| %w[brew-t1 brew-t2.rb brew-t3.py].each do |file| path = "#{dir}/#{file}" @@ -65,8 +65,6 @@ class CommandsTests < Homebrew::TestCase "Executable files with a non Ruby extension shoudn't be included" refute cmds.include?("t4"), "Non-executable files shouldn't be included" end - ensure - ENV.replace(env) end def test_internal_command_path diff --git a/Library/Homebrew/test/compiler_selector_test.rb b/Library/Homebrew/test/compiler_selector_test.rb index b1591bdbe..aa1a6f97e 100644 --- a/Library/Homebrew/test/compiler_selector_test.rb +++ b/Library/Homebrew/test/compiler_selector_test.rb @@ -31,6 +31,7 @@ class CompilerSelectorTests < Homebrew::TestCase 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 db3b78226..c5444fcbc 100644 --- a/Library/Homebrew/test/dependencies_test.rb +++ b/Library/Homebrew/test/dependencies_test.rb @@ -5,6 +5,7 @@ require "requirements" class DependenciesTests < Homebrew::TestCase def setup + super @deps = Dependencies.new end @@ -89,6 +90,7 @@ end 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 1c7f70118..c63d04637 100644 --- a/Library/Homebrew/test/dependency_collector_test.rb +++ b/Library/Homebrew/test/dependency_collector_test.rb @@ -11,11 +11,13 @@ class DependencyCollectorTests < Homebrew::TestCase 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 9d6de35e2..de743ce03 100644 --- a/Library/Homebrew/test/dependency_expansion_test.rb +++ b/Library/Homebrew/test/dependency_expansion_test.rb @@ -9,6 +9,7 @@ class DependencyExpansionTests < Homebrew::TestCase 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 65255995e..404f26d79 100644 --- a/Library/Homebrew/test/dependency_test.rb +++ b/Library/Homebrew/test/dependency_test.rb @@ -3,6 +3,7 @@ require "dependency" class DependableTests < Homebrew::TestCase def setup + super @tags = ["foo", "bar", :build] @dep = Struct.new(:tags).new(@tags).extend(Dependable) end @@ -118,6 +119,11 @@ class DependencyTests < Homebrew::TestCase end class TapDependencyTests < Homebrew::TestCase + def test_tap + dep = TapDependency.new("foo/bar/dog") + assert_equal Tap.new("foo", "bar"), dep.tap + end + def test_option_names dep = TapDependency.new("foo/bar/dog") assert_equal %w[dog], dep.option_names diff --git a/Library/Homebrew/test/descriptions_test.rb b/Library/Homebrew/test/descriptions_test.rb index de38fdbd1..baeeb7b19 100644 --- a/Library/Homebrew/test/descriptions_test.rb +++ b/Library/Homebrew/test/descriptions_test.rb @@ -3,6 +3,8 @@ require "descriptions" class DescriptionsTest < Homebrew::TestCase def setup + super + @descriptions_hash = {} @descriptions = Descriptions.new(@descriptions_hash) @@ -12,6 +14,7 @@ class DescriptionsTest < Homebrew::TestCase 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 c9bb524b0..7a1fb25f7 100644 --- a/Library/Homebrew/test/diagnostic_test.rb +++ b/Library/Homebrew/test/diagnostic_test.rb @@ -5,14 +5,10 @@ require "diagnostic" class DiagnosticChecksTest < Homebrew::TestCase def setup - @env = ENV.to_hash + super @checks = Homebrew::Diagnostic::Checks.new end - def teardown - ENV.replace(@env) - end - def test_inject_file_list assert_equal "foo:\n", @checks.inject_file_list([], "foo:\n") @@ -103,8 +99,6 @@ class DiagnosticChecksTest < Homebrew::TestCase assert_match "/usr/bin occurs before #{HOMEBREW_PREFIX}/bin", @checks.check_user_path_1 - ensure - bin.rmtree end def test_check_user_path_bin diff --git a/Library/Homebrew/test/download_strategies_test.rb b/Library/Homebrew/test/download_strategies_test.rb index 87218fb12..40236b420 100644 --- a/Library/Homebrew/test/download_strategies_test.rb +++ b/Library/Homebrew/test/download_strategies_test.rb @@ -2,11 +2,12 @@ require "testing_env" require "download_strategy" class ResourceDouble - attr_reader :url, :specs, :version + attr_reader :url, :specs, :version, :mirrors def initialize(url = "http://example.com/foo.tar.gz", specs = {}) @url = url @specs = specs + @mirrors = [] end end @@ -14,6 +15,7 @@ class AbstractDownloadStrategyTests < Homebrew::TestCase include FileUtils def setup + super @name = "foo" @resource = ResourceDouble.new @strategy = AbstractDownloadStrategy.new(@name, @resource) @@ -60,10 +62,86 @@ class VCSDownloadStrategyTests < Homebrew::TestCase end end +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 {} + @strategy = GitHubPrivateRepositoryDownloadStrategy.new("foo", resource) + end + + def test_set_github_token + assert_equal "token", @strategy.instance_variable_get(:@github_token) + end + + def test_parse_url_pattern + assert_equal "owner", @strategy.instance_variable_get(:@owner) + assert_equal "repo", @strategy.instance_variable_get(:@repo) + assert_equal "archive/1.1.5.tar.gz", @strategy.instance_variable_get(:@filepath) + end + + def test_download_url + expected = "https://token@github.com/owner/repo/archive/1.1.5.tar.gz" + assert_equal expected, @strategy.download_url + end +end + +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 {} + @strategy = GitHubPrivateRepositoryReleaseDownloadStrategy.new("foo", resource) + end + + def test_parse_url_pattern + assert_equal "owner", @strategy.instance_variable_get(:@owner) + assert_equal "repo", @strategy.instance_variable_get(:@repo) + assert_equal "tag", @strategy.instance_variable_get(:@tag) + assert_equal "foo_v0.1.0_darwin_amd64.tar.gz", @strategy.instance_variable_get(:@filename) + end + + def test_download_url + @strategy.stubs(:resolve_asset_id).returns(456) + expected = "https://token@api.github.com/repos/owner/repo/releases/assets/456" + assert_equal expected, @strategy.download_url + end + + def test_resolve_asset_id + release_metadata = { + "assets" => [ + { + "id" => 123, + "name" => "foo_v0.1.0_linux_amd64.tar.gz", + }, + { + "id" => 456, + "name" => "foo_v0.1.0_darwin_amd64.tar.gz", + }, + ], + } + @strategy.stubs(:fetch_release_metadata).returns(release_metadata) + assert_equal 456, @strategy.send(:resolve_asset_id) + end + + def test_fetch_release_metadata + expected_release_url = "https://api.github.com/repos/owner/repo/releases/tags/tag" + github_mock = MiniTest::Mock.new + github_mock.expect :call, {}, [expected_release_url] + GitHub.stub :open, github_mock do + @strategy.send(:fetch_release_metadata) + end + github_mock.verify + end +end + 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) @@ -71,10 +149,6 @@ class GitDownloadStrategyTests < Homebrew::TestCase mkpath @cached_location end - def teardown - rmtree @cached_location - end - def git_commit_all shutup do system "git", "add", "--all" @@ -83,28 +157,14 @@ class GitDownloadStrategyTests < Homebrew::TestCase end end - def using_git_env - initial_env = ENV.to_hash - %w[AUTHOR COMMITTER].each do |role| - ENV["GIT_#{role}_NAME"] = "brew tests" - ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost" - ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100" - end - yield - ensure - ENV.replace(initial_env) - end - def setup_git_repo - using_git_env do - @cached_location.cd do - shutup do - system "git", "init" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" - end - touch "README" - git_commit_all + @cached_location.cd do + shutup do + system "git", "init" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" end + touch "README" + git_commit_all end end @@ -118,18 +178,16 @@ class GitDownloadStrategyTests < Homebrew::TestCase def test_source_modified_time setup_git_repo - assert_equal 1_242_860_651, @strategy.source_modified_time.to_i + assert_equal 1_485_115_153, @strategy.source_modified_time.to_i end def test_last_commit setup_git_repo - using_git_env do - @cached_location.cd do - touch "LICENSE" - git_commit_all - end + @cached_location.cd do + touch "LICENSE" + git_commit_all end - assert_equal "c50c79b", @strategy.last_commit + assert_equal "f68266e", @strategy.last_commit end def test_fetch_last_commit @@ -140,21 +198,19 @@ class GitDownloadStrategyTests < Homebrew::TestCase resource.instance_variable_set(:@version, Version.create("HEAD")) @strategy = GitDownloadStrategy.new("baz", resource) - using_git_env do - remote_repo.cd do - shutup do - system "git", "init" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" - end - touch "README" - git_commit_all - touch "LICENSE" - git_commit_all + remote_repo.cd do + shutup do + system "git", "init" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-foo" end + touch "README" + git_commit_all + touch "LICENSE" + git_commit_all end @strategy.shutup! - assert_equal "c50c79b", @strategy.fetch_last_commit + assert_equal "f68266e", @strategy.fetch_last_commit ensure remote_repo.rmtree if remote_repo.directory? end @@ -162,6 +218,7 @@ end class DownloadStrategyDetectorTests < Homebrew::TestCase def setup + super @d = DownloadStrategyDetector.new end diff --git a/Library/Homebrew/test/emoji_test.rb b/Library/Homebrew/test/emoji_test.rb new file mode 100644 index 000000000..ea68db8f6 --- /dev/null +++ b/Library/Homebrew/test/emoji_test.rb @@ -0,0 +1,11 @@ +require "testing_env" +require "emoji" + +class EmojiTest < Homebrew::TestCase + def test_install_badge + assert_equal "🍺", Emoji.install_badge + + ENV["HOMEBREW_INSTALL_BADGE"] = "foo" + assert_equal "foo", Emoji.install_badge + end +end diff --git a/Library/Homebrew/test/formula_installer_test.rb b/Library/Homebrew/test/formula_installer_test.rb index 652548bd7..c99b2de74 100644 --- a/Library/Homebrew/test/formula_installer_test.rb +++ b/Library/Homebrew/test/formula_installer_test.rb @@ -84,13 +84,10 @@ class InstallTests < Homebrew::TestCase cc_arg = "--cc=clang" ARGV << cc_arg - begin - temporary_install(TestballBottle.new) do |f| - tab = Tab.for_formula(f) - assert_equal "clang", tab.compiler - end - ensure - ARGV.delete_if { |x| x == cc_arg } + + temporary_install(TestballBottle.new) do |f| + tab = Tab.for_formula(f) + assert_equal "clang", tab.compiler end end end @@ -128,11 +125,7 @@ class FormulaInstallerTests < Homebrew::TestCase fi = FormulaInstaller.new(dependent) assert_raises(CannotInstallFormulaError) { fi.check_install_sanity } ensure - dependency.unpin dependency_keg.unlink - dependency_keg.uninstall - dependency.clear_cache - dep_path.unlink Formulary::FORMULAE.delete(dep_path) end end diff --git a/Library/Homebrew/test/formula_lock_test.rb b/Library/Homebrew/test/formula_lock_test.rb index 80ee9dd25..13244555d 100644 --- a/Library/Homebrew/test/formula_lock_test.rb +++ b/Library/Homebrew/test/formula_lock_test.rb @@ -3,13 +3,14 @@ require "formula_lock" 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 diff --git a/Library/Homebrew/test/formula_pin_test.rb b/Library/Homebrew/test/formula_pin_test.rb index 297d7703e..7e3c7efa0 100644 --- a/Library/Homebrew/test/formula_pin_test.rb +++ b/Library/Homebrew/test/formula_pin_test.rb @@ -21,6 +21,7 @@ class FormulaPinTests < Homebrew::TestCase end def setup + super @f = FormulaDouble.new @pin = FormulaPin.new(@f) @f.rack.mkpath @@ -47,8 +48,4 @@ class FormulaPinTests < Homebrew::TestCase refute_predicate @pin, :pinned? refute_predicate HOMEBREW_PINNED_KEGS, :directory? end - - def teardown - @f.rack.rmtree - end end diff --git a/Library/Homebrew/test/formula_test.rb b/Library/Homebrew/test/formula_test.rb index a6db1b57f..ecdd1847b 100644 --- a/Library/Homebrew/test/formula_test.rb +++ b/Library/Homebrew/test/formula_test.rb @@ -176,8 +176,6 @@ class FormulaTests < Homebrew::TestCase prefix.mkpath FileUtils.touch prefix+Tab::FILENAME assert_predicate f, :any_version_installed? - ensure - f.rack.rmtree end def test_migration_needed @@ -203,9 +201,6 @@ class FormulaTests < Homebrew::TestCase newname_prefix.mkpath refute_predicate f, :migration_needed? - ensure - oldname_prefix.parent.rmtree - newname_prefix.parent.rmtree end def test_installed? @@ -240,8 +235,6 @@ class FormulaTests < Homebrew::TestCase prefix = HOMEBREW_CELLAR+f.name+f.head.version prefix.mkpath assert_equal prefix, f.installed_prefix - ensure - f.rack.rmtree end def test_installed_prefix_devel_installed @@ -255,8 +248,6 @@ class FormulaTests < Homebrew::TestCase prefix = HOMEBREW_CELLAR+f.name+f.devel.version prefix.mkpath assert_equal prefix, f.installed_prefix - ensure - f.rack.rmtree end def test_installed_prefix_stable_installed @@ -270,8 +261,6 @@ class FormulaTests < Homebrew::TestCase prefix = HOMEBREW_CELLAR+f.name+f.version prefix.mkpath assert_equal prefix, f.installed_prefix - ensure - f.rack.rmtree end def test_installed_prefix_outdated_stable_head_installed @@ -289,8 +278,6 @@ class FormulaTests < Homebrew::TestCase tab.write assert_equal HOMEBREW_CELLAR/"#{f.name}/#{f.version}", f.installed_prefix - ensure - f.rack.rmtree end def test_installed_prefix_outdated_devel_head_installed @@ -311,8 +298,6 @@ class FormulaTests < Homebrew::TestCase tab.write assert_equal HOMEBREW_CELLAR/"#{f.name}/#{f.version}", f.installed_prefix - ensure - f.rack.rmtree end def test_installed_prefix_head @@ -358,8 +343,6 @@ class FormulaTests < Homebrew::TestCase prefix = HOMEBREW_CELLAR/"#{f.name}/HEAD-222222_2" assert_equal prefix, f.latest_head_prefix - ensure - f.rack.rmtree end def test_equality @@ -543,8 +526,6 @@ class FormulaTests < Homebrew::TestCase end def test_update_head_version - initial_env = ENV.to_hash - f = formula do head "foo", using: :git end @@ -552,12 +533,6 @@ class FormulaTests < Homebrew::TestCase cached_location = f.head.downloader.cached_location cached_location.mkpath - %w[AUTHOR COMMITTER].each do |role| - ENV["GIT_#{role}_NAME"] = "brew tests" - ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost" - ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100" - end - cached_location.cd do FileUtils.touch "LICENSE" shutup do @@ -569,9 +544,6 @@ class FormulaTests < Homebrew::TestCase f.update_head_version assert_equal Version.create("HEAD-5658946"), f.head.version - ensure - ENV.replace(initial_env) - cached_location.rmtree end def test_legacy_options @@ -651,12 +623,80 @@ class FormulaTests < Homebrew::TestCase f4 = formula("f4") do url "f4-1.0" - depends_on "f3" + depends_on "f1" end + stub_formula_loader f4 - assert_equal %w[f3], f4.deps.map(&:name) - assert_equal %w[f1 f2 f3], f4.recursive_dependencies.map(&:name) - assert_equal %w[f2 f3], f4.runtime_dependencies.map(&:name) + f5 = formula("f5") do + url "f5-1.0" + depends_on "f3" => :build + depends_on "f4" + end + + assert_equal %w[f3 f4], f5.deps.map(&:name) + assert_equal %w[f1 f2 f3 f4], f5.recursive_dependencies.map(&:name) + assert_equal %w[f1 f4], f5.runtime_dependencies.map(&:name) + end + + def test_runtime_dependencies_with_optional_deps_from_tap + tap_loader = mock + tap_loader.stubs(:get_formula).raises(RuntimeError, "tried resolving tap formula") + Formulary.stubs(:loader_for).with("foo/bar/f1", from: nil).returns(tap_loader) + + stub_formula_loader formula("f2") { url "f2-1.0" }, "baz/qux/f2" + + f3 = formula("f3") do + url "f3-1.0" + depends_on "foo/bar/f1" => :optional + depends_on "baz/qux/f2" + end + + # f1 shouldn't be loaded by default. + # If it is, an exception will be raised. + assert_equal %w[baz/qux/f2], f3.runtime_dependencies.map(&:name) + + # If --with-f1, f1 should be loaded. + stub_formula_loader formula("f1") { url "f1-1.0" }, "foo/bar/f1" + f3.build = BuildOptions.new(Options.create(%w[--with-f1]), f3.options) + assert_equal %w[foo/bar/f1 baz/qux/f2], f3.runtime_dependencies.map(&:name) + end + + def test_requirements + f1 = formula("f1") do + url "f1-1" + + depends_on :python + depends_on x11: :recommended + depends_on xcode: ["1.0", :optional] + end + stub_formula_loader f1 + + python = PythonRequirement.new + x11 = X11Requirement.new("x11", [:recommended]) + xcode = XcodeRequirement.new(["1.0", :optional]) + + # Default block should filter out deps that aren't being used + assert_equal Set[python, x11], Set.new(f1.recursive_requirements) + + f1.build = BuildOptions.new(["--with-xcode", "--without-x11"], f1.options) + assert_equal Set[python, xcode], Set.new(f1.recursive_requirements) + f1.build = f1.stable.build + + f2 = formula("f2") do + url "f2-1" + depends_on "f1" + end + + assert_equal Set[python, x11], Set.new(f2.recursive_requirements) + + # Empty block should allow all requirements + assert_equal Set[python, x11, xcode], Set.new(f2.recursive_requirements {}) + + # Requirements can be pruned + requirements = f2.recursive_requirements do |_dependent, requirement| + Requirement.prune if requirement.is_a?(PythonRequirement) + end + assert_equal Set[x11, xcode], Set.new(requirements) end def test_to_hash @@ -703,9 +743,6 @@ class FormulaTests < Homebrew::TestCase assert_equal f3.installed_kegs.sort_by(&:version)[0..1], f3.eligible_kegs_for_cleanup.sort_by(&:version) - ensure - [f1, f2, f3].each(&:clear_cache) - f3.rack.rmtree end def test_eligible_kegs_for_cleanup_keg_pinned @@ -727,10 +764,6 @@ class FormulaTests < Homebrew::TestCase assert_predicate f3, :installed? assert_equal [Keg.new(f2.prefix)], shutup { f3.eligible_kegs_for_cleanup } - ensure - f1.unpin - [f1, f2, f3].each(&:clear_cache) - f3.rack.rmtree end def test_eligible_kegs_for_cleanup_head_installed @@ -753,8 +786,6 @@ class FormulaTests < Homebrew::TestCase eligible_kegs = f.installed_kegs - [Keg.new(f.prefix("HEAD-111111_1"))] assert_equal eligible_kegs, f.eligible_kegs_for_cleanup - ensure - f.rack.rmtree end def test_pour_bottle @@ -806,6 +837,8 @@ class AliasChangeTests < Homebrew::TestCase end def setup + super + alias_name = "bar" @alias_path = "#{CoreTap.instance.alias_dir}/#{alias_name}" @@ -874,6 +907,8 @@ class OutdatedVersionsTests < Homebrew::TestCase attr_reader :f, :old_formula, :new_formula def setup + super + @f = formula do url "foo" version "1.20" @@ -889,11 +924,6 @@ class OutdatedVersionsTests < Homebrew::TestCase @old_alias_target_prefix = HOMEBREW_CELLAR/"#{old_formula.name}/1.0" end - def teardown - formulae = [@f, @old_formula, @new_formula] - formulae.map(&:rack).select(&:exist?).each(&:rmtree) - end - def alias_path "#{@f.tap.alias_dir}/bar" end @@ -1058,13 +1088,12 @@ class OutdatedVersionsTests < Homebrew::TestCase outdated_stable_prefix = HOMEBREW_CELLAR.join("testball/1.0") head_prefix_a = HOMEBREW_CELLAR.join("testball/HEAD") head_prefix_b = HOMEBREW_CELLAR.join("testball/HEAD-aaaaaaa_1") - head_prefix_c = HOMEBREW_CELLAR.join("testball/HEAD-5658946") + head_prefix_c = HOMEBREW_CELLAR.join("testball/HEAD-18a7103") setup_tab_for_prefix(outdated_stable_prefix) tab_a = setup_tab_for_prefix(head_prefix_a, versions: { "stable" => "1.0" }) setup_tab_for_prefix(head_prefix_b) - initial_env = ENV.to_hash testball_repo = HOMEBREW_PREFIX.join("testball_repo") testball_repo.mkdir @@ -1074,12 +1103,6 @@ class OutdatedVersionsTests < Homebrew::TestCase head "file://#{testball_repo}", using: :git end - %w[AUTHOR COMMITTER].each do |role| - ENV["GIT_#{role}_NAME"] = "brew tests" - ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost" - ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100" - end - testball_repo.cd do FileUtils.touch "LICENSE" shutup do @@ -1104,13 +1127,7 @@ class OutdatedVersionsTests < Homebrew::TestCase reset_outdated_kegs assert_predicate f.outdated_kegs(fetch_head: true), :empty? ensure - ENV.replace(initial_env) testball_repo.rmtree if testball_repo.exist? - outdated_stable_prefix.rmtree if outdated_stable_prefix.exist? - head_prefix_b.rmtree if head_prefix.exist? - head_prefix_c.rmtree if head_prefix_c.exist? - FileUtils.rm_rf HOMEBREW_CACHE/"testball--git" - FileUtils.rm_rf HOMEBREW_CELLAR/"testball" end def test_outdated_kegs_version_scheme_changed @@ -1124,8 +1141,6 @@ class OutdatedVersionsTests < Homebrew::TestCase setup_tab_for_prefix(prefix, versions: { "stable" => "0.1" }) refute_predicate f.outdated_kegs, :empty? - ensure - prefix.rmtree end def test_outdated_kegs_mixed_version_schemes @@ -1153,8 +1168,6 @@ class OutdatedVersionsTests < Homebrew::TestCase prefix_d = HOMEBREW_CELLAR.join("testball/20141011") setup_tab_for_prefix(prefix_d, versions: { "stable" => "20141009", "version_scheme" => 3 }) assert_predicate f.outdated_kegs, :empty? - ensure - f.rack.rmtree end def test_outdated_kegs_head_with_version_scheme @@ -1174,7 +1187,5 @@ class OutdatedVersionsTests < Homebrew::TestCase setup_tab_for_prefix(head_prefix, versions: { "stable" => "1.0", "version_scheme" => 2 }) assert_predicate f.outdated_kegs, :empty? - ensure - head_prefix.rmtree end end diff --git a/Library/Homebrew/test/formulary_test.rb b/Library/Homebrew/test/formulary_test.rb index 3d88c8407..ea7ecf8d0 100644 --- a/Library/Homebrew/test/formulary_test.rb +++ b/Library/Homebrew/test/formulary_test.rb @@ -16,6 +16,7 @@ end 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") @@ -39,10 +40,6 @@ class FormularyFactoryTest < Homebrew::TestCase EOS end - def teardown - @path.unlink - end - def test_factory assert_kind_of Formula, Formulary.factory(@name) end @@ -61,8 +58,6 @@ class FormularyFactoryTest < Homebrew::TestCase path.write "class Wrong#{Formulary.class_s(name)} < Formula\nend\n" assert_raises(FormulaClassUnavailableError) { Formulary.factory(name) } - ensure - path.unlink end def test_factory_from_path @@ -90,8 +85,6 @@ class FormularyFactoryTest < Homebrew::TestCase result = Formulary.factory("foo") assert_kind_of Formula, result assert_equal alias_path.to_s, result.alias_path - ensure - alias_dir.rmtree end def test_factory_from_rack_and_from_keg @@ -107,9 +100,6 @@ class FormularyFactoryTest < Homebrew::TestCase assert_kind_of Tab, f.build ensure keg.unlink - keg.uninstall - formula.clear_cache - formula.bottle.clear_cache end def test_load_from_contents @@ -121,13 +111,12 @@ class FormularyFactoryTest < Homebrew::TestCase (HOMEBREW_CELLAR/@name).mkpath assert_equal HOMEBREW_CELLAR/@name, Formulary.to_rack(@name) assert_raises(TapFormulaUnavailableError) { Formulary.to_rack("a/b/#{@name}") } - ensure - FileUtils.rm_rf HOMEBREW_CELLAR/@name end end class FormularyTapFactoryTest < Homebrew::TestCase def setup + super @name = "foo" @tap = Tap.new "homebrew", "foo" @path = @tap.path/"#{@name}.rb" @@ -139,10 +128,6 @@ class FormularyTapFactoryTest < Homebrew::TestCase @path.write @code end - def teardown - @tap.path.rmtree - end - def test_factory_tap_formula assert_kind_of Formula, Formulary.factory(@name) end @@ -173,6 +158,7 @@ end class FormularyTapPriorityTest < Homebrew::TestCase def setup + super @name = "foo" @core_path = CoreTap.new.formula_dir/"#{@name}.rb" @tap = Tap.new "homebrew", "foo" @@ -186,11 +172,6 @@ class FormularyTapPriorityTest < Homebrew::TestCase @tap_path.write code end - def teardown - @core_path.unlink - @tap.path.rmtree - end - def test_find_with_priority_core_formula formula = Formulary.find_with_priority(@name) assert_kind_of Formula, formula diff --git a/Library/Homebrew/test/gpg2_requirement_test.rb b/Library/Homebrew/test/gpg2_requirement_test.rb index fa7fc9ea4..3297c2851 100644 --- a/Library/Homebrew/test/gpg2_requirement_test.rb +++ b/Library/Homebrew/test/gpg2_requirement_test.rb @@ -4,6 +4,7 @@ require "fileutils" class GPG2RequirementTests < Homebrew::TestCase def setup + super @dir = Pathname.new(mktmpdir) (@dir/"bin/gpg").write <<-EOS.undent #!/bin/bash @@ -14,11 +15,11 @@ class GPG2RequirementTests < Homebrew::TestCase def teardown FileUtils.rm_rf @dir + super end def test_satisfied - with_environment("PATH" => @dir/"bin") do - assert_predicate GPG2Requirement.new, :satisfied? - end + ENV["PATH"] = @dir/"bin" + assert_predicate GPG2Requirement.new, :satisfied? end end diff --git a/Library/Homebrew/test/gpg_test.rb b/Library/Homebrew/test/gpg_test.rb index 0374bdab4..ea4372549 100644 --- a/Library/Homebrew/test/gpg_test.rb +++ b/Library/Homebrew/test/gpg_test.rb @@ -3,18 +3,16 @@ require "gpg" class GpgTest < Homebrew::TestCase def setup + super skip "GPG Unavailable" unless Gpg.available? @dir = Pathname.new(mktmpdir) end def test_create_test_key Dir.chdir(@dir) do - with_environment("HOME" => @dir) do - shutup { Gpg.create_test_key(@dir) } - assert_predicate @dir/".gnupg/secring.gpg", :exist? - end + ENV["HOME"] = @dir + shutup { Gpg.create_test_key(@dir) } + assert_predicate @dir/".gnupg/secring.gpg", :exist? end - ensure - @dir.rmtree end end diff --git a/Library/Homebrew/test/hardware_test.rb b/Library/Homebrew/test/hardware_test.rb index 2bea5387d..69f881a60 100644 --- a/Library/Homebrew/test/hardware_test.rb +++ b/Library/Homebrew/test/hardware_test.rb @@ -8,7 +8,7 @@ class HardwareTests < Homebrew::TestCase if Hardware::CPU.intel? def test_hardware_intel_family - families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :dunno] + families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :kabylake, :dunno] assert_includes families, Hardware::CPU.family end end diff --git a/Library/Homebrew/test/install_test.rb b/Library/Homebrew/test/install_test.rb index e047c0030..da6c1863f 100644 --- a/Library/Homebrew/test/install_test.rb +++ b/Library/Homebrew/test/install_test.rb @@ -73,13 +73,6 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase end def test_install_head_installed - initial_env = ENV.to_hash - %w[AUTHOR COMMITTER].each do |role| - ENV["GIT_#{role}_NAME"] = "brew tests" - ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost" - ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100" - end - repo_path = HOMEBREW_CACHE.join("repo") repo_path.join("bin").mkpath @@ -105,15 +98,11 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase # Ignore dependencies, because we'll try to resolve requirements in build.rb # and there will be the git requirement, but we cannot instantiate git # formula since we only have testball1 formula. - assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-2ccdf4f", cmd("install", "testball1", "--HEAD", "--ignore-dependencies") - assert_match "testball1-HEAD-2ccdf4f already installed", + assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689", cmd("install", "testball1", "--HEAD", "--ignore-dependencies") + assert_match "testball1-HEAD-d5eb689 already installed", cmd("install", "testball1", "--HEAD", "--ignore-dependencies") - assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-2ccdf4f", cmd("unlink", "testball1") + assert_match "#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689", cmd("unlink", "testball1") assert_match "#{HOMEBREW_CELLAR}/testball1/1.0", cmd("install", "testball1") - - ensure - ENV.replace(initial_env) - repo_path.rmtree end def test_install_with_invalid_option diff --git a/Library/Homebrew/test/keg_test.rb b/Library/Homebrew/test/keg_test.rb index 2c91027e5..bd4232038 100644 --- a/Library/Homebrew/test/keg_test.rb +++ b/Library/Homebrew/test/keg_test.rb @@ -2,7 +2,7 @@ require "testing_env" require "keg" require "stringio" -class LinkTests < Homebrew::TestCase +class LinkTestCase < Homebrew::TestCase include FileUtils def setup_test_keg(name, version) @@ -20,6 +20,8 @@ class LinkTests < Homebrew::TestCase end def setup + super + @keg = setup_test_keg("foo", "1.0") @dst = HOMEBREW_PREFIX.join("bin", "helloworld") @nonexistent = Pathname.new("/some/nonexistent/path") @@ -34,15 +36,17 @@ class LinkTests < Homebrew::TestCase end def teardown - @kegs.each do |keg| - keg.unlink - keg.uninstall - end - + @kegs.each(&:unlink) $stdout = @old_stdout - - rmtree HOMEBREW_PREFIX/"bin" rmtree HOMEBREW_PREFIX/"lib" + super + end +end + +class LinkTests < LinkTestCase + def test_all + Formula.clear_racks_cache + assert_equal [@keg], Keg.all end def test_empty_installation @@ -294,8 +298,6 @@ class LinkTests < Homebrew::TestCase assert_equal 2, lib.children.length ensure a.unlink - a.uninstall - b.uninstall end def test_removes_broken_symlinks_that_conflict_with_directories @@ -311,11 +313,10 @@ class LinkTests < Homebrew::TestCase keg.link ensure keg.unlink - keg.uninstall end end -class InstalledDependantsTests < LinkTests +class InstalledDependantsTests < LinkTestCase def stub_formula_name(name) f = formula(name) { url "foo-1.0" } stub_formula_loader f @@ -333,6 +334,7 @@ class InstalledDependantsTests < LinkTests def setup super @dependent = setup_test_keg("bar", "1.0") + @keg.link end def alter_tab(keg = @dependent) @@ -341,24 +343,55 @@ class InstalledDependantsTests < LinkTests tab.write end - def dependencies(deps) + # 1.1.6 is the earliest version of Homebrew that generates correct runtime + # dependency lists in tabs. + def dependencies(deps, homebrew_version: "1.1.6") alter_tab do |tab| + tab.homebrew_version = homebrew_version tab.tabfile = @dependent.join("INSTALL_RECEIPT.json") tab.runtime_dependencies = deps end end + def unreliable_dependencies(deps) + # 1.1.5 is (hopefully!) the last version of Homebrew that generates + # incorrect runtime dependency lists in tabs. + dependencies(deps, homebrew_version: "1.1.5") + end + # Test with a keg whose formula isn't known. # This can happen if e.g. a formula is installed # from a file path or URL. def test_unknown_formula Formulary.unstub(:loader_for) - dependencies [] - alter_tab { |t| t.source["path"] = nil } - assert_empty @keg.installed_dependents + alter_tab(@keg) do |t| + t.source["tap"] = "some/tap" + t.source["path"] = nil + end + + dependencies [{ "full_name" => "some/tap/foo", "version" => "1.0" }] + assert_equal [@dependent], @keg.installed_dependents + assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg]) + + dependencies nil + # It doesn't make sense for a keg with no formula to have any dependents, + # so that can't really be tested. assert_nil Keg.find_some_installed_dependents([@keg]) end + def test_a_dependency_with_no_tap_in_tab + @tap_dep = setup_test_keg("baz", "1.0") + + alter_tab(@keg) { |t| t.source["tap"] = nil } + + dependencies nil + Formula["bar"].class.depends_on "foo" + Formula["bar"].class.depends_on "baz" + + result = Keg.find_some_installed_dependents([@keg, @tap_dep]) + assert_equal [[@keg, @tap_dep], ["bar"]], result + end + def test_no_dependencies_anywhere dependencies nil assert_empty @keg.installed_dependents @@ -372,6 +405,27 @@ class InstalledDependantsTests < LinkTests assert_equal [[@keg], ["bar"]], Keg.find_some_installed_dependents([@keg]) end + def test_uninstalling_dependent_and_dependency + dependencies nil + Formula["bar"].class.depends_on "foo" + assert_empty @keg.installed_dependents + assert_nil Keg.find_some_installed_dependents([@keg, @dependent]) + end + + def test_renamed_dependency + dependencies nil + + stub_formula_loader Formula["foo"], "homebrew/core/foo-old" + renamed_path = HOMEBREW_CELLAR/"foo-old" + (HOMEBREW_CELLAR/"foo").rename(renamed_path) + renamed_keg = Keg.new(renamed_path.join("1.0")) + + Formula["bar"].class.depends_on "foo" + + result = Keg.find_some_installed_dependents([renamed_keg]) + assert_equal [[renamed_keg], ["bar"]], result + end + def test_empty_dependencies_in_tab dependencies [] assert_empty @keg.installed_dependents @@ -380,8 +434,8 @@ class InstalledDependantsTests < LinkTests def test_same_name_different_version_in_tab dependencies [{ "full_name" => "foo", "version" => "1.1" }] - assert_empty @keg.installed_dependents - assert_nil Keg.find_some_installed_dependents([@keg]) + assert_equal [@dependent], @keg.installed_dependents + assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg]) end def test_different_name_same_version_in_tab @@ -396,4 +450,26 @@ class InstalledDependantsTests < LinkTests assert_equal [@dependent], @keg.installed_dependents assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg]) end + + def test_fallback_for_old_versions + unreliable_dependencies [{ "full_name" => "baz", "version" => "1.0" }] + Formula["bar"].class.depends_on "foo" + assert_empty @keg.installed_dependents + assert_equal [[@keg], ["bar"]], Keg.find_some_installed_dependents([@keg]) + end + + def test_nonoptlinked + @keg.remove_opt_record + dependencies [{ "full_name" => "foo", "version" => "1.0" }] + assert_empty @keg.installed_dependents + assert_nil Keg.find_some_installed_dependents([@keg]) + end + + def test_keg_only + @keg.unlink + Formula["foo"].class.keg_only "a good reason" + dependencies [{ "full_name" => "foo", "version" => "1.1" }] # different version + assert_equal [@dependent], @keg.installed_dependents + assert_equal [[@keg], ["bar 1.0"]], Keg.find_some_installed_dependents([@keg]) + end end diff --git a/Library/Homebrew/test/language_python_test.rb b/Library/Homebrew/test/language_python_test.rb index d1e3867f7..aa0a7d51d 100644 --- a/Library/Homebrew/test/language_python_test.rb +++ b/Library/Homebrew/test/language_python_test.rb @@ -4,6 +4,7 @@ require "resource" class LanguagePythonTests < Homebrew::TestCase def setup + super @dir = Pathname.new(mktmpdir) resource = stub("resource", stage: true) formula_bin = @dir/"formula_bin" @@ -14,10 +15,6 @@ class LanguagePythonTests < Homebrew::TestCase @venv = Language::Python::Virtualenv::Virtualenv.new(@formula, @dir, "python") end - def teardown - FileUtils.rm_rf @dir - end - def test_virtualenv_creation @formula.expects(:resource).with("homebrew-virtualenv").returns( mock("resource", stage: true) diff --git a/Library/Homebrew/test/migrator_test.rb b/Library/Homebrew/test/migrator_test.rb index 8a2b6ad63..012ea12bb 100644 --- a/Library/Homebrew/test/migrator_test.rb +++ b/Library/Homebrew/test/migrator_test.rb @@ -10,6 +10,7 @@ end class MigratorErrorsTests < Homebrew::TestCase def setup + super @new_f = Testball.new("newname") @new_f.oldname = "oldname" @old_f = Testball.new("oldname") @@ -31,8 +32,6 @@ class MigratorErrorsTests < Homebrew::TestCase tab.source["tap"] = "homebrew/core" tab.write assert_raises(Migrator::MigratorDifferentTapsError) { Migrator.new(@new_f) } - ensure - keg.parent.rmtree end end @@ -40,6 +39,8 @@ class MigratorTests < Homebrew::TestCase include FileUtils def setup + super + @new_f = Testball.new("newname") @new_f.oldname = "oldname" @@ -69,30 +70,16 @@ class MigratorTests < Homebrew::TestCase end def teardown - @old_pin.unlink if @old_pin.symlink? - - if @old_keg_record.parent.symlink? - @old_keg_record.parent.unlink - elsif @old_keg_record.directory? + if !@old_keg_record.parent.symlink? && @old_keg_record.directory? @keg.unlink - @keg.uninstall end if @new_keg_record.directory? new_keg = Keg.new(@new_keg_record) new_keg.unlink - new_keg.uninstall end - @old_keg_record.parent.rmtree if @old_keg_record.parent.directory? - @new_keg_record.parent.rmtree if @new_keg_record.parent.directory? - - rmtree HOMEBREW_PREFIX/"bin" - rmtree HOMEBREW_PREFIX/"opt" if (HOMEBREW_PREFIX/"opt").directory? - # What to do with pin? - @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 e7189a604..f38ec4415 100644 --- a/Library/Homebrew/test/options_test.rb +++ b/Library/Homebrew/test/options_test.rb @@ -15,6 +15,7 @@ end class OptionTests < Homebrew::TestCase def setup + super @option = Option.new("foo") end @@ -43,6 +44,7 @@ end class DeprecatedOptionTests < Homebrew::TestCase def setup + super @deprecated_option = DeprecatedOption.new("foo", "bar") end @@ -68,6 +70,7 @@ end 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 2f88050ae..e9ae9b753 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 @@ require "utils/bottles" 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 4fdf3ebe4..1033df9ab 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 @@ class OSMacDependencyCollectorTests < Homebrew::TestCase 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 655aa1d46..704235b01 100644 --- a/Library/Homebrew/test/os/mac/diagnostic_test.rb +++ b/Library/Homebrew/test/os/mac/diagnostic_test.rb @@ -5,14 +5,10 @@ require "diagnostic" class OSMacDiagnosticChecksTest < Homebrew::TestCase def setup - @env = ENV.to_hash + super @checks = Homebrew::Diagnostic::Checks.new end - def teardown - ENV.replace(@env) - end - def test_check_for_other_package_managers MacOS.stubs(:macports_or_fink).returns ["fink"] assert_match "You have MacPorts or Fink installed:", @@ -20,7 +16,7 @@ class OSMacDiagnosticChecksTest < Homebrew::TestCase end def test_check_for_unsupported_macos - ARGV.stubs(:homebrew_developer?).returns false + ENV.delete("HOMEBREW_DEVELOPER") OS::Mac.stubs(:prerelease?).returns true assert_match "We do not provide support for this pre-release version.", @checks.check_for_unsupported_macos diff --git a/Library/Homebrew/test/os/mac/keg_test.rb b/Library/Homebrew/test/os/mac/keg_test.rb index e79cbc921..d1103415d 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 @@ -28,12 +30,12 @@ class OSMacLinkTests < Homebrew::TestCase def teardown @keg.unlink - @keg.uninstall $stdout = @old_stdout - rmtree HOMEBREW_PREFIX/"bin" rmtree HOMEBREW_PREFIX/"lib" + + super end def test_mach_o_files_skips_hardlinks @@ -48,7 +50,6 @@ class OSMacLinkTests < Homebrew::TestCase assert_equal 1, keg.mach_o_files.size ensure keg.unlink - keg.uninstall end def test_mach_o_files_isnt_confused_by_symlinks @@ -64,6 +65,5 @@ class OSMacLinkTests < Homebrew::TestCase assert_equal 1, keg.mach_o_files.size ensure keg.unlink - keg.uninstall end end diff --git a/Library/Homebrew/test/os/mac/mach_test.rb b/Library/Homebrew/test/os/mac/mach_test.rb index a42f7316b..ed0424be6 100644 --- a/Library/Homebrew/test/os/mac/mach_test.rb +++ b/Library/Homebrew/test/os/mac/mach_test.rb @@ -109,6 +109,7 @@ end 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 f702c7097..ba4217691 100644 --- a/Library/Homebrew/test/os/mac/version_test.rb +++ b/Library/Homebrew/test/os/mac/version_test.rb @@ -4,6 +4,7 @@ require "os/mac/version" 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 62624720e..f5a61398a 100644 --- a/Library/Homebrew/test/patch_test.rb +++ b/Library/Homebrew/test/patch_test.rb @@ -111,6 +111,7 @@ end 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 ac14c8e1e..3dacc0818 100644 --- a/Library/Homebrew/test/patching_test.rb +++ b/Library/Homebrew/test/patching_test.rb @@ -20,11 +20,6 @@ class PatchingTests < Homebrew::TestCase end end - def teardown - @_f.clear_cache - @_f.patchlist.each { |p| p.clear_cache if p.external? } - end - def assert_patched(formula) shutup do formula.brew do diff --git a/Library/Homebrew/test/pathname_test.rb b/Library/Homebrew/test/pathname_test.rb index 2f6360719..b48a26fbd 100644 --- a/Library/Homebrew/test/pathname_test.rb +++ b/Library/Homebrew/test/pathname_test.rb @@ -7,16 +7,12 @@ module PathnameTestExtension include FileUtils def setup + super @src = Pathname.new(mktmpdir) @dst = Pathname.new(mktmpdir) @file = @src/"foo" @dir = @src/"bar" end - - def teardown - rmtree(@src) - rmtree(@dst) - end end class PathnameTests < Homebrew::TestCase diff --git a/Library/Homebrew/test/resource_test.rb b/Library/Homebrew/test/resource_test.rb index c1b526cb2..d982a7c33 100644 --- a/Library/Homebrew/test/resource_test.rb +++ b/Library/Homebrew/test/resource_test.rb @@ -3,6 +3,7 @@ require "resource" 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 2a062cb10..a633defce 100644 --- a/Library/Homebrew/test/sandbox_test.rb +++ b/Library/Homebrew/test/sandbox_test.rb @@ -3,26 +3,23 @@ require "sandbox" class SandboxTest < Homebrew::TestCase def setup + super skip "sandbox not implemented" unless Sandbox.available? @sandbox = Sandbox.new @dir = Pathname.new(mktmpdir) @file = @dir/"foo" end - def teardown - @dir.rmtree - end - def test_formula? f = formula { url "foo-1.0" } f2 = formula { url "bar-1.0" } f2.stubs(:tap).returns(Tap.fetch("test/tap")) - ARGV.stubs(:sandbox?).returns true + ENV["HOMEBREW_SANDBOX"] = "1" assert Sandbox.formula?(f), "Formulae should be sandboxed if --sandbox was passed." - ARGV.stubs(:sandbox?).returns false + ENV.delete("HOMEBREW_SANDBOX") assert Sandbox.formula?(f), "Formulae should be sandboxed if in a sandboxed tap." refute Sandbox.formula?(f2), @@ -30,7 +27,7 @@ class SandboxTest < Homebrew::TestCase end def test_test? - ARGV.stubs(:no_sandbox?).returns false + ENV.delete("HOMEBREW_NO_SANDBOX") assert Sandbox.test?, "Tests should be sandboxed unless --no-sandbox was passed." end @@ -50,7 +47,7 @@ class SandboxTest < Homebrew::TestCase def test_complains_on_failure Utils.expects(popen_read: "foo") - ARGV.stubs(verbose?: true) + ENV["HOMEBREW_VERBOSE"] = "1" out, _err = capture_io do assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } end @@ -64,7 +61,7 @@ class SandboxTest < Homebrew::TestCase bar EOS Utils.expects(popen_read: with_bogus_error) - ARGV.stubs(verbose?: true) + ENV["HOMEBREW_VERBOSE"] = "1" out, _err = capture_io do assert_raises(ErrorDuringExecution) { @sandbox.exec "false" } end diff --git a/Library/Homebrew/test/shell_test.rb b/Library/Homebrew/test/shell_test.rb index 877acb5c8..a32d09863 100644 --- a/Library/Homebrew/test/shell_test.rb +++ b/Library/Homebrew/test/shell_test.rb @@ -37,7 +37,6 @@ class ShellSmokeTest < Homebrew::TestCase end def prepend_path_shell(shell, path, fragment) - original_shell = ENV["SHELL"] ENV["SHELL"] = shell prepend_message = Utils::Shell.prepend_path_in_shell_profile(path) @@ -45,8 +44,6 @@ class ShellSmokeTest < Homebrew::TestCase prepend_message.start_with?(fragment), "#{shell}: expected #{prepend_message} to match #{fragment}" ) - - ENV["SHELL"] = original_shell end def test_prepend_path_in_shell_profile diff --git a/Library/Homebrew/test/software_spec_test.rb b/Library/Homebrew/test/software_spec_test.rb index d9226f8c3..026265a4a 100644 --- a/Library/Homebrew/test/software_spec_test.rb +++ b/Library/Homebrew/test/software_spec_test.rb @@ -3,6 +3,7 @@ require "software_spec" class SoftwareSpecTests < Homebrew::TestCase def setup + super @spec = SoftwareSpec.new end @@ -136,6 +137,7 @@ end class HeadSoftwareSpecTests < Homebrew::TestCase def setup + super @spec = HeadSoftwareSpec.new end @@ -150,6 +152,7 @@ end 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 ee53e7c8c..f193ae71e 100644 --- a/Library/Homebrew/test/stdlib_test.rb +++ b/Library/Homebrew/test/stdlib_test.rb @@ -4,9 +4,11 @@ require "cxxstdlib" class CxxStdlibTests < Homebrew::TestCase def setup + super @clang = CxxStdlib.create(:libstdcxx, :clang) @gcc = CxxStdlib.create(:libstdcxx, :gcc) - @gcc4 = CxxStdlib.create(:libstdcxx, :gcc_4_0) + @gcc40 = CxxStdlib.create(:libstdcxx, :gcc_4_0) + @gcc42 = CxxStdlib.create(:libstdcxx, :gcc_4_2) @gcc48 = CxxStdlib.create(:libstdcxx, "gcc-4.8") @gcc49 = CxxStdlib.create(:libstdcxx, "gcc-4.9") @lcxx = CxxStdlib.create(:libcxx, :clang) @@ -15,7 +17,7 @@ class CxxStdlibTests < Homebrew::TestCase def test_apple_libstdcxx_intercompatibility assert @clang.compatible_with?(@gcc) - assert @clang.compatible_with?(@gcc4) + assert @clang.compatible_with?(@gcc42) end def test_compatibility_same_compilers_and_type @@ -42,7 +44,7 @@ class CxxStdlibTests < Homebrew::TestCase def test_apple_compiler_reporting assert_predicate @clang, :apple_compiler? assert_predicate @gcc, :apple_compiler? - assert_predicate @gcc4, :apple_compiler? + assert_predicate @gcc42, :apple_compiler? refute_predicate @gcc48, :apple_compiler? end diff --git a/Library/Homebrew/test/support/fixtures/receipt.json b/Library/Homebrew/test/support/fixtures/receipt.json index b20626bbe..a57d6d80d 100644 --- a/Library/Homebrew/test/support/fixtures/receipt.json +++ b/Library/Homebrew/test/support/fixtures/receipt.json @@ -1,4 +1,5 @@ { + "homebrew_version": "1.1.6", "used_options": [ "--with-foo", "--without-bar" diff --git a/Library/Homebrew/test/support/helper/env.rb b/Library/Homebrew/test/support/helper/env.rb deleted file mode 100644 index 904a1d4c7..000000000 --- a/Library/Homebrew/test/support/helper/env.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Test - module Helper - module Env - def with_environment(partial_env) - old = ENV.to_hash - ENV.update partial_env - begin - yield - ensure - ENV.replace old - end - 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 index b79fdd6e0..a36b56691 100644 --- a/Library/Homebrew/test/support/helper/integration_command_test_case.rb +++ b/Library/Homebrew/test/support/helper/integration_command_test_case.rb @@ -6,40 +6,12 @@ require "test/support/helper/test_case" 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 teardown - coretap = CoreTap.new - paths_to_delete = [ - HOMEBREW_LINKED_KEGS, - HOMEBREW_PINNED_KEGS, - HOMEBREW_CELLAR.children, - HOMEBREW_CACHE.children, - HOMEBREW_LOCK_DIR.children, - HOMEBREW_LOGS.children, - HOMEBREW_TEMP.children, - 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.path/".git", - coretap.alias_dir, - coretap.formula_dir.children, - coretap.path/"formula_renames.json", - ].flatten - FileUtils.rm_rf paths_to_delete - end - def needs_test_cmd_taps return if ENV["HOMEBREW_TEST_OFFICIAL_CMD_TAPS"] skip "HOMEBREW_TEST_OFFICIAL_CMD_TAPS is not set" @@ -106,16 +78,20 @@ class IntegrationCommandTestCase < Homebrew::TestCase def cmd(*args) output = cmd_output(*args) status = $?.exitstatus - puts "\n'brew #{args.join " "}' output: #{output}" if status.nonzero? - assert_equal 0, status + assert_equal 0, status, <<-EOS.undent + `brew #{args.join " "}` exited with non-zero status! + #{output} + EOS output end def cmd_fail(*args) output = cmd_output(*args) status = $?.exitstatus - $stderr.puts "\n'brew #{args.join " "}'" if status.zero? - refute_equal 0, status + refute_equal 0, status, <<-EOS.undent + `brew #{args.join " "}` exited with zero status! + #{output} + EOS output end 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 000000000..413f8b11e --- /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 60c91e7bb..ab97ef758 100644 --- a/Library/Homebrew/test/support/helper/test_case.rb +++ b/Library/Homebrew/test/support/helper/test_case.rb @@ -1,17 +1,60 @@ 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 TEST_SHA1 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze TEST_SHA256 = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef".freeze + def setup + 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 + + coretap = CoreTap.new + paths_to_delete = [ + HOMEBREW_LINKED_KEGS, + HOMEBREW_PINNED_KEGS, + HOMEBREW_CELLAR.children, + HOMEBREW_CACHE.children, + HOMEBREW_LOCK_DIR.children, + HOMEBREW_LOGS.children, + HOMEBREW_TEMP.children, + 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.path/".git", + coretap.alias_dir, + coretap.formula_dir.children, + coretap.path/"formula_renames.json", + ].flatten + FileUtils.rm_rf paths_to_delete + + 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 diff --git a/Library/Homebrew/test/tab_test.rb b/Library/Homebrew/test/tab_test.rb index 5d83b5907..f6f55348d 100644 --- a/Library/Homebrew/test/tab_test.rb +++ b/Library/Homebrew/test/tab_test.rb @@ -4,6 +4,8 @@ require "formula" class TabTests < Homebrew::TestCase def setup + super + @used = Options.create(%w[--with-foo --without-bar]) @unused = Options.create(%w[--with-baz --without-qux]) @@ -32,6 +34,8 @@ class TabTests < Homebrew::TestCase def test_defaults tab = Tab.empty + + assert_equal HOMEBREW_VERSION, tab.homebrew_version assert_empty tab.unused_options assert_empty tab.used_options assert_nil tab.changed_files @@ -69,6 +73,49 @@ class TabTests < Homebrew::TestCase assert_predicate tab, :universal? end + def test_parsed_homebrew_version + tab = Tab.new + assert_same Version::NULL, tab.parsed_homebrew_version + + tab = Tab.new(homebrew_version: "1.2.3") + assert_equal "1.2.3", tab.parsed_homebrew_version + assert tab.parsed_homebrew_version < "1.2.3-1-g12789abdf" + assert_kind_of Version, tab.parsed_homebrew_version + + tab.homebrew_version = "1.2.4-567-g12789abdf" + assert tab.parsed_homebrew_version > "1.2.4" + assert tab.parsed_homebrew_version > "1.2.4-566-g21789abdf" + assert tab.parsed_homebrew_version < "1.2.4-568-g01789abdf" + + tab = Tab.new(homebrew_version: "2.0.0-134-gabcdefabc-dirty") + assert tab.parsed_homebrew_version > "2.0.0" + assert tab.parsed_homebrew_version > "2.0.0-133-g21789abdf" + assert tab.parsed_homebrew_version < "2.0.0-135-g01789abdf" + end + + def test_runtime_dependencies + tab = Tab.new + assert_nil tab.runtime_dependencies + + tab.homebrew_version = "1.1.6" + assert_nil tab.runtime_dependencies + + tab.runtime_dependencies = [] + refute_nil tab.runtime_dependencies + + tab.homebrew_version = "1.1.5" + assert_nil tab.runtime_dependencies + + tab.homebrew_version = "1.1.7" + refute_nil tab.runtime_dependencies + + tab.homebrew_version = "1.1.10" + refute_nil tab.runtime_dependencies + + tab.runtime_dependencies = [{ "full_name" => "foo", "version" => "1.0" }] + refute_nil tab.runtime_dependencies + end + def test_cxxstdlib assert_equal :clang, @tab.cxxstdlib.compiler assert_equal :libcxx, @tab.cxxstdlib.type @@ -215,16 +262,13 @@ end class TabLoadingTests < Homebrew::TestCase def setup + super @f = formula { url "foo-1.0" } @f.prefix.mkpath @path = @f.prefix.join(Tab::FILENAME) @path.write TEST_FIXTURE_DIR.join("receipt.json").read end - def teardown - @f.rack.rmtree - end - def test_for_keg tab = Tab.for_keg(@f.prefix) assert_equal @path, tab.tabfile diff --git a/Library/Homebrew/test/tap_test.rb b/Library/Homebrew/test/tap_test.rb index b950cd166..578326cea 100644 --- a/Library/Homebrew/test/tap_test.rb +++ b/Library/Homebrew/test/tap_test.rb @@ -16,7 +16,7 @@ class IntegrationCommandTestTap < IntegrationCommandTestCase end assert_match "homebrew/foo", cmd("tap") - assert_match "homebrew/versions", cmd("tap", "--list-official") + assert_match "homebrew/science", cmd("tap", "--list-official") assert_match "2 taps", cmd("tap-info") assert_match "https://github.com/Homebrew/homebrew-foo", cmd("tap-info", "homebrew/foo") assert_match "https://github.com/Homebrew/homebrew-foo", cmd("tap-info", "--json=v1", "--installed") @@ -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") @@ -65,13 +66,6 @@ class TapTest < Homebrew::TestCase end def setup_git_repo - env = ENV.to_hash - %w[AUTHOR COMMITTER].each do |role| - ENV["GIT_#{role}_NAME"] = "brew tests" - ENV["GIT_#{role}_EMAIL"] = "brew-tests@localhost" - ENV["GIT_#{role}_DATE"] = "Thu May 21 00:04:11 2009 +0100" - end - @path.cd do shutup do system "git", "init" @@ -80,12 +74,6 @@ class TapTest < Homebrew::TestCase system "git", "commit", "-m", "init" end end - ensure - ENV.replace(env) - end - - def teardown - @path.rmtree end def test_fetch @@ -162,17 +150,15 @@ class TapTest < Homebrew::TestCase assert_raises(TapUnavailableError) { Tap.new("Homebrew", "bar").remote } refute_predicate @tap, :custom_remote? - version_tap = Tap.new("Homebrew", "versions") - version_tap.path.mkpath - version_tap.path.cd do + services_tap = Tap.new("Homebrew", "services") + services_tap.path.mkpath + services_tap.path.cd do shutup do system "git", "init" - system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-versions" + system "git", "remote", "add", "origin", "https://github.com/Homebrew/homebrew-services" end end - refute_predicate version_tap, :private? - ensure - version_tap.path.rmtree if version_tap + refute_predicate services_tap, :private? end def test_remote_not_git_repo @@ -189,10 +175,10 @@ class TapTest < Homebrew::TestCase touch @path/"README" setup_git_repo - assert_equal "e1893a6bd191ba895c71b652ff8376a6114c7fa7", @tap.git_head - assert_equal "e189", @tap.git_short_head - assert_match "years ago", @tap.git_last_commit - assert_equal "2009-05-21", @tap.git_last_commit_date + assert_equal "0453e16c8e3fac73104da50927a86221ca0740c2", @tap.git_head + assert_equal "0453", @tap.git_short_head + assert_match(/\A\d+ .+ ago\Z/, @tap.git_last_commit) + assert_equal "2017-01-22", @tap.git_last_commit_date end def test_private_remote @@ -256,8 +242,6 @@ class TapTest < Homebrew::TestCase refute_predicate tap, :installed? refute_predicate HOMEBREW_PREFIX/"share/man/man1/brew-tap-cmd.1", :exist? refute_predicate HOMEBREW_PREFIX/"share/man/man1", :exist? - ensure - (HOMEBREW_PREFIX/"share").rmtree if (HOMEBREW_PREFIX/"share").exist? end def test_pin_and_unpin @@ -285,6 +269,7 @@ class CoreTapTest < Homebrew::TestCase include FileUtils def setup + super @repo = CoreTap.new end @@ -322,8 +307,5 @@ class CoreTapTest < Homebrew::TestCase assert_equal ["bar"], @repo.aliases assert_equal @repo.alias_table, "bar" => "foo" assert_equal @repo.alias_reverse_table, "foo" => ["bar"] - ensure - @formula_file.unlink - @repo.alias_dir.rmtree end end diff --git a/Library/Homebrew/test/uninstall_test.rb b/Library/Homebrew/test/uninstall_test.rb index 5c53988f2..2f8bf4fff 100644 --- a/Library/Homebrew/test/uninstall_test.rb +++ b/Library/Homebrew/test/uninstall_test.rb @@ -3,15 +3,21 @@ require "cmd/uninstall" class UninstallTests < Homebrew::TestCase def setup + super + @dependency = formula("dependency") { url "f-1" } @dependent = formula("dependent") do url "f-1" depends_on "dependency" end - [@dependency, @dependent].each { |f| f.installed_prefix.mkpath } + [@dependency, @dependent].each do |f| + f.installed_prefix.mkpath + Keg.new(f.installed_prefix).optlink + end tab = Tab.empty + tab.homebrew_version = "1.1.6" tab.tabfile = @dependent.installed_prefix/Tab::FILENAME tab.runtime_dependencies = [ { "full_name" => "dependency", "version" => "1" }, @@ -24,7 +30,7 @@ class UninstallTests < Homebrew::TestCase def teardown Homebrew.failed = false - [@dependency, @dependent].each { |f| f.rack.rmtree } + super end def handle_unsatisfied_dependents @@ -52,8 +58,6 @@ class UninstallTests < Homebrew::TestCase assert_empty handle_unsatisfied_dependents refute_predicate Homebrew, :failed? end - ensure - ARGV.delete("--ignore-dependencies") end end diff --git a/Library/Homebrew/test/update_report_test.rb b/Library/Homebrew/test/update_report_test.rb index 6b6cec6ce..32c3e36d0 100644 --- a/Library/Homebrew/test/update_report_test.rb +++ b/Library/Homebrew/test/update_report_test.rb @@ -24,6 +24,7 @@ class ReportTests < Homebrew::TestCase 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 146f57b49..1f2fb7b55 100644 --- a/Library/Homebrew/test/utils_test.rb +++ b/Library/Homebrew/test/utils_test.rb @@ -5,13 +5,12 @@ require "utils/shell" class UtilTests < Homebrew::TestCase def setup + super @dir = Pathname.new(mktmpdir) - @env = ENV.to_hash end - def teardown - @dir.rmtree - ENV.replace @env + def esc(code) + /(\e\[\d+m)*\e\[#{code}m/ end def test_ofail @@ -27,11 +26,29 @@ class UtilTests < Homebrew::TestCase end def test_pretty_installed + $stdout.stubs(:tty?).returns true + ENV.delete("HOMEBREW_NO_EMOJI") + tty_with_emoji_output = /\A#{esc 1}foo #{esc 32}✔#{esc 0}\Z/ + assert_match tty_with_emoji_output, pretty_installed("foo") + + ENV["HOMEBREW_NO_EMOJI"] = "1" + tty_no_emoji_output = /\A#{esc 1}foo \(installed\)#{esc 0}\Z/ + assert_match tty_no_emoji_output, pretty_installed("foo") + $stdout.stubs(:tty?).returns false assert_equal "foo", pretty_installed("foo") end def test_pretty_uninstalled + $stdout.stubs(:tty?).returns true + ENV.delete("HOMEBREW_NO_EMOJI") + tty_with_emoji_output = /\A#{esc 1}foo #{esc 31}✘#{esc 0}\Z/ + assert_match tty_with_emoji_output, pretty_uninstalled("foo") + + ENV["HOMEBREW_NO_EMOJI"] = "1" + tty_no_emoji_output = /\A#{esc 1}foo \(uninstalled\)#{esc 0}\Z/ + assert_match tty_no_emoji_output, pretty_uninstalled("foo") + $stdout.stubs(:tty?).returns false assert_equal "foo", pretty_uninstalled("foo") end @@ -212,11 +229,11 @@ class UtilTests < Homebrew::TestCase end def test_odeprecated - ARGV.stubs(:homebrew_developer?).returns false + ENV.delete("HOMEBREW_DEVELOPER") e = assert_raises(MethodDeprecatedError) do odeprecated("method", "replacement", caller: ["#{HOMEBREW_LIBRARY}/Taps/homebrew/homebrew-core/"], - die: true) + disable: true) end assert_match "method", e.message assert_match "replacement", e.message diff --git a/Library/Homebrew/test/versions_test.rb b/Library/Homebrew/test/versions_test.rb index a6e922178..b6814b1d1 100644 --- a/Library/Homebrew/test/versions_test.rb +++ b/Library/Homebrew/test/versions_test.rb @@ -185,8 +185,6 @@ class VersionParsingTests < Homebrew::TestCase d = HOMEBREW_CELLAR/"foo-0.1.9" d.mkpath assert_equal version("0.1.9"), d.version - ensure - d.unlink end def test_no_version |
