2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-25 20:10:25 +01:00
|
|
|
require "formula"
|
|
|
|
require "caveats"
|
|
|
|
|
|
|
|
describe Caveats do
|
2021-01-31 13:14:23 -05:00
|
|
|
subject(:caveats) { described_class.new(f) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2017-02-25 20:10:25 +01:00
|
|
|
let(:f) { formula { url "foo-1.0" } }
|
|
|
|
|
|
|
|
specify "#f" do
|
2021-01-31 13:14:23 -05:00
|
|
|
expect(caveats.f).to eq(f)
|
2017-02-25 20:10:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#empty?" do
|
|
|
|
it "returns true if the Formula has no caveats" do
|
2021-01-31 13:14:23 -05:00
|
|
|
expect(caveats).to be_empty
|
2017-02-25 20:10:25 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "returns false if the Formula has caveats" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
|
|
|
|
def caveats
|
|
|
|
"something"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expect(described_class.new(f)).not_to be_empty
|
|
|
|
end
|
|
|
|
end
|
2017-06-20 05:32:13 +05:30
|
|
|
|
|
|
|
describe "#caveats" do
|
2017-07-23 22:50:39 +05:30
|
|
|
context "when f.plist is not nil", :needs_macos do
|
2017-06-20 05:32:13 +05:30
|
|
|
it "prints plist startup information when f.plist_startup is not nil" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
def plist
|
|
|
|
"plist_test.plist"
|
|
|
|
end
|
|
|
|
plist_options startup: true
|
|
|
|
end
|
2017-07-18 01:29:05 +05:30
|
|
|
expect(described_class.new(f).caveats).to include("startup")
|
2017-06-20 05:32:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "prints plist login information when f.plist_startup is nil" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
def plist
|
|
|
|
"plist_test.plist"
|
|
|
|
end
|
|
|
|
end
|
2017-07-18 01:29:05 +05:30
|
|
|
expect(described_class.new(f).caveats).to include("login")
|
2017-06-20 05:32:13 +05:30
|
|
|
end
|
2017-07-21 06:38:45 +05:30
|
|
|
|
|
|
|
it "gives information about restarting services after upgrade" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
def plist
|
|
|
|
"plist_test.plist"
|
|
|
|
end
|
|
|
|
plist_options startup: true
|
|
|
|
end
|
|
|
|
f_obj = described_class.new(f)
|
2017-07-29 22:21:41 +02:00
|
|
|
plist_path = mktmpdir/"plist"
|
2017-07-21 06:38:45 +05:30
|
|
|
FileUtils.touch plist_path
|
|
|
|
allow(f_obj).to receive(:plist_path).and_return(plist_path)
|
|
|
|
allow(plist_path).to receive(:symlink?).and_return(true)
|
|
|
|
expect(f_obj.caveats).to include("restart #{f.full_name}")
|
|
|
|
expect(f_obj.caveats).to include("sudo")
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when plist_path is not a file nor symlinked and plist_startup is false" do
|
|
|
|
let(:f) {
|
|
|
|
formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
def plist
|
|
|
|
"plist_test.plist"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
let(:f_obj) { described_class.new(f) }
|
|
|
|
let(:caveats) { f_obj.caveats }
|
2017-07-29 22:21:41 +02:00
|
|
|
let(:plist_path) { mktmpdir/"plist" }
|
2017-07-21 06:38:45 +05:30
|
|
|
|
|
|
|
before do
|
|
|
|
FileUtils.touch plist_path
|
|
|
|
allow(f_obj).to receive(:plist_path).and_return(plist_path)
|
|
|
|
allow(plist_path).to receive(:symlink?).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "tells command to run after upgrade" do
|
|
|
|
allow(Kernel).to receive(:system).with(any_args).and_return(true)
|
|
|
|
expect(caveats).to include("restart #{f.full_name} after an upgrade")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "tells command to run to start formula" do
|
|
|
|
expect(caveats).to include("To start #{f.full_name}:")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives information about plist_manual" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
def plist
|
|
|
|
"plist_test.plist"
|
|
|
|
end
|
|
|
|
plist_options manual: "foo"
|
|
|
|
end
|
|
|
|
caveats = described_class.new(f).caveats
|
|
|
|
|
|
|
|
expect(caveats).to include("background service")
|
|
|
|
expect(caveats).to include(f.plist_manual)
|
|
|
|
end
|
|
|
|
|
2021-05-01 16:05:25 +02:00
|
|
|
it "gives information about service" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
|
|
|
run [bin/"php", "test"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
caveats = described_class.new(f).caveats
|
|
|
|
|
|
|
|
expect(f.service?).to eq(true)
|
2021-09-01 11:54:38 -06:00
|
|
|
expect(caveats).to include("'#{f.bin}/php' 'test'")
|
2021-05-01 16:05:25 +02:00
|
|
|
expect(caveats).to include("background service")
|
|
|
|
end
|
|
|
|
|
2017-07-21 06:38:45 +05:30
|
|
|
it "warns about brew failing under tmux" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
def plist
|
|
|
|
"plist_test.plist"
|
|
|
|
end
|
|
|
|
end
|
2021-05-13 17:05:18 +01:00
|
|
|
ENV["HOMEBREW_TMUX"] = "1"
|
2017-07-21 06:38:45 +05:30
|
|
|
allow(Homebrew).to receive(:_system).with("/usr/bin/pbpaste").and_return(false)
|
|
|
|
caveats = described_class.new(f).caveats
|
|
|
|
|
|
|
|
expect(caveats).to include("WARNING:")
|
|
|
|
expect(caveats).to include("tmux")
|
|
|
|
end
|
2017-06-20 05:32:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "when f.keg_only is not nil" do
|
2017-07-18 01:29:05 +05:30
|
|
|
let(:f) {
|
|
|
|
formula do
|
2017-06-20 05:32:13 +05:30
|
|
|
url "foo-1.0"
|
|
|
|
keg_only "some reason"
|
|
|
|
end
|
2017-07-18 01:29:05 +05:30
|
|
|
}
|
|
|
|
let(:caveats) { described_class.new(f).caveats }
|
2017-06-20 05:32:13 +05:30
|
|
|
|
2017-07-18 01:29:05 +05:30
|
|
|
it "tells formula is keg_only" do
|
2017-06-20 05:32:13 +05:30
|
|
|
expect(caveats).to include("keg-only")
|
2017-07-18 01:29:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "gives command to be run when f.bin is a directory" do
|
|
|
|
Pathname.new(f.bin).mkpath
|
2017-06-20 05:32:13 +05:30
|
|
|
expect(caveats).to include(f.opt_bin.to_s)
|
2017-07-18 01:29:05 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it "gives command to be run when f.sbin is a directory" do
|
|
|
|
Pathname.new(f.sbin).mkpath
|
2017-06-20 05:32:13 +05:30
|
|
|
expect(caveats).to include(f.opt_sbin.to_s)
|
|
|
|
end
|
2017-07-18 01:29:05 +05:30
|
|
|
|
|
|
|
context "when f.lib or f.include is a directory" do
|
|
|
|
it "gives command to be run when f.lib is a directory" do
|
|
|
|
Pathname.new(f.lib).mkpath
|
|
|
|
expect(caveats).to include("-L#{f.opt_lib}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives command to be run when f.include is a directory" do
|
|
|
|
Pathname.new(f.include).mkpath
|
|
|
|
expect(caveats).to include("-I#{f.opt_include}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives PKG_CONFIG_PATH when f.lib/'pkgconfig' and f.share/'pkgconfig' are directories" do
|
|
|
|
allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("blah"))
|
|
|
|
|
|
|
|
Pathname.new(f.share/"pkgconfig").mkpath
|
|
|
|
Pathname.new(f.lib/"pkgconfig").mkpath
|
|
|
|
|
|
|
|
expect(caveats).to include("#{f.opt_lib}/pkgconfig")
|
|
|
|
expect(caveats).to include("#{f.opt_share}/pkgconfig")
|
|
|
|
end
|
|
|
|
end
|
2017-06-20 05:32:13 +05:30
|
|
|
end
|
2017-07-20 03:47:02 +05:30
|
|
|
|
2021-02-19 23:15:33 +00:00
|
|
|
describe "shell completions" do
|
2017-07-20 03:47:02 +05:30
|
|
|
let(:f) {
|
|
|
|
formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
end
|
|
|
|
}
|
|
|
|
let(:caveats) { described_class.new(f).caveats }
|
|
|
|
let(:path) { f.prefix.resolved_path }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow_any_instance_of(Pathname).to receive(:children).and_return([Pathname.new("child")])
|
|
|
|
allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("shell"))
|
2020-11-26 16:08:26 +00:00
|
|
|
allow(Utils::Shell).to receive(:preferred).and_return(nil)
|
|
|
|
allow(Utils::Shell).to receive(:parent).and_return(nil)
|
2017-07-20 03:47:02 +05:30
|
|
|
end
|
|
|
|
|
2020-07-29 17:31:11 -04:00
|
|
|
it "gives dir where Bash completions have been installed" do
|
2017-07-20 03:47:02 +05:30
|
|
|
(path/"etc/bash_completion.d").mkpath
|
|
|
|
expect(caveats).to include(HOMEBREW_PREFIX/"etc/bash_completion.d")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives dir where zsh completions have been installed" do
|
|
|
|
(path/"share/zsh/site-functions").mkpath
|
|
|
|
expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives dir where fish completions have been installed" do
|
|
|
|
(path/"share/fish/vendor_completions.d").mkpath
|
|
|
|
expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
|
|
|
|
end
|
|
|
|
end
|
2017-06-20 05:32:13 +05:30
|
|
|
end
|
2017-02-25 20:10:25 +01:00
|
|
|
end
|