2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-21 02:02:39 +01:00
|
|
|
require "diagnostic"
|
|
|
|
|
|
|
|
describe Homebrew::Diagnostic::Checks do
|
|
|
|
specify "#inject_file_list" do
|
|
|
|
expect(subject.inject_file_list([], "foo:\n")).to eq("foo:\n")
|
|
|
|
expect(subject.inject_file_list(%w[/a /b], "foo:\n")).to eq("foo:\n /a\n /b\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#check_for_anaconda" do
|
2017-02-28 14:50:46 +01:00
|
|
|
mktmpdir do |path|
|
2017-02-21 02:02:39 +01:00
|
|
|
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 0755, anaconda
|
|
|
|
FileUtils.chmod 0755, python
|
|
|
|
|
2017-02-28 14:50:46 +01:00
|
|
|
ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
|
2017-02-21 02:02:39 +01:00
|
|
|
|
|
|
|
expect(subject.check_for_anaconda).to match("Anaconda")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-06 18:38:43 +01:00
|
|
|
specify "#check_access_directories" do
|
2019-02-16 12:16:02 -08:00
|
|
|
skip "User is root so everything is writable." if Process.euid.zero?
|
2017-02-21 02:02:39 +01:00
|
|
|
begin
|
2018-09-06 18:38:43 +01:00
|
|
|
dirs = [
|
|
|
|
HOMEBREW_CACHE,
|
|
|
|
HOMEBREW_CELLAR,
|
|
|
|
HOMEBREW_REPOSITORY,
|
|
|
|
HOMEBREW_LOGS,
|
|
|
|
HOMEBREW_LOCKS,
|
|
|
|
]
|
|
|
|
modes = {}
|
|
|
|
dirs.each do |dir|
|
|
|
|
modes[dir] = dir.stat.mode & 0777
|
|
|
|
dir.chmod 0555
|
|
|
|
expect(subject.check_access_directories).to match(dir.to_s)
|
|
|
|
end
|
2017-02-21 02:02:39 +01:00
|
|
|
ensure
|
2018-09-06 18:38:43 +01:00
|
|
|
modes.each do |dir, mode|
|
|
|
|
dir.chmod mode
|
|
|
|
end
|
2017-02-21 02:02:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#check_user_path_1" do
|
|
|
|
bin = HOMEBREW_PREFIX/"bin"
|
|
|
|
sep = File::PATH_SEPARATOR
|
|
|
|
# ensure /usr/bin is before HOMEBREW_PREFIX/bin in the PATH
|
|
|
|
ENV["PATH"] = "/usr/bin#{sep}#{bin}#{sep}" +
|
|
|
|
ENV["PATH"].gsub(%r{(?:^|#{sep})(?:/usr/bin|#{bin})}, "")
|
|
|
|
|
|
|
|
# ensure there's at least one file with the same name in both /usr/bin/ and
|
|
|
|
# HOMEBREW_PREFIX/bin/
|
|
|
|
(bin/File.basename(Dir["/usr/bin/*"].first)).mkpath
|
|
|
|
|
|
|
|
expect(subject.check_user_path_1)
|
|
|
|
.to match("/usr/bin occurs before #{HOMEBREW_PREFIX}/bin")
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#check_user_path_2" do
|
|
|
|
ENV["PATH"] = ENV["PATH"].gsub \
|
|
|
|
%r{(?:^|#{File::PATH_SEPARATOR})#{HOMEBREW_PREFIX}/bin}, ""
|
|
|
|
|
|
|
|
expect(subject.check_user_path_1).to be nil
|
|
|
|
expect(subject.check_user_path_2)
|
|
|
|
.to match("Homebrew's bin was not found in your PATH.")
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#check_user_path_3" do
|
2019-10-13 10:03:26 +01:00
|
|
|
sbin = HOMEBREW_PREFIX/"sbin"
|
|
|
|
ENV["HOMEBREW_PATH"] =
|
|
|
|
"#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
|
|
|
|
ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
|
|
|
|
(sbin/"something").mkpath
|
|
|
|
|
|
|
|
expect(subject.check_user_path_1).to be nil
|
|
|
|
expect(subject.check_user_path_2).to be nil
|
|
|
|
expect(subject.check_user_path_3)
|
|
|
|
.to match("Homebrew's sbin was not found in your PATH")
|
|
|
|
ensure
|
|
|
|
sbin.rmtree
|
2017-02-21 02:02:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
specify "#check_for_config_scripts" do
|
2017-02-28 14:50:46 +01:00
|
|
|
mktmpdir do |path|
|
2017-02-21 02:02:39 +01:00
|
|
|
file = "#{path}/foo-config"
|
|
|
|
FileUtils.touch file
|
|
|
|
FileUtils.chmod 0755, file
|
2019-10-03 08:50:45 +02:00
|
|
|
ENV["HOMEBREW_PATH"] = ENV["PATH"] =
|
|
|
|
"#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
|
2017-02-21 02:02:39 +01:00
|
|
|
|
|
|
|
expect(subject.check_for_config_scripts)
|
|
|
|
.to match('"config" scripts exist')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#check_for_symlinked_cellar" do
|
2019-10-13 10:03:26 +01:00
|
|
|
HOMEBREW_CELLAR.rmtree
|
2017-02-21 02:02:39 +01:00
|
|
|
|
2019-10-13 10:03:26 +01:00
|
|
|
mktmpdir do |path|
|
|
|
|
FileUtils.ln_s path, HOMEBREW_CELLAR
|
2017-02-21 02:02:39 +01:00
|
|
|
|
2019-10-13 10:03:26 +01:00
|
|
|
expect(subject.check_for_symlinked_cellar).to match(path)
|
2017-02-21 02:02:39 +01:00
|
|
|
end
|
2019-10-13 10:03:26 +01:00
|
|
|
ensure
|
|
|
|
HOMEBREW_CELLAR.unlink
|
|
|
|
HOMEBREW_CELLAR.mkpath
|
2017-02-21 02:02:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
specify "#check_tmpdir" do
|
|
|
|
ENV["TMPDIR"] = "/i/don/t/exis/t"
|
|
|
|
expect(subject.check_tmpdir).to match("doesn't exist")
|
|
|
|
end
|
|
|
|
|
|
|
|
specify "#check_for_external_cmd_name_conflict" do
|
2017-02-28 14:50:46 +01:00
|
|
|
mktmpdir do |path1|
|
|
|
|
mktmpdir do |path2|
|
2017-02-21 02:02:39 +01:00
|
|
|
[path1, path2].each do |path|
|
|
|
|
cmd = "#{path}/brew-foo"
|
|
|
|
FileUtils.touch cmd
|
|
|
|
FileUtils.chmod 0755, cmd
|
|
|
|
end
|
|
|
|
|
2017-11-17 17:41:58 +00:00
|
|
|
allow(Tap).to receive(:cmd_directories).and_return([path1, path2])
|
2017-02-21 02:02:39 +01:00
|
|
|
|
|
|
|
expect(subject.check_for_external_cmd_name_conflict)
|
|
|
|
.to match("brew-foo")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-01-01 18:11:59 -08:00
|
|
|
|
|
|
|
specify "#check_homebrew_prefix" do
|
2019-01-21 14:33:56 +00:00
|
|
|
allow(Homebrew).to receive(:default_prefix?).and_return(false)
|
2019-01-01 18:11:59 -08:00
|
|
|
expect(subject.check_homebrew_prefix)
|
|
|
|
.to match("Your Homebrew's prefix is not #{Homebrew::DEFAULT_PREFIX}")
|
|
|
|
end
|
2017-02-21 02:02:39 +01:00
|
|
|
end
|