From e9815bf2bd2950b5450f0c3ed3bb7eadd3b4cbb3 Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Fri, 18 Nov 2016 20:47:46 +0900 Subject: install: add tests with custom requirements --- Library/Homebrew/test/install_test.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Library') diff --git a/Library/Homebrew/test/install_test.rb b/Library/Homebrew/test/install_test.rb index fa1057a02..9fe5fff0e 100644 --- a/Library/Homebrew/test/install_test.rb +++ b/Library/Homebrew/test/install_test.rb @@ -27,4 +27,27 @@ class IntegrationCommandTestInstall < IntegrationCommandTestCase assert_match "testball1: this formula has no --with-fo option so it will be ignored!", cmd("install", "testball1", "--with-fo") end + + def test_install_with_nonfatal_requirement + setup_test_formula "testball1", <<-EOS.undent + class NonFatalRequirement < Requirement + satisfy { false } + end + depends_on NonFatalRequirement + EOS + message = "NonFatalRequirement unsatisfied!" + assert_equal 1, cmd("install", "testball1").scan(message).size + end + + def test_install_with_fatal_requirement + setup_test_formula "testball1", <<-EOS.undent + class FatalRequirement < Requirement + fatal true + satisfy { false } + end + depends_on FatalRequirement + EOS + message = "FatalRequirement unsatisfied!" + assert_equal 1, cmd_fail("install", "testball1").scan(message).size + end end -- cgit v1.2.3 From 61c8fff0ee2717522a1fb971ca4ef7450df305b9 Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sat, 19 Nov 2016 02:03:30 +0900 Subject: install: suppress redundunt warnings with `depends_on` requirement When a formula depends on any requirements, they evaluated at most three times: before locking, before installing dependent, before building formula. When a non-fatal requirement is specified and thus evaluated three times, mostly the same warning message is also emitted three times. This change restricts printing the warning messages only when a bottle is successfully installed or before building. Since this timing is after the final dependency computation for each cases, the warnings will be most useful to check what is not yet satisfied. --- Library/Homebrew/formula_installer.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index c05b0da60..e2af9779c 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -251,6 +251,7 @@ class FormulaInstaller opoo "Bottle installation failed: building from source." raise BuildToolsError, [formula] unless DevelopmentTools.installed? else + puts @requirement_messages @poured_bottle = true end end @@ -260,6 +261,7 @@ class FormulaInstaller unless @poured_bottle not_pouring = !pour_bottle || @pour_failed compute_and_install_dependencies if not_pouring && !ignore_deps? + puts @requirement_messages build clean @@ -334,17 +336,21 @@ class FormulaInstaller end def check_requirements(req_map) + @requirement_messages = [] fatals = [] req_map.each_pair do |dependent, reqs| next if dependent.installed? reqs.each do |req| - puts "#{dependent}: #{req.message}" + @requirement_messages << "#{dependent}: #{req.message}" fatals << req if req.fatal? end end - raise UnsatisfiedRequirements, fatals unless fatals.empty? + return if fatals.empty? + + puts @requirement_messages + raise UnsatisfiedRequirements, fatals end def install_requirement_default_formula?(req, dependent, build) -- cgit v1.2.3 From bcc9002214955d588f323c0854ab3f4e2de9904f Mon Sep 17 00:00:00 2001 From: Kaito Udagawa Date: Sun, 20 Nov 2016 19:45:33 +0900 Subject: install: print nothing if `@requirement_messages` is a String or nil --- Library/Homebrew/formula_installer.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index e2af9779c..19b619625 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -52,6 +52,7 @@ class FormulaInstaller @debug = false @options = Options.new @invalid_option_names = [] + @requirement_messages = [] @@attempted ||= Set.new @@ -251,7 +252,7 @@ class FormulaInstaller opoo "Bottle installation failed: building from source." raise BuildToolsError, [formula] unless DevelopmentTools.installed? else - puts @requirement_messages + puts_requirement_messages @poured_bottle = true end end @@ -261,7 +262,7 @@ class FormulaInstaller unless @poured_bottle not_pouring = !pour_bottle || @pour_failed compute_and_install_dependencies if not_pouring && !ignore_deps? - puts @requirement_messages + puts_requirement_messages build clean @@ -349,7 +350,7 @@ class FormulaInstaller return if fatals.empty? - puts @requirement_messages + puts_requirement_messages raise UnsatisfiedRequirements, fatals end @@ -837,4 +838,10 @@ class FormulaInstaller @@locked.clear @hold_locks = false end + + def puts_requirement_messages + return unless @requirement_messages + return if @requirement_messages.empty? + puts @requirement_messages + end end -- cgit v1.2.3