aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorMike McQuaid2017-08-05 17:39:40 +0100
committerGitHub2017-08-05 17:39:40 +0100
commit8405158d8db0d752222039d5b6226ae8dcff1f9f (patch)
treece8a0a623cd2f8fce5d377aed9b24ed7f3c432d9 /Library/Homebrew/test
parentc26c9204fa48c8d2bfa3837193eaf2a82b611fa6 (diff)
parent66ffdb5b062d8361433897c723f40a66cf382e82 (diff)
downloadbrew-8405158d8db0d752222039d5b6226ae8dcff1f9f.tar.bz2
Merge pull request #2976 from GauthamGoli/audit_external_patches_rubocop
audit: Port patches audit code to a rubocop and add tests
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/rubocops/patches_cop_spec.rb (renamed from Library/Homebrew/test/rubocops/legacy_patches_cop_spec.rb)77
1 files changed, 75 insertions, 2 deletions
diff --git a/Library/Homebrew/test/rubocops/legacy_patches_cop_spec.rb b/Library/Homebrew/test/rubocops/patches_cop_spec.rb
index a08fa614d..4bd79bf35 100644
--- a/Library/Homebrew/test/rubocops/legacy_patches_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/patches_cop_spec.rb
@@ -1,9 +1,9 @@
require "rubocop"
require "rubocop/rspec/support"
require_relative "../../extend/string"
-require_relative "../../rubocops/legacy_patches_cop"
+require_relative "../../rubocops/patches_cop"
-describe RuboCop::Cop::FormulaAudit::LegacyPatches do
+describe RuboCop::Cop::FormulaAudit::Patches do
subject(:cop) { described_class.new }
context "When auditing legacy patches" do
@@ -47,6 +47,7 @@ describe RuboCop::Cop::FormulaAudit::LegacyPatches do
"https://mirrors.ustc.edu.cn/macports/trunk/",
"http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch",
"http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340",
+ "https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch",
]
patch_urls.each do |patch_url|
source = <<-EOS.undent
@@ -84,6 +85,15 @@ describe RuboCop::Cop::FormulaAudit::LegacyPatches do
line: 5,
column: 5,
source: source }]
+ elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
+ expected_offenses = [{ message: "use GitHub pull request URLs:\n"\
+ " https://github.com/foo/foo-bar/pull/100.patch\n"\
+ "Rather than patch-diff:\n"\
+ " https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch\n",
+ severity: :convention,
+ line: 5,
+ column: 5,
+ source: source }]
end
expected_offenses.zip([cop.offenses.last]).each do |expected, actual|
expect_offense(expected, actual)
@@ -125,4 +135,67 @@ describe RuboCop::Cop::FormulaAudit::LegacyPatches do
end
end
end
+
+ context "When auditing external patches" do
+ it "Patch URLs" do
+ patch_urls = [
+ "https://raw.github.com/mogaal/sendemail",
+ "https://mirrors.ustc.edu.cn/macports/trunk/",
+ "http://trac.macports.org/export/102865/trunk/dports/mail/uudeview/files/inews.c.patch",
+ "http://bugs.debian.org/cgi-bin/bugreport.cgi?msg=5;filename=patch-libunac1.txt;att=1;bug=623340",
+ "https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch",
+ ]
+ patch_urls.each do |patch_url|
+ source = <<-EOS.undent
+ class Foo < Formula
+ homepage "ftp://example.com/foo"
+ url "http://example.com/foo-1.0.tgz"
+ patch do
+ url "#{patch_url}"
+ sha256 "63376b8fdd6613a91976106d9376069274191860cd58f039b29ff16de1925621"
+ end
+ end
+ EOS
+
+ inspect_source(cop, source)
+ if patch_url =~ %r{/raw\.github\.com/}
+ expected_offenses = [{ message: "GitHub/Gist patches should specify a revision:\n#{patch_url}",
+ severity: :convention,
+ line: 5,
+ column: 16,
+ source: source }]
+ elsif patch_url =~ %r{macports/trunk}
+ expected_offenses = [{ message: "MacPorts patches should specify a revision instead of trunk:\n#{patch_url}",
+ severity: :convention,
+ line: 5,
+ column: 37,
+ source: source }]
+ elsif patch_url =~ %r{^http://trac\.macports\.org}
+ expected_offenses = [{ message: "Patches from MacPorts Trac should be https://, not http:\n#{patch_url}",
+ severity: :convention,
+ line: 5,
+ column: 9,
+ source: source }]
+ elsif patch_url =~ %r{^http://bugs\.debian\.org}
+ expected_offenses = [{ message: "Patches from Debian should be https://, not http:\n#{patch_url}",
+ severity: :convention,
+ line: 5,
+ column: 9,
+ source: source }]
+ elsif patch_url =~ %r{https?://patch-diff\.githubusercontent\.com/raw/(.+)/(.+)/pull/(.+)\.(?:diff|patch)}
+ expected_offenses = [{ message: "use GitHub pull request URLs:\n"\
+ " https://github.com/foo/foo-bar/pull/100.patch\n"\
+ "Rather than patch-diff:\n"\
+ " https://patch-diff.githubusercontent.com/raw/foo/foo-bar/pull/100.patch\n",
+ severity: :convention,
+ line: 5,
+ column: 9,
+ source: source }]
+ end
+ expected_offenses.zip([cop.offenses.last]).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+ end
end