Merge pull request #3389 from amyspark/hacktoberfest-single-zap
Check that a single uninstall_* and zap stanza is defined
This commit is contained in:
		
						commit
						4eeac6f884
					
				@ -31,6 +31,8 @@ module Hbc
 | 
			
		||||
      check_generic_artifacts
 | 
			
		||||
      check_token_conflicts
 | 
			
		||||
      check_download
 | 
			
		||||
      check_single_pre_postflight
 | 
			
		||||
      check_single_uninstall_zap
 | 
			
		||||
      self
 | 
			
		||||
    rescue StandardError => e
 | 
			
		||||
      odebug "#{e.message}\n#{e.backtrace.join("\n")}"
 | 
			
		||||
@ -48,6 +50,36 @@ module Hbc
 | 
			
		||||
 | 
			
		||||
    private
 | 
			
		||||
 | 
			
		||||
    def check_single_pre_postflight
 | 
			
		||||
      odebug "Auditing preflight and postflight stanzas"
 | 
			
		||||
 | 
			
		||||
      if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:preflight) } > 1
 | 
			
		||||
        add_warning "only a single preflight stanza is allowed"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      return unless cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:postflight) } > 1
 | 
			
		||||
      add_warning "only a single postflight stanza is allowed"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def check_single_uninstall_zap
 | 
			
		||||
      odebug "Auditing single uninstall_* and zap stanzas"
 | 
			
		||||
 | 
			
		||||
      if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Uninstall) } > 1
 | 
			
		||||
        add_warning "only a single uninstall stanza is allowed"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:uninstall_preflight) } > 1
 | 
			
		||||
        add_warning "only a single uninstall_preflight stanza is allowed"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:uninstall_postflight) } > 1
 | 
			
		||||
        add_warning "only a single uninstall_postflight stanza is allowed"
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      return unless cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Zap) } > 1
 | 
			
		||||
      add_warning "only a single zap stanza is allowed"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    def check_required_stanzas
 | 
			
		||||
      odebug "Auditing required stanzas"
 | 
			
		||||
      [:version, :sha256, :url, :homepage].each do |sym|
 | 
			
		||||
 | 
			
		||||
