2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-25 20:10:25 +01:00
|
|
|
require "formula"
|
|
|
|
require "caveats"
|
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.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
|
2023-03-10 23:46:07 +00:00
|
|
|
expect(caveats.formula).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
|
2024-05-07 12:01:26 +01:00
|
|
|
context "when service block is defined" do
|
2023-04-13 23:33:31 -07:00
|
|
|
before do
|
2024-05-07 12:01:26 +01:00
|
|
|
allow(Utils::Service).to receive_messages(launchctl?: true, systemctl?: true)
|
2017-06-20 05:32:13 +05:30
|
|
|
end
|
2017-07-21 06:38:45 +05:30
|
|
|
|
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
|
|
|
|
|
2022-03-01 00:02:36 +00:00
|
|
|
expect(f.service?).to be(true)
|
2021-09-02 09:26:34 -06:00
|
|
|
expect(caveats).to include("#{f.bin}/php test")
|
|
|
|
expect(caveats).to include("background service")
|
|
|
|
end
|
|
|
|
|
2023-07-17 12:30:12 -07:00
|
|
|
it "prints warning when no service daemon is found" do
|
2017-07-21 06:38:45 +05:30
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
2021-08-23 22:52:36 +02:00
|
|
|
service do
|
|
|
|
run [bin/"cmd"]
|
2017-07-21 06:38:45 +05:30
|
|
|
end
|
|
|
|
end
|
2024-05-07 12:01:26 +01:00
|
|
|
expect(Utils::Service).to receive(:launchctl?).and_return(false)
|
|
|
|
expect(Utils::Service).to receive(:systemctl?).and_return(false)
|
2021-08-23 22:52:36 +02:00
|
|
|
expect(described_class.new(f).caveats).to include("service which can only be used on macOS or systemd!")
|
|
|
|
end
|
|
|
|
|
2023-02-07 19:25:51 +01:00
|
|
|
it "prints service startup information when service.require_root is true" do
|
2021-08-23 22:52:36 +02:00
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
|
|
|
run [bin/"cmd"]
|
2023-02-07 19:25:51 +01:00
|
|
|
require_root true
|
2021-08-23 22:52:36 +02:00
|
|
|
end
|
|
|
|
end
|
2023-04-13 23:33:31 -07:00
|
|
|
expect(Utils::Service).to receive(:running?).with(f).once.and_return(false)
|
2021-08-23 22:52:36 +02:00
|
|
|
expect(described_class.new(f).caveats).to include("startup")
|
|
|
|
end
|
|
|
|
|
2024-05-07 19:31:28 +01:00
|
|
|
it "prints service login information" do
|
2021-08-23 22:52:36 +02:00
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
|
|
|
run [bin/"cmd"]
|
|
|
|
end
|
|
|
|
end
|
2023-04-13 23:33:31 -07:00
|
|
|
expect(Utils::Service).to receive(:running?).with(f).once.and_return(false)
|
|
|
|
expect(described_class.new(f).caveats).to include("restart at login")
|
2021-08-23 22:52:36 +02:00
|
|
|
end
|
|
|
|
|
2022-12-05 12:12:38 +01:00
|
|
|
it "gives information about require_root restarting services after upgrade" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
|
|
|
run [bin/"cmd"]
|
|
|
|
require_root true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
f_obj = described_class.new(f)
|
2023-04-13 23:33:31 -07:00
|
|
|
expect(Utils::Service).to receive(:running?).with(f).once.and_return(true)
|
2022-12-05 12:12:38 +01:00
|
|
|
expect(f_obj.caveats).to include(" sudo brew services restart #{f.full_name}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives information about user restarting services after upgrade" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
|
|
|
run [bin/"cmd"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
f_obj = described_class.new(f)
|
2023-04-13 23:33:31 -07:00
|
|
|
expect(Utils::Service).to receive(:running?).with(f).once.and_return(true)
|
2022-12-05 12:12:38 +01:00
|
|
|
expect(f_obj.caveats).to include(" brew services restart #{f.full_name}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives information about require_root starting services after upgrade" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
|
|
|
run [bin/"cmd"]
|
|
|
|
require_root true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
f_obj = described_class.new(f)
|
2023-04-13 23:33:31 -07:00
|
|
|
expect(Utils::Service).to receive(:running?).with(f).once.and_return(false)
|
2022-12-05 12:12:38 +01:00
|
|
|
expect(f_obj.caveats).to include(" sudo brew services start #{f.full_name}")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "gives information about user starting services after upgrade" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
|
|
|
run [bin/"cmd"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
f_obj = described_class.new(f)
|
2023-04-13 23:33:31 -07:00
|
|
|
expect(Utils::Service).to receive(:running?).with(f).once.and_return(false)
|
2022-12-05 12:12:38 +01:00
|
|
|
expect(f_obj.caveats).to include(" brew services start #{f.full_name}")
|
2021-08-23 22:52:36 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it "gives information about service manual command" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
|
|
|
run [bin/"cmd", "start"]
|
|
|
|
environment_variables VAR: "foo"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
cmd = "#{HOMEBREW_CELLAR}/formula_name/1.0/bin/cmd"
|
2017-07-21 06:38:45 +05:30
|
|
|
caveats = described_class.new(f).caveats
|
|
|
|
|
2022-12-05 12:12:38 +01:00
|
|
|
expect(caveats).to include("if you don't want/need a background service")
|
2021-08-23 22:52:36 +02:00
|
|
|
expect(caveats).to include("VAR=\"foo\" #{cmd} start")
|
2017-07-21 06:38:45 +05:30
|
|
|
end
|
2023-04-13 23:33:31 -07:00
|
|
|
|
|
|
|
it "prints info when there are custom service files" do
|
|
|
|
f = formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
service do
|
2023-05-13 12:35:50 -07:00
|
|
|
name macos: "custom.mxcl.foo", linux: "custom.foo"
|
2023-04-13 23:33:31 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
expect(Utils::Service).to receive(:installed?).with(f).once.and_return(true)
|
|
|
|
expect(Utils::Service).to receive(:running?).with(f).once.and_return(false)
|
|
|
|
expect(described_class.new(f).caveats).to include("restart at login")
|
|
|
|
end
|
2017-06-20 05:32:13 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context "when f.keg_only is not nil" do
|
2023-03-08 23:14:46 +00:00
|
|
|
let(:f) do
|
2017-07-18 01:29:05 +05:30
|
|
|
formula do
|
2017-06-20 05:32:13 +05:30
|
|
|
url "foo-1.0"
|
|
|
|
keg_only "some reason"
|
|
|
|
end
|
2023-03-08 23:14:46 +00:00
|
|
|
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
|
2023-03-19 18:25:56 +00:00
|
|
|
|
|
|
|
context "when joining different caveat types together" do
|
|
|
|
let(:f) do
|
|
|
|
formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
keg_only "some reason"
|
|
|
|
|
|
|
|
def caveats
|
|
|
|
"something else"
|
|
|
|
end
|
|
|
|
|
|
|
|
service do
|
|
|
|
run [bin/"cmd"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:caveats) { described_class.new(f).caveats }
|
|
|
|
|
|
|
|
it "adds the correct amount of new lines to the output" do
|
2023-12-07 03:06:47 +00:00
|
|
|
expect(Utils::Service).to receive(:launchctl?).at_least(:once).and_return(true)
|
2023-03-19 18:25:56 +00:00
|
|
|
expect(caveats).to include("something else")
|
|
|
|
expect(caveats).to include("keg-only")
|
|
|
|
expect(caveats).to include("if you don't want/need a background service")
|
|
|
|
expect(caveats.count("\n")).to eq(9)
|
|
|
|
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
|
2023-03-08 23:14:46 +00:00
|
|
|
let(:f) do
|
2017-07-20 03:47:02 +05:30
|
|
|
formula do
|
|
|
|
url "foo-1.0"
|
|
|
|
end
|
2023-03-08 23:14:46 +00:00
|
|
|
end
|
2017-07-20 03:47:02 +05:30
|
|
|
let(:caveats) { described_class.new(f).caveats }
|
|
|
|
let(:path) { f.prefix.resolved_path }
|
|
|
|
|
2024-02-13 18:46:58 +01:00
|
|
|
let(:bash_completion_dir) { path/"etc/bash_completion.d" }
|
|
|
|
let(:fish_vendor_completions) { path/"share/fish/vendor_completions.d" }
|
|
|
|
let(:zsh_site_functions) { path/"share/zsh/site-functions" }
|
2025-03-02 18:17:38 -08:00
|
|
|
let(:pwsh_completion_dir) { path/"share/pwsh/completions" }
|
2024-02-13 18:46:58 +01:00
|
|
|
|
2017-07-20 03:47:02 +05:30
|
|
|
before do
|
2022-11-09 14:45:43 +00:00
|
|
|
# don't try to load/fetch gcc/glibc
|
2023-12-14 02:52:30 +00:00
|
|
|
allow(DevelopmentTools).to receive_messages(needs_libc_formula?: false, needs_compiler_formula?: false)
|
2022-11-09 14:45:43 +00:00
|
|
|
|
2017-07-20 03:47:02 +05:30
|
|
|
allow_any_instance_of(Object).to receive(:which).with(any_args).and_return(Pathname.new("shell"))
|
2023-12-14 02:52:30 +00:00
|
|
|
allow(Utils::Shell).to receive_messages(preferred: nil, parent: nil)
|
2017-07-20 03:47:02 +05:30
|
|
|
end
|
|
|
|
|
2024-02-13 18:46:58 +01:00
|
|
|
it "includes where Bash completions have been installed to" do
|
|
|
|
bash_completion_dir.mkpath
|
|
|
|
FileUtils.touch bash_completion_dir/f.name
|
2017-07-20 03:47:02 +05:30
|
|
|
expect(caveats).to include(HOMEBREW_PREFIX/"etc/bash_completion.d")
|
|
|
|
end
|
|
|
|
|
2024-02-13 18:46:58 +01:00
|
|
|
it "includes where fish completions have been installed to" do
|
|
|
|
fish_vendor_completions.mkpath
|
|
|
|
FileUtils.touch fish_vendor_completions/f.name
|
|
|
|
expect(caveats).to include(HOMEBREW_PREFIX/"share/fish/vendor_completions.d")
|
2017-07-20 03:47:02 +05:30
|
|
|
end
|
|
|
|
|
2024-02-13 18:46:58 +01:00
|
|
|
it "includes where zsh completions have been installed to" do
|
|
|
|
zsh_site_functions.mkpath
|
|
|
|
FileUtils.touch zsh_site_functions/f.name
|
|
|
|
expect(caveats).to include(HOMEBREW_PREFIX/"share/zsh/site-functions")
|
2017-07-20 03:47:02 +05:30
|
|
|
end
|
2025-03-02 18:17:38 -08:00
|
|
|
|
|
|
|
it "includes where pwsh completions have been installed to" do
|
|
|
|
pwsh_completion_dir.mkpath
|
|
|
|
FileUtils.touch pwsh_completion_dir/f.name
|
|
|
|
expect(caveats).to include(HOMEBREW_PREFIX/"share/pwsh/completions")
|
|
|
|
end
|
2017-07-20 03:47:02 +05:30
|
|
|
end
|
2017-06-20 05:32:13 +05:30
|
|
|
end
|
2017-02-25 20:10:25 +01:00
|
|
|
end
|