diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 54c6296438..d83bcd5e0f 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -35,6 +35,7 @@ module Hbc check_single_uninstall_zap check_untrusted_pkg check_github_releases_appcast + check_latest_with_appcast self rescue StandardError => e odebug "#{e.message}\n#{e.backtrace.join("\n")}" @@ -228,6 +229,13 @@ module Hbc end end + def check_latest_with_appcast + return unless cask.version.latest? + return unless cask.appcast + + add_warning "Casks with an appcast should not use version :latest" + end + def check_github_releases_appcast return if cask.appcast return unless cask.url.to_s =~ %r{github.com/([^/]+)/([^/]+)/releases/download/(\S+)} diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 091e8bbb85..20d75872c5 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -387,6 +387,25 @@ describe Hbc::Audit, :cask do end end + describe "latest with appcast checks" do + let(:error_msg) { "Casks with an appcast should not use version :latest" } + + context "when the Cask is :latest and does not have an appcast" do + let(:cask_token) { "version-latest" } + it { should_not warn_with(error_msg) } + end + + context "when the Cask is versioned and has an appcast" do + let(:cask_token) { "with-appcast" } + it { should_not warn_with(error_msg) } + end + + context "when the Cask is :latest and has an appcast" do + let(:cask_token) { "latest-with-appcast" } + it { is_expected.to warn_with(error_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-appcast.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/latest-with-appcast.rb new file mode 100644 index 0000000000..12b0b3e619 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/latest-with-appcast.rb @@ -0,0 +1,11 @@ +cask 'latest-with-appcast' do + version :latest + sha256 :no_check + + url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip" + appcast 'http://example.com/appcast.xml', + checkpoint: '67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94' + homepage 'http://example.com/with-appcast' + + app 'Caffeine.app' +end