diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index db56cff872..9ed6f68a96 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -36,6 +36,7 @@ module Hbc check_untrusted_pkg check_hosting_with_appcast check_latest_with_appcast + check_latest_with_auto_updates check_stanza_requires_uninstall self rescue StandardError => e @@ -199,6 +200,13 @@ module Hbc add_warning "Casks with an appcast should not use version :latest" end + def check_latest_with_auto_updates + return unless cask.version.latest? + return unless cask.auto_updates + + add_warning "Casks with `version :latest` should not use `auto_updates`" + end + def check_hosting_with_appcast return if cask.appcast diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 82487982a9..8d5b2fdd59 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -413,6 +413,34 @@ describe Hbc::Audit, :cask do end end + describe "latest with auto_updates checks" do + let(:warning_msg) { "Casks with `version :latest` should not use `auto_updates`" } + + context "when the Cask is :latest and does not have auto_updates" do + let(:cask_token) { "version-latest" } + + it { is_expected.not_to warn_with(warning_msg) } + end + + context "when the Cask is versioned and does not have auto_updates" do + let(:cask_token) { "basic-cask" } + + it { is_expected.not_to warn_with(warning_msg) } + end + + context "when the Cask is versioned and has auto_updates" do + let(:cask_token) { "auto-updates" } + + it { is_expected.not_to warn_with(warning_msg) } + end + + context "when the Cask is :latest and has auto_updates" do + let(:cask_token) { "latest-with-auto-updates" } + + it { is_expected.to warn_with(warning_msg) } + end + end + describe "preferred download URL formats" do let(:warning_msg) { /URL format incorrect/ } diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/latest-with-auto-updates.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/latest-with-auto-updates.rb new file mode 100644 index 0000000000..6b2162b3c4 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/latest-with-auto-updates.rb @@ -0,0 +1,11 @@ +cask 'latest-with-auto-updates' do + version :latest + sha256 :no_check + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + homepage 'http://example.com/latest-with-auto-updates' + + auto_updates true + + app 'Caffeine.app' +end