aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorMike McQuaid2017-06-09 09:46:05 +0300
committerGitHub2017-06-09 09:46:05 +0300
commite83e394a731f3317dc09a5eb1210ff6996e40ed2 (patch)
tree73a9cc10ded84946bad2773b9fc848ec607b3315 /Library/Homebrew/test
parent0e2b043c125538dab0cee416bff908034ad37e84 (diff)
parentd09d5ecc559c4971fae77769cb1a203bb20c7a97 (diff)
downloadbrew-e83e394a731f3317dc09a5eb1210ff6996e40ed2.tar.bz2
Merge pull request #2755 from GauthamGoli/audit_checksum_rubocop
audit: Port audit_checksum method to rubocop and add tests
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/rubocops/checksum_cop_spec.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/Library/Homebrew/test/rubocops/checksum_cop_spec.rb b/Library/Homebrew/test/rubocops/checksum_cop_spec.rb
new file mode 100644
index 000000000..fb21771ff
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/checksum_cop_spec.rb
@@ -0,0 +1,78 @@
+require "rubocop"
+require "rubocop/rspec/support"
+require_relative "../../extend/string"
+require_relative "../../rubocops/checksum_cop"
+
+describe RuboCop::Cop::FormulaAudit::Checksum do
+ subject(:cop) { described_class.new }
+
+ context "When auditing spec checksums" do
+ it "When the checksum is empty" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ stable do
+ url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz"
+ sha256 ""
+
+ resource "foo-package" do
+ url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
+ sha256 ""
+ end
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Stable: sha256 is empty",
+ severity: :convention,
+ line: 5,
+ column: 4,
+ source: source },
+ { message: "Stable resource \"foo-package\": sha256 is empty",
+ severity: :convention,
+ line: 9,
+ column: 6,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When the checksum is not 64 characters" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ stable do
+ url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz"
+ sha256 "5cf6e1ae0a645b426c0474cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9ad"
+
+ resource "foo-package" do
+ url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
+ sha256 "5cf6e1ae0a645b426c047aaa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9"
+ end
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Stable: sha256 should be 64 characters",
+ severity: :convention,
+ line: 5,
+ column: 12,
+ source: source },
+ { message: "Stable resource \"foo-package\": sha256 should be 64 characters",
+ severity: :convention,
+ line: 9,
+ column: 14,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+end