2018-09-06 08:29:14 +02:00
|
|
|
describe Cask::Artifact::Binary, :cask do
|
2016-08-18 22:11:42 +03:00
|
|
|
let(:cask) {
|
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
|
|
|
|
}
|
2017-10-04 17:54:52 +02:00
|
|
|
let(:artifacts) { cask.artifacts.select { |a| a.is_a?(described_class) } }
|
2019-02-02 17:11:37 +01:00
|
|
|
let(:expected_path) { cask.config.binarydir.join("binary") }
|
2017-03-08 16:35:02 +01:00
|
|
|
|
2018-03-25 13:30:37 +01:00
|
|
|
after do
|
2016-08-18 22:11:42 +03:00
|
|
|
FileUtils.rm expected_path if expected_path.exist?
|
|
|
|
end
|
|
|
|
|
2017-05-19 19:13:23 +02:00
|
|
|
context "when --no-binaries is specified" do
|
|
|
|
let(:cask) {
|
2018-09-06 08:29:14 +02:00
|
|
|
Cask::CaskLoader.load(cask_path("with-binary"))
|
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|
|
2018-07-19 23:56:51 +02:00
|
|
|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
|
2017-10-04 17:54:52 +02:00
|
|
|
end
|
2017-07-29 19:55:05 +02:00
|
|
|
|
2017-02-09 19:01:46 +01: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) {
|
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
|
|
|
|
}
|
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|
|
2018-07-19 23:56:51 +02:00
|
|
|
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
|
|
|
|
|
2016-11-29 11:04:45 +01:00
|
|
|
expect {
|
2017-10-04 17:54:52 +02:00
|
|
|
artifacts.each do |artifact|
|
2018-07-19 23:56:51 +02:00
|
|
|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
|
2017-10-04 17:54:52 +02:00
|
|
|
end
|
2018-09-06 08:29:14 +02:00
|
|
|
}.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
|
|
|
|
|
|
|
|
it "clobbers an existing symlink" do
|
|
|
|
expected_path.make_symlink("/tmp")
|
|
|
|
|
2017-10-04 17:54:52 +02:00
|
|
|
artifacts.each do |artifact|
|
2018-07-19 23:56:51 +02:00
|
|
|
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(File.readlink(expected_path)).not_to eq("/tmp")
|
|
|
|
end
|
|
|
|
|
|
|
|
it "creates parent directory if it doesn't exist" do
|
2018-09-06 08:29:14 +02:00
|
|
|
FileUtils.rmdir Cask::Config.global.binarydir
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-10-04 17:54:52 +02:00
|
|
|
artifacts.each do |artifact|
|
2018-07-19 23:56:51 +02:00
|
|
|
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 "binary is inside an app package" do
|
|
|
|
let(:cask) {
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
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|
|
2018-07-19 23:56:51 +02:00
|
|
|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
|
2017-10-04 17:54:52 +02:00
|
|
|
end
|
|
|
|
artifacts.each do |artifact|
|
2018-07-19 23:56:51 +02:00
|
|
|
artifact.install_phase(command: NeverSudoSystemCommand, force: false)
|
2017-10-04 17:54:52 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-02-09 19:01:46 +01: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
|