doctor: move code away from cmd/
Closes Homebrew/homebrew#47665. Signed-off-by: Baptiste Fontaine <batifon@yahoo.fr>
This commit is contained in:
parent
5d8a6e368f
commit
9f1442db14
File diff suppressed because it is too large
Load Diff
@ -1,5 +1,5 @@
|
|||||||
require "blacklist"
|
require "blacklist"
|
||||||
require "cmd/doctor"
|
require "diagnostic"
|
||||||
require "cmd/search"
|
require "cmd/search"
|
||||||
require "formula_installer"
|
require "formula_installer"
|
||||||
require "tap"
|
require "tap"
|
||||||
@ -159,7 +159,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def check_xcode
|
def check_xcode
|
||||||
checks = Checks.new
|
checks = Diagnostic::Checks.new
|
||||||
%w[
|
%w[
|
||||||
check_for_unsupported_osx
|
check_for_unsupported_osx
|
||||||
check_for_bad_install_name_tool
|
check_for_bad_install_name_tool
|
||||||
|
@ -1,30 +1,8 @@
|
|||||||
require "formula"
|
require "formula"
|
||||||
require "tab"
|
require "tab"
|
||||||
|
require "diagnostic"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
def missing_deps(ff)
|
|
||||||
missing = {}
|
|
||||||
ff.each do |f|
|
|
||||||
missing_deps = f.recursive_dependencies do |dependent, dep|
|
|
||||||
if dep.optional? || dep.recommended?
|
|
||||||
tab = Tab.for_formula(dependent)
|
|
||||||
Dependency.prune unless tab.with?(dep)
|
|
||||||
elsif dep.build?
|
|
||||||
Dependency.prune
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
missing_deps.map!(&:to_formula)
|
|
||||||
missing_deps.reject! { |d| d.installed_prefixes.any? }
|
|
||||||
|
|
||||||
unless missing_deps.empty?
|
|
||||||
yield f.full_name, missing_deps if block_given?
|
|
||||||
missing[f.full_name] = missing_deps
|
|
||||||
end
|
|
||||||
end
|
|
||||||
missing
|
|
||||||
end
|
|
||||||
|
|
||||||
def missing
|
def missing
|
||||||
return unless HOMEBREW_CELLAR.exist?
|
return unless HOMEBREW_CELLAR.exist?
|
||||||
|
|
||||||
@ -34,7 +12,7 @@ module Homebrew
|
|||||||
ARGV.resolved_formulae
|
ARGV.resolved_formulae
|
||||||
end
|
end
|
||||||
|
|
||||||
missing_deps(ff) do |name, missing|
|
Diagnostic.missing_deps(ff) do |name, missing|
|
||||||
print "#{name}: " if ff.size > 1
|
print "#{name}: " if ff.size > 1
|
||||||
puts "#{missing * " "}"
|
puts "#{missing * " "}"
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
require "cmd/tap"
|
require "cmd/tap"
|
||||||
require "cmd/doctor"
|
require "diagnostic"
|
||||||
require "formula_versions"
|
require "formula_versions"
|
||||||
require "migrator"
|
require "migrator"
|
||||||
require "formulary"
|
require "formulary"
|
||||||
@ -15,7 +15,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
# check permissions
|
# check permissions
|
||||||
checks = Checks.new
|
checks = Diagnostic::Checks.new
|
||||||
%w[
|
%w[
|
||||||
check_access_usr_local
|
check_access_usr_local
|
||||||
check_access_homebrew_repository
|
check_access_homebrew_repository
|
||||||
|
1344
Library/Homebrew/diagnostic.rb
Normal file
1344
Library/Homebrew/diagnostic.rb
Normal file
File diff suppressed because it is too large
Load Diff
@ -265,8 +265,8 @@ class BuildError < RuntimeError
|
|||||||
puts issues.map { |i| "#{i["title"]} #{i["html_url"]}" }.join("\n")
|
puts issues.map { |i| "#{i["title"]} #{i["html_url"]}" }.join("\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
require "cmd/doctor"
|
require "diagnostic"
|
||||||
unsupported_osx = Checks.new.check_for_unsupported_osx
|
unsupported_osx = Diagnostic::Checks.new.check_for_unsupported_osx
|
||||||
opoo unsupported_osx if unsupported_osx
|
opoo unsupported_osx if unsupported_osx
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
require "bundler"
|
require "bundler"
|
||||||
require "testing_env"
|
require "testing_env"
|
||||||
require "core_formula_repository"
|
require "core_formula_repository"
|
||||||
|
require "fileutils"
|
||||||
|
|
||||||
class IntegrationCommandTests < Homebrew::TestCase
|
class IntegrationCommandTests < Homebrew::TestCase
|
||||||
def cmd_output(*args)
|
def cmd_output(*args)
|
||||||
@ -152,7 +153,7 @@ class IntegrationCommandTests < Homebrew::TestCase
|
|||||||
cmd("readall", "--aliases", "--syntax")
|
cmd("readall", "--aliases", "--syntax")
|
||||||
cmd("readall", "Homebrew/homebrew")
|
cmd("readall", "Homebrew/homebrew")
|
||||||
ensure
|
ensure
|
||||||
formula_file.unlink
|
formula_file.unlink unless formula_file.nil?
|
||||||
repo.alias_dir.rmtree
|
repo.alias_dir.rmtree
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -181,4 +182,58 @@ class IntegrationCommandTests < Homebrew::TestCase
|
|||||||
ensure
|
ensure
|
||||||
Tap::TAP_DIRECTORY.rmtree
|
Tap::TAP_DIRECTORY.rmtree
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_missing
|
||||||
|
url = "file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
|
||||||
|
sha256 = "1dfb13ce0f6143fe675b525fc9e168adb2215c5d5965c9f57306bb993170914f"
|
||||||
|
repo = CoreFormulaRepository.new
|
||||||
|
foo_file = repo.formula_dir/"foo.rb"
|
||||||
|
foo_file.write <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
url "#{url}"
|
||||||
|
sha256 "#{sha256}"
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
bar_file = repo.formula_dir/"bar.rb"
|
||||||
|
bar_file.write <<-EOS.undent
|
||||||
|
class Bar < Formula
|
||||||
|
url "#{url}"
|
||||||
|
sha256 "#{sha256}"
|
||||||
|
depends_on "foo"
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
cmd("install", "bar")
|
||||||
|
cmd("uninstall", "foo")
|
||||||
|
assert_match "foo", cmd("missing")
|
||||||
|
ensure
|
||||||
|
cmd("uninstall", "--force", "foo", "bar")
|
||||||
|
cmd("cleanup", "--force", "--prune=all")
|
||||||
|
foo_file.unlink unless foo_file.nil?
|
||||||
|
bar_file.unlink unless bar_file.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_doctor_check_path_for_trailing_slashes
|
||||||
|
assert_match "Some directories in your path end in a slash",
|
||||||
|
cmd_fail("doctor", "check_path_for_trailing_slashes",
|
||||||
|
{"PATH" => ENV["PATH"] + File::PATH_SEPARATOR + "/foo/bar/"})
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_doctor_check_for_anaconda
|
||||||
|
mktmpdir do |path|
|
||||||
|
anaconda = "#{path}/anaconda"
|
||||||
|
python = "#{path}/python"
|
||||||
|
FileUtils.touch anaconda
|
||||||
|
File.open(python, "w") do |file|
|
||||||
|
file.write("#! #{`which bash`}\necho -n '#{python}'\n")
|
||||||
|
end
|
||||||
|
FileUtils.chmod 0777, anaconda
|
||||||
|
FileUtils.chmod 0777, python
|
||||||
|
|
||||||
|
assert_match "Anaconda",
|
||||||
|
cmd_fail("doctor", "check_for_anaconda",
|
||||||
|
{"PATH" => path + File::PATH_SEPARATOR + ENV["PATH"]})
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user