Merge pull request #8285 from reitermarkus/desc-audit

Ensure new casks have a description.
This commit is contained in:
Markus Reiter 2020-08-10 20:16:11 +02:00 committed by GitHub
commit deea71b1d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 70 additions and 6 deletions

View File

@ -13,7 +13,7 @@ module Cask
attr_reader :cask, :commit_range, :download
attr_predicate :appcast?
attr_predicate :appcast?, :new_cask?, :strict?, :online?
def initialize(cask, appcast: false, download: false, quarantine: nil,
token_conflicts: false, online: false, strict: false,
@ -34,6 +34,7 @@ module Cask
check_required_stanzas
check_version
check_sha256
check_desc
check_url
check_generic_artifacts
check_token_valid
@ -279,6 +280,14 @@ module Cask
end
end
def check_desc
return unless new_cask?
return if cask.desc.present?
add_warning "Cask should have a description. Please add a `desc` stanza."
end
def check_url
return unless cask.url
@ -339,7 +348,7 @@ module Cask
end
def check_token_valid
return unless @strict
return unless strict?
add_warning "cask token is not lowercase" if cask.token.downcase!
@ -365,7 +374,7 @@ module Cask
end
def check_token_bad_words
return unless @strict
return unless strict?
token = cask.token
@ -467,8 +476,8 @@ module Cask
end
def get_repo_data(regex)
return unless @online
return unless @new_cask
return unless online?
return unless new_cask?
_, user, repo = *regex.match(cask.url.to_s)
_, user, repo = *regex.match(cask.homepage) unless user

View File

@ -33,12 +33,14 @@ describe Cask::Audit, :cask do
let(:download) { false }
let(:token_conflicts) { false }
let(:strict) { false }
let(:new_cask) { false }
let(:fake_system_command) { class_double(SystemCommand) }
let(:audit) {
described_class.new(cask, download: download,
token_conflicts: token_conflicts,
command: fake_system_command,
strict: strict)
strict: strict,
new_cask: new_cask)
}
describe "#result" do
@ -790,5 +792,58 @@ describe Cask::Audit, :cask do
expect(subject).to fail_with(/exception while auditing/)
end
end
describe "without description" do
let(:cask_token) { "without-description" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask '#{cask_token}' do
version '1.0'
sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a'
url "https://brew.sh/"
name 'Audit'
homepage 'https://brew.sh/'
app 'Audit.app'
end
RUBY
end
context "when `new_cask` is true" do
let(:new_cask) { true }
it "warns" do
expect(subject).to warn_with(/should have a description/)
end
end
context "when `new_cask` is true" do
let(:new_cask) { false }
it "does not warn" do
expect(subject).not_to warn_with(/should have a description/)
end
end
end
context "with description" do
let(:cask_token) { "with-description" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask '#{cask_token}' do
version '1.0'
sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a'
url "https://brew.sh/"
name 'Audit'
desc 'Cask Auditor'
homepage 'https://brew.sh/'
app 'Audit.app'
end
RUBY
end
it "does not warn" do
expect(subject).not_to warn_with(/should have a description/)
end
end
end
end