@ -91,6 +91,120 @@ describe Hbc::Audit, :cask do
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe "preflight stanza checks" do
 | 
			
		||||
      let(:error_msg) { "only a single preflight stanza is allowed" }
 | 
			
		||||
 | 
			
		||||
      context "when the cask has no preflight stanza" do
 | 
			
		||||
        let(:cask_token) { "with-zap-rmdir" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has only one preflight stanza" do
 | 
			
		||||
        let(:cask_token) { "with-preflight" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has multiple preflight stanzas" do
 | 
			
		||||
        let(:cask_token) { "with-preflight-multi" }
 | 
			
		||||
        it { is_expected.to warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe "uninstall_postflight stanza checks" do
 | 
			
		||||
      let(:error_msg) { "only a single postflight stanza is allowed" }
 | 
			
		||||
 | 
			
		||||
      context "when the cask has no postflight stanza" do
 | 
			
		||||
        let(:cask_token) { "with-zap-rmdir" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has only one postflight stanza" do
 | 
			
		||||
        let(:cask_token) { "with-postflight" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has multiple postflight stanzas" do
 | 
			
		||||
        let(:cask_token) { "with-postflight-multi" }
 | 
			
		||||
        it { is_expected.to warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe "uninstall stanza checks" do
 | 
			
		||||
      let(:error_msg) { "only a single uninstall stanza is allowed" }
 | 
			
		||||
 | 
			
		||||
      context "when the cask has no uninstall stanza" do
 | 
			
		||||
        let(:cask_token) { "with-zap-rmdir" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has only one uninstall stanza" do
 | 
			
		||||
        let(:cask_token) { "with-uninstall-rmdir" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has multiple uninstall stanzas" do
 | 
			
		||||
        let(:cask_token) { "with-uninstall-multi" }
 | 
			
		||||
        it { is_expected.to warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe "uninstall_preflight stanza checks" do
 | 
			
		||||
      let(:error_msg) { "only a single uninstall_preflight stanza is allowed" }
 | 
			
		||||
 | 
			
		||||
      context "when the cask has no uninstall_preflight stanza" do
 | 
			
		||||
        let(:cask_token) { "with-zap-rmdir" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has only one uninstall_preflight stanza" do
 | 
			
		||||
        let(:cask_token) { "with-uninstall-preflight" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has multiple uninstall_preflight stanzas" do
 | 
			
		||||
        let(:cask_token) { "with-uninstall-preflight-multi" }
 | 
			
		||||
        it { is_expected.to warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe "uninstall_postflight stanza checks" do
 | 
			
		||||
      let(:error_msg) { "only a single uninstall_postflight stanza is allowed" }
 | 
			
		||||
 | 
			
		||||
      context "when the cask has no uninstall_postflight stanza" do
 | 
			
		||||
        let(:cask_token) { "with-zap-rmdir" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has only one uninstall_postflight stanza" do
 | 
			
		||||
        let(:cask_token) { "with-uninstall-postflight" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has multiple uninstall_postflight stanzas" do
 | 
			
		||||
        let(:cask_token) { "with-uninstall-postflight-multi" }
 | 
			
		||||
        it { is_expected.to warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe "zap stanza checks" do
 | 
			
		||||
      let(:error_msg) { "only a single zap stanza is allowed" }
 | 
			
		||||
 | 
			
		||||
      context "when the cask has no zap stanza" do
 | 
			
		||||
        let(:cask_token) { "with-uninstall-rmdir" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has only one zap stanza" do
 | 
			
		||||
        let(:cask_token) { "with-zap-rmdir" }
 | 
			
		||||
        it { should_not warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
 | 
			
		||||
      context "when the cask has multiple zap stanzas" do
 | 
			
		||||
        let(:cask_token) { "with-zap-multi" }
 | 
			
		||||
        it { is_expected.to warn_with(error_msg) }
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    describe "version checks" do
 | 
			
		||||
      let(:error_msg) { "you should use version :latest instead of version 'latest'" }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,15 @@
 | 
			
		||||
cask 'with-postflight-multi' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  postflight do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  postflight do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,12 @@
 | 
			
		||||
cask 'with-postflight' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  postflight do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,15 @@
 | 
			
		||||
cask 'with-preflight-multi' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  preflight do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  preflight do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,12 @@
 | 
			
		||||
cask 'with-preflight' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  preflight do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,13 @@
 | 
			
		||||
cask 'with-uninstall-multi' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  uninstall rmdir: "#{TEST_TMPDIR}/empty_directory_path"
 | 
			
		||||
 | 
			
		||||
  uninstall delete: "#{TEST_TMPDIR}/empty_directory_path"
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,15 @@
 | 
			
		||||
cask 'with-uninstall-postflight-multi' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  uninstall_postflight do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  uninstall_postflight do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,12 @@
 | 
			
		||||
cask 'with-uninstall-postflight' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  uninstall_postflight do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,15 @@
 | 
			
		||||
cask 'with-uninstall-preflight-multi' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  uninstall_preflight do
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  uninstall_preflight do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,12 @@
 | 
			
		||||
cask 'with-uninstall-preflight' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  uninstall_preflight do
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,13 @@
 | 
			
		||||
cask 'with-zap-multi' do
 | 
			
		||||
  version '1.2.3'
 | 
			
		||||
  sha256 '8c62a2b791cf5f0da6066a0a4b6e85f62949cd60975da062df44adf887f4370b'
 | 
			
		||||
 | 
			
		||||
  url "file://#{TEST_FIXTURE_DIR}/cask/MyFancyPkg.zip"
 | 
			
		||||
  homepage 'http://example.com/fancy-pkg'
 | 
			
		||||
 | 
			
		||||
  pkg 'MyFancyPkg/Fancy.pkg'
 | 
			
		||||
 | 
			
		||||
  zap rmdir: "#{TEST_TMPDIR}/empty_directory_path"
 | 
			
		||||
 | 
			
		||||
  zap delete: "#{TEST_TMPDIR}/empty_directory_path"
 | 
			
		||||
end
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user