118 lines
3.3 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
RSpec.describe Cask::Artifact::Binary, :cask do
let(:cask) do
2018-09-06 08:29:14 +02:00
Cask::CaskLoader.load(cask_path("with-binary")).tap do |cask|
2017-07-29 19:55:05 +02:00
InstallHelper.install_without_artifacts(cask)
2016-08-18 22:11:42 +03:00
end
end
2017-10-04 17:54:52 +02:00
let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } }
2020-09-29 23:46:30 +02:00
let(:binarydir) { cask.config.binarydir }
let(:expected_path) { binarydir.join("binary") }
2017-03-08 16:35:02 +01:00
2020-09-29 23:46:30 +02:00
around do |example|
binarydir.mkpath
example.run
ensure
FileUtils.rm_f expected_path
FileUtils.rmdir binarydir
2016-08-18 22:11:42 +03:00
end
2017-05-19 19:13:23 +02:00
context "when --no-binaries is specified" do
let(:cask) do
2018-09-06 08:29:14 +02:00
Cask::CaskLoader.load(cask_path("with-binary"))
end
2017-05-19 19:13:23 +02:00
it "doesn't link the binary when --no-binaries is specified" do
2018-09-06 08:29:14 +02:00
Cask::Installer.new(cask, binaries: false).install
2017-05-19 19:13:23 +02:00
expect(expected_path).not_to exist
end
end
2016-08-18 22:11:42 +03:00
it "links the binary to the proper directory" do
2017-10-04 17:54:52 +02:00
artifacts.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
2017-10-04 17:54:52 +02:00
end
2017-07-29 19:55:05 +02:00
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to exist
2016-08-18 22:11:42 +03:00
end
2017-04-21 14:50:23 +02:00
context "when the binary is not executable" do
let(:cask) do
2018-09-06 08:29:14 +02:00
Cask::CaskLoader.load(cask_path("with-non-executable-binary")).tap do |cask|
2017-07-29 19:55:05 +02:00
InstallHelper.install_without_artifacts(cask)
2017-04-21 14:50:23 +02:00
end
end
2017-03-08 16:35:02 +01:00
2019-02-02 17:11:37 +01:00
let(:expected_path) { cask.config.binarydir.join("naked_non_executable") }
2017-03-08 16:35:02 +01:00
2017-04-21 14:50:23 +02:00
it "makes the binary executable" do
expect(FileUtils).to receive(:chmod)
.with("+x", cask.staged_path.join("naked_non_executable")).and_call_original
2017-10-04 17:54:52 +02:00
artifacts.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
2017-10-04 17:54:52 +02:00
end
2017-04-21 14:50:23 +02:00
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to be_executable
end
2017-03-08 16:35:02 +01:00
end
2016-08-18 22:11:42 +03:00
it "avoids clobbering an existing binary by linking over it" do
FileUtils.touch expected_path
expect do
2017-10-04 17:54:52 +02:00
artifacts.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
2017-10-04 17:54:52 +02:00
end
end.to raise_error(Cask::CaskError)
2016-08-18 22:11:42 +03:00
2016-08-27 11:52:14 +02:00
expect(expected_path).not_to be :symlink?
2016-08-18 22:11:42 +03:00
end
2020-08-17 19:39:27 +08:00
it "avoids clobbering an existing symlink" do
2016-08-18 22:11:42 +03:00
expected_path.make_symlink("/tmp")
expect do
2020-08-17 19:39:27 +08:00
artifacts.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
end
end.to raise_error(Cask::CaskError)
2016-08-18 22:11:42 +03:00
2020-08-17 19:39:27 +08:00
expect(File.readlink(expected_path)).to eq("/tmp")
2016-08-18 22:11:42 +03:00
end
it "creates parent directory if it doesn't exist" do
2020-09-29 23:46:30 +02:00
FileUtils.rmdir binarydir
2016-08-18 22:11:42 +03:00
2017-10-04 17:54:52 +02:00
artifacts.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
2017-10-04 17:54:52 +02:00
end
2016-08-18 22:11:42 +03:00
expect(expected_path.exist?).to be true
end
context "when the binary is inside an app package" do
let(:cask) do
2018-09-06 08:29:14 +02:00
Cask::CaskLoader.load(cask_path("with-embedded-binary")).tap do |cask|
2017-07-29 19:55:05 +02:00
InstallHelper.install_without_artifacts(cask)
2016-08-18 22:11:42 +03:00
end
end
2016-08-18 22:11:42 +03:00
it "links the binary to the proper directory" do
2018-09-06 08:29:14 +02:00
cask.artifacts.select { |a| a.is_a?(Cask::Artifact::App) }.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
2017-10-04 17:54:52 +02:00
end
artifacts.each do |artifact|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
2017-10-04 17:54:52 +02:00
end
2016-08-18 22:11:42 +03:00
expect(expected_path).to be_a_symlink
expect(expected_path.readlink).to exist
2016-08-18 22:11:42 +03:00
end
end
end