Merge pull request #9531 from reitermarkus/tilde-artifact-targets
Properly handle `~` artifact targets.
This commit is contained in:
commit
d49f31cdea
@ -1,4 +1,4 @@
|
||||
# typed: false
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "cask/artifact/moved"
|
||||
@ -19,25 +19,26 @@ module Cask
|
||||
"Generic Artifact"
|
||||
end
|
||||
|
||||
sig { params(cask: Cask, args: T.untyped).returns(T.attached_class) }
|
||||
def self.from_args(cask, *args)
|
||||
source_string, target_hash = args
|
||||
source, options = args
|
||||
|
||||
raise CaskInvalidError.new(cask.token, "no source given for #{english_name}") if source_string.nil?
|
||||
raise CaskInvalidError.new(cask.token, "No source provided for #{english_name}.") if source.blank?
|
||||
|
||||
unless target_hash.is_a?(Hash)
|
||||
raise CaskInvalidError.new(cask.token, "target required for #{english_name} '#{source_string}'")
|
||||
unless options.try(:key?, :target)
|
||||
raise CaskInvalidError.new(cask.token, "#{english_name} '#{source}' requires a target.")
|
||||
end
|
||||
|
||||
target_hash.assert_valid_keys!(:target)
|
||||
|
||||
new(cask, source_string, **target_hash)
|
||||
new(cask, source, **options)
|
||||
end
|
||||
|
||||
sig { params(target: T.any(String, Pathname)).returns(Pathname) }
|
||||
def resolve_target(target)
|
||||
Pathname(target)
|
||||
super(target, base_dir: nil)
|
||||
end
|
||||
|
||||
def initialize(cask, source, target: nil)
|
||||
sig { params(cask: Cask, source: T.any(String, Pathname), target: T.any(String, Pathname)).void }
|
||||
def initialize(cask, source, target:)
|
||||
super(cask, source, target: target)
|
||||
end
|
||||
end
|
||||
|
@ -28,12 +28,23 @@ module Cask
|
||||
new(cask, source_string, **target_hash)
|
||||
end
|
||||
|
||||
def resolve_target(target)
|
||||
config.public_send(self.class.dirmethod).join(target)
|
||||
def resolve_target(target, base_dir: config.public_send(self.class.dirmethod))
|
||||
target = Pathname(target)
|
||||
|
||||
if target.relative?
|
||||
return target.expand_path if target.descend.first.to_s == "~"
|
||||
return base_dir/target if base_dir
|
||||
end
|
||||
|
||||
target
|
||||
end
|
||||
|
||||
attr_reader :source, :target
|
||||
|
||||
sig do
|
||||
params(cask: Cask, source: T.nilable(T.any(String, Pathname)), target: T.nilable(T.any(String, Pathname)))
|
||||
.void
|
||||
end
|
||||
def initialize(cask, source, target: nil)
|
||||
super(cask)
|
||||
|
||||
|
@ -5,5 +5,7 @@ module Cask
|
||||
def artifacts; end
|
||||
|
||||
def homepage; end
|
||||
|
||||
def staged_path; end
|
||||
end
|
||||
end
|
||||
|
@ -23,7 +23,23 @@ describe Cask::Artifact::Artifact, :cask do
|
||||
it "fails to load" do
|
||||
expect {
|
||||
Cask::CaskLoader.load(cask_path("invalid/invalid-generic-artifact-no-target"))
|
||||
}.to raise_error(Cask::CaskInvalidError, /target required for Generic Artifact/)
|
||||
}.to raise_error(Cask::CaskInvalidError, /Generic Artifact.*requires.*target/)
|
||||
end
|
||||
end
|
||||
|
||||
context "with relative target" do
|
||||
it "does not fail to load" do
|
||||
expect {
|
||||
Cask::CaskLoader.load(cask_path("generic-artifact-relative-target"))
|
||||
}.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
context "with user-relative target" do
|
||||
it "does not fail to load" do
|
||||
expect {
|
||||
Cask::CaskLoader.load(cask_path("generic-artifact-user-relative-target"))
|
||||
}.not_to raise_error
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -756,13 +756,19 @@ describe Cask::Audit, :cask do
|
||||
context "with relative target" do
|
||||
let(:cask_token) { "generic-artifact-relative-target" }
|
||||
|
||||
it { is_expected.to fail_with(/target must be absolute path for Generic Artifact/) }
|
||||
it { is_expected.to fail_with(/target must be.*absolute/) }
|
||||
end
|
||||
|
||||
context "with user-relative target" do
|
||||
let(:cask_token) { "generic-artifact-user-relative-target" }
|
||||
|
||||
it { is_expected.not_to fail_with(/target must be.*absolute/) }
|
||||
end
|
||||
|
||||
context "with absolute target" do
|
||||
let(:cask_token) { "generic-artifact-absolute-target" }
|
||||
|
||||
it { is_expected.not_to fail_with(/target required for Generic Artifact/) }
|
||||
it { is_expected.not_to fail_with(/target must be.*absolute/) }
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -0,0 +1,11 @@
|
||||
cask "generic-artifact-user-relative-target" do
|
||||
version "1.2.3"
|
||||
sha256 "d5b2dfbef7ea28c25f7a77cd7fa14d013d82b626db1d82e00e25822464ba19e2"
|
||||
|
||||
url "file://#{TEST_FIXTURE_DIR}/cask/AppWithBinary.zip"
|
||||
name "With Binary"
|
||||
desc "Cask with a binary stanza"
|
||||
homepage "https://brew.sh/with-binary"
|
||||
|
||||
artifact "Caffeine.app", target: "~/Desktop/Caffeine.app"
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user