From 809e82038894da86a49f634e2b798db21e09a852 Mon Sep 17 00:00:00 2001 From: L. E. Segovia Date: Fri, 27 Oct 2017 16:53:22 -0300 Subject: Check that a single uninstall_* and zap stanzas is defined --- Library/Homebrew/cask/lib/hbc/audit.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Library') diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 5180c5688..e4349dc2d 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -31,6 +31,7 @@ module Hbc check_generic_artifacts check_token_conflicts check_download + check_single_uninstall_zap self rescue StandardError => e odebug "#{e.message}\n#{e.backtrace.join("\n")}" @@ -48,6 +49,22 @@ module Hbc private + def check_single_uninstall_zap + odebug "Auditing single uninstall_* and zap stanzas" + + uninstalls = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Uninstall) } + add_warning "there should be a single uninstall stanza" unless uninstalls.size <= 1 + + uninstalls_preflight = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.keys.include?("uninstall_preflight") } + add_warning "there should be a single uninstall_preflight stanza" unless uninstalls_preflight.size <= 1 + + uninstalls_postflight = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.keys.include?("uninstall_postflight") } + add_warning "there should be a single uninstall_postflight stanza" unless uninstalls_postflight.size <= 1 + + zaps = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Zap) } + add_warning "there should be a single zap stanza" unless zaps.size <= 1 + end + def check_required_stanzas odebug "Auditing required stanzas" [:version, :sha256, :url, :homepage].each do |sym| -- cgit v1.2.3 From 9b6b0bfed7f0ebf461d21dba9ba12ad340e20508 Mon Sep 17 00:00:00 2001 From: L. E. Segovia Date: Mon, 30 Oct 2017 20:47:22 -0300 Subject: Use #count, rewrite warning, and add pre/postflight checks too --- Library/Homebrew/cask/lib/hbc/audit.rb | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index e4349dc2d..4a5a40e4f 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -31,6 +31,7 @@ module Hbc check_generic_artifacts check_token_conflicts check_download + check_single_pre_postflight check_single_uninstall_zap self rescue StandardError => e @@ -49,20 +50,24 @@ module Hbc private + def check_single_pre_postflight + odebug "Auditing preflight and postflight stanzas" + + add_warning "only a single preflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:preflight) } > 1 + + add_warning "only a single postflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:postflight) } > 1 + end + def check_single_uninstall_zap odebug "Auditing single uninstall_* and zap stanzas" - uninstalls = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Uninstall) } - add_warning "there should be a single uninstall stanza" unless uninstalls.size <= 1 + add_warning "only a single uninstall stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Uninstall) } > 1 - uninstalls_preflight = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.keys.include?("uninstall_preflight") } - add_warning "there should be a single uninstall_preflight stanza" unless uninstalls_preflight.size <= 1 + add_warning "only a single uninstall_preflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:uninstall_preflight) } > 1 - uninstalls_postflight = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.keys.include?("uninstall_postflight") } - add_warning "there should be a single uninstall_postflight stanza" unless uninstalls_postflight.size <= 1 + add_warning "only a single uninstall_postflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:uninstall_postflight) } > 1 - zaps = cask.artifacts.find_all { |k| k.is_a?(Hbc::Artifact::Zap) } - add_warning "there should be a single zap stanza" unless zaps.size <= 1 + add_warning "only a single zap stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Zap) } > 1 end def check_required_stanzas -- cgit v1.2.3 From 917c138eeb4af0cee212f94edc425512dfbade99 Mon Sep 17 00:00:00 2001 From: L. E. Segovia Date: Mon, 30 Oct 2017 20:47:40 -0300 Subject: Add tests for uninstall_* and zap stanzas --- Library/Homebrew/test/cask/audit_spec.rb | 114 +++++++++++++++++++++ .../fixtures/cask/Casks/with-postflight-multi.rb | 13 +++ .../support/fixtures/cask/Casks/with-postflight.rb | 11 ++ .../fixtures/cask/Casks/with-preflight-multi.rb | 13 +++ .../support/fixtures/cask/Casks/with-preflight.rb | 11 ++ .../fixtures/cask/Casks/with-uninstall-multi.rb | 13 +++ .../cask/Casks/with-uninstall-postflight-multi.rb | 13 +++ .../cask/Casks/with-uninstall-postflight.rb | 11 ++ .../cask/Casks/with-uninstall-preflight-multi.rb | 13 +++ .../cask/Casks/with-uninstall-preflight.rb | 11 ++ .../support/fixtures/cask/Casks/with-zap-multi.rb | 13 +++ 11 files changed, 236 insertions(+) create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight-multi.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight-multi.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-multi.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight.rb create mode 100644 Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-multi.rb (limited to 'Library') diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index 7e140acb2..ec051c138 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -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'" } diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight-multi.rb new file mode 100644 index 000000000..edbb9aff9 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight-multi.rb @@ -0,0 +1,13 @@ +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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb new file mode 100644 index 000000000..b680f8c44 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb @@ -0,0 +1,11 @@ +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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight-multi.rb new file mode 100644 index 000000000..b7505f7f5 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight-multi.rb @@ -0,0 +1,13 @@ +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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb new file mode 100644 index 000000000..bdb0f6145 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb @@ -0,0 +1,11 @@ +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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-multi.rb new file mode 100644 index 000000000..e4c2e22e1 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-multi.rb @@ -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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb new file mode 100644 index 000000000..389d9991c --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb @@ -0,0 +1,13 @@ +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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight.rb new file mode 100644 index 000000000..adb894a15 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight.rb @@ -0,0 +1,11 @@ +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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb new file mode 100644 index 000000000..22c1628c1 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb @@ -0,0 +1,13 @@ +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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight.rb new file mode 100644 index 000000000..5510f4234 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight.rb @@ -0,0 +1,11 @@ +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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-multi.rb new file mode 100644 index 000000000..775e106b4 --- /dev/null +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-multi.rb @@ -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 -- cgit v1.2.3 From c636be07f97e4a659f038c51cab6f0efe2e83bfa Mon Sep 17 00:00:00 2001 From: L. E. Segovia Date: Tue, 31 Oct 2017 09:54:30 -0300 Subject: Separate do end into multiple lines --- .../test/support/fixtures/cask/Casks/with-postflight-multi.rb | 6 ++++-- .../Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb | 3 ++- .../test/support/fixtures/cask/Casks/with-preflight-multi.rb | 6 ++++-- Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb | 3 ++- .../support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb | 6 ++++-- .../test/support/fixtures/cask/Casks/with-uninstall-postflight.rb | 3 ++- .../support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb | 6 ++++-- .../test/support/fixtures/cask/Casks/with-uninstall-preflight.rb | 3 ++- 8 files changed, 24 insertions(+), 12 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight-multi.rb index edbb9aff9..6d0d64798 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight-multi.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight-multi.rb @@ -7,7 +7,9 @@ cask 'with-postflight-multi' do pkg 'MyFancyPkg/Fancy.pkg' - postflight do end + postflight do + end - postflight do end + postflight do + end end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb index b680f8c44..295a2534e 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-postflight.rb @@ -7,5 +7,6 @@ cask 'with-postflight' do pkg 'MyFancyPkg/Fancy.pkg' - postflight do end + postflight do + end end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight-multi.rb index b7505f7f5..d45480fac 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight-multi.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight-multi.rb @@ -7,7 +7,9 @@ cask 'with-preflight-multi' do pkg 'MyFancyPkg/Fancy.pkg' - preflight do end + preflight do + end - preflight do end + preflight do + end end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb index bdb0f6145..d7d1bef06 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-preflight.rb @@ -7,5 +7,6 @@ cask 'with-preflight' do pkg 'MyFancyPkg/Fancy.pkg' - preflight do end + preflight do + end end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb index 389d9991c..58f096061 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight-multi.rb @@ -7,7 +7,9 @@ cask 'with-uninstall-postflight-multi' do pkg 'MyFancyPkg/Fancy.pkg' - uninstall_postflight do end + uninstall_postflight do + end - uninstall_postflight do end + uninstall_postflight do + end end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight.rb index adb894a15..4beffe489 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-postflight.rb @@ -7,5 +7,6 @@ cask 'with-uninstall-postflight' do pkg 'MyFancyPkg/Fancy.pkg' - uninstall_postflight do end + uninstall_postflight do + end end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb index 22c1628c1..f671da64f 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight-multi.rb @@ -7,7 +7,9 @@ cask 'with-uninstall-preflight-multi' do pkg 'MyFancyPkg/Fancy.pkg' - uninstall_preflight do end + uninstall_preflight do + end - uninstall_preflight do end + uninstall_preflight do + end end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight.rb index 5510f4234..2978ed527 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-uninstall-preflight.rb @@ -7,5 +7,6 @@ cask 'with-uninstall-preflight' do pkg 'MyFancyPkg/Fancy.pkg' - uninstall_preflight do end + uninstall_preflight do + end end -- cgit v1.2.3 From 7f398d01b8d5970677d490e120be616aa596ef8b Mon Sep 17 00:00:00 2001 From: L. E. Segovia Date: Wed, 1 Nov 2017 22:35:41 -0300 Subject: Turn ifs into multiple lines --- Library/Homebrew/cask/lib/hbc/audit.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 4a5a40e4f..51316baec 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -53,21 +53,33 @@ module Hbc def check_single_pre_postflight odebug "Auditing preflight and postflight stanzas" - add_warning "only a single preflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:preflight) } > 1 + 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 - add_warning "only a single postflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:postflight) } > 1 + if 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 end def check_single_uninstall_zap odebug "Auditing single uninstall_* and zap stanzas" - add_warning "only a single uninstall stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Uninstall) } > 1 + if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Uninstall) } > 1 + add_warning "only a single uninstall stanza is allowed" + end - add_warning "only a single uninstall_preflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PreflightBlock) && k.directives.key?(:uninstall_preflight) } > 1 + 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 - add_warning "only a single uninstall_postflight stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::PostflightBlock) && k.directives.key?(:uninstall_postflight) } > 1 + 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 - add_warning "only a single zap stanza is allowed" if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Zap) } > 1 + if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Zap) } > 1 + add_warning "only a single zap stanza is allowed" + end end def check_required_stanzas -- cgit v1.2.3 From eaae7f3a5b7dcce0d6c4a3238547996e886b7144 Mon Sep 17 00:00:00 2001 From: L. E. Segovia Date: Thu, 2 Nov 2017 09:56:51 -0300 Subject: Fix last remaining style issues --- Library/Homebrew/cask/lib/hbc/audit.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'Library') diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index 51316baec..d757b0623 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -57,9 +57,8 @@ module Hbc add_warning "only a single preflight stanza is allowed" end - if 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 + 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 @@ -77,9 +76,8 @@ module Hbc add_warning "only a single uninstall_postflight stanza is allowed" end - if cask.artifacts.count { |k| k.is_a?(Hbc::Artifact::Zap) } > 1 - add_warning "only a single zap 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 -- cgit v1.2.3