Cask::Audit: Handle livecheck skip conditions

This commit is contained in:
Sam Ford 2021-06-14 12:05:32 -04:00
parent d3887df2a3
commit e8f803bc75
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
6 changed files with 97 additions and 2 deletions

View File

@ -552,8 +552,10 @@ module Cask
def check_livecheck_version
return unless appcast?
return :skip if cask.livecheck.skip?
return :latest if cask.version.latest?
# Respect cask skip conditions (e.g. discontinued, latest, unversioned)
skip_info = Homebrew::Livecheck::SkipConditions.skip_information(cask)
return :skip if skip_info.present?
latest_version = Homebrew::Livecheck.latest_version(cask)&.fetch(:latest)
if cask.version.to_s == latest_version.to_s

View File

@ -411,6 +411,35 @@ describe Cask::Audit, :cask do
end
end
describe "livecheck should be skipped" do
let(:online) { true }
let(:message) { /Version '[^']*' differs from '[^']*' retrieved by livecheck\./ }
context "when the Cask has a livecheck block using skip" do
let(:cask_token) { "livecheck/livecheck-skip" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask is discontinued" do
let(:cask_token) { "livecheck/discontinued" }
it { is_expected.not_to fail_with(message) }
end
context "when version is :latest" do
let(:cask_token) { "livecheck/version-latest" }
it { is_expected.not_to fail_with(message) }
end
context "when url is unversioned" do
let(:cask_token) { "livecheck/url-unversioned" }
it { is_expected.not_to fail_with(message) }
end
end
describe "when the Cask stanza requires uninstall" do
let(:message) { "installer and pkg stanzas require an uninstall stanza" }

View File

@ -0,0 +1,18 @@
cask "discontinued" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
# This cask is used in --online tests, so we use fake URLs to avoid impacting
# real servers. The URL paths are specific enough that they'll be
# understandable if they appear in local server logs.
url "http://localhost/homebrew/test/cask/audit/livecheck/discontinued-#{version}.dmg"
name "Discontinued"
desc "Cask for testing discontinued in livecheck"
homepage "http://localhost/homebrew/test/cask/audit/livecheck/discontinued"
app "TestCask.app"
caveats do
discontinued
end
end

View File

@ -0,0 +1,18 @@
cask "livecheck-skip" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
# This cask is used in --online tests, so we use fake URLs to avoid impacting
# real servers. The URL paths are specific enough that they'll be
# understandable if they appear in local server logs.
url "http://localhost/homebrew/test/cask/audit/livecheck/livecheck-skip-#{version}.dmg"
name "Skip"
desc "Cask for testing skip in a livecheck block"
homepage "http://localhost/homebrew/test/cask/audit/livecheck/livecheck-skip"
livecheck do
skip "No version information available to check"
end
app "TestCask.app"
end

View File

@ -0,0 +1,14 @@
cask "url-unversioned" do
version "1.2.3"
sha256 "8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b"
# This cask is used in --online tests, so we use fake URLs to avoid impacting
# real servers. The URL paths are specific enough that they'll be
# understandable if they appear in local server logs.
url "http://localhost/homebrew/test/cask/audit/livecheck/url-unversioned.dmg"
name "Unversioned URL"
desc "Cask for testing an unversioned URL in livecheck"
homepage "http://localhost/homebrew/test/cask/audit/livecheck/url-unversioned"
app "TestCask.app"
end

View File

@ -0,0 +1,14 @@
cask "version-latest" do
version :latest
sha256 :no_check
# This cask is used in --online tests, so we use fake URLs to avoid impacting
# real servers. The URL paths are specific enough that they'll be
# understandable if they appear in local server logs.
url "http://localhost/homebrew/test/cask/audit/livecheck/version-latest.dmg"
name "Version Latest"
desc "Cask for testing a latest version in livecheck"
homepage "http://localhost/homebrew/test/cask/audit/livecheck/version-latest"
app "TestCask.app"
end