From e8f803bc7531f22891ab299e224b0761f1f3a2b5 Mon Sep 17 00:00:00 2001 From: Sam Ford <1584702+samford@users.noreply.github.com> Date: Mon, 14 Jun 2021 12:05:32 -0400 Subject: [PATCH] Cask::Audit: Handle livecheck skip conditions --- Library/Homebrew/cask/audit.rb | 6 ++-- Library/Homebrew/test/cask/audit_spec.rb | 29 +++++++++++++++++++ .../cask/Casks/livecheck/discontinued.rb | 18 ++++++++++++ .../cask/Casks/livecheck/livecheck-skip.rb | 18 ++++++++++++ .../cask/Casks/livecheck/url-unversioned.rb | 14 +++++++++ .../cask/Casks/livecheck/version-latest.rb | 14 +++++++++ 6 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/discontinued.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-skip.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/url-unversioned.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/version-latest.rb diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 70821958b5..3f1bcce808 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -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 diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index dc8600afc4..693d864093 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -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" } diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/discontinued.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/discontinued.rb new file mode 100644 index 0000000000..eb9a50c816 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/discontinued.rb @@ -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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-skip.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-skip.rb new file mode 100644 index 0000000000..7b841ed505 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/livecheck-skip.rb @@ -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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/url-unversioned.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/url-unversioned.rb new file mode 100644 index 0000000000..c696ae0696 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/url-unversioned.rb @@ -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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/version-latest.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/version-latest.rb new file mode 100644 index 0000000000..37286c09c2 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/livecheck/version-latest.rb @@ -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