mirror of
https://github.com/Homebrew/brew.git
synced 2026-08-12 22:29:27 +04:00
Require an installable artifact when auditing casks
Signed-off-by: Patrick Linnane <patrick@linnane.io>
This commit is contained in:
@@ -344,10 +344,19 @@ module Cask
|
||||
add_error "a #{sym} stanza is required" unless cask.public_send(sym)
|
||||
end
|
||||
add_error "at least one name stanza is required" if cask.name.empty?
|
||||
# TODO: specific DSL knowledge should not be spread around in various files like this
|
||||
rejected_artifacts = [:uninstall, :zap]
|
||||
installable_artifacts = cask.artifacts.reject { |k| rejected_artifacts.include?(k) }
|
||||
add_error "at least one activatable artifact stanza is required" if installable_artifacts.empty?
|
||||
|
||||
installable_artifact = if cask.on_system_blocks_exist?
|
||||
begin
|
||||
OnSystem::VALID_OS_ARCH_TAGS.any? do |tag|
|
||||
cask.refresh_for_tag(tag) { cask.installable_artifact? }
|
||||
end
|
||||
ensure
|
||||
cask.refresh
|
||||
end
|
||||
else
|
||||
cask.installable_artifact?
|
||||
end
|
||||
add_error "at least one installable artifact stanza is required" unless installable_artifact
|
||||
end
|
||||
|
||||
sig { void }
|
||||
|
||||
@@ -170,6 +170,42 @@ RSpec.describe Cask::Audit, :cask do
|
||||
it { is_expected.to error_with(/#{stanza} stanza is required/) }
|
||||
end
|
||||
end
|
||||
|
||||
context "when a cask has only uninstall artifacts" do
|
||||
let(:cask) do
|
||||
Cask::Cask.new("uninstall-only") do
|
||||
version :latest
|
||||
sha256 :no_check
|
||||
url "https://brew.sh/foo.pkg"
|
||||
name "Uninstall Only"
|
||||
homepage "https://brew.sh/"
|
||||
uninstall pkgutil: "org.example.foo"
|
||||
zap trash: "~/Library/Caches/org.example.foo"
|
||||
end
|
||||
end
|
||||
|
||||
it { is_expected.to error_with("at least one installable artifact stanza is required") }
|
||||
end
|
||||
|
||||
context "when a cask has an installable artifact only on Linux" do
|
||||
let(:cask) do
|
||||
Homebrew::SimulateSystem.with(os: :sequoia, arch: :arm) do
|
||||
Cask::Cask.new("linux-only-artifact") do
|
||||
version :latest
|
||||
sha256 :no_check
|
||||
url "https://brew.sh/foo"
|
||||
name "Linux Only Artifact"
|
||||
homepage "https://brew.sh/"
|
||||
|
||||
on_linux do
|
||||
binary "foo"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
it { is_expected.not_to error_with("at least one installable artifact stanza is required") }
|
||||
end
|
||||
end
|
||||
|
||||
describe "checking homepage availability" do
|
||||
|
||||
Reference in New Issue
Block a user