aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/test
diff options
context:
space:
mode:
authorMike McQuaid2017-06-20 14:27:51 +0100
committerGitHub2017-06-20 14:27:51 +0100
commit80ce43dff1a196d021f64277a2d3b6aa3e2898f7 (patch)
treef54eb5d756f8737351cbf0bc655a62a010f15562 /Library/Homebrew/test
parenta1e5077adf60b6594b1c372ddfb275fb55b33c65 (diff)
parent0e1c88e7aefb93a8e2cc927fa9a4e903ac015c57 (diff)
downloadbrew-80ce43dff1a196d021f64277a2d3b6aa3e2898f7.tar.bz2
Merge pull request #2776 from GauthamGoli/audit_checksum_rubocop_fix
audit: Fix audit_checksum method's rubocop and add more tests
Diffstat (limited to 'Library/Homebrew/test')
-rw-r--r--Library/Homebrew/test/rubocops/checksum_cop_spec.rb222
1 files changed, 222 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..644152c32
--- /dev/null
+++ b/Library/Homebrew/test/rubocops/checksum_cop_spec.rb
@@ -0,0 +1,222 @@
+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: "sha256 is empty",
+ severity: :convention,
+ line: 5,
+ column: 12,
+ source: source },
+ { message: "sha256 is empty",
+ 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
+
+ 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: "sha256 should be 64 characters",
+ severity: :convention,
+ line: 5,
+ column: 12,
+ source: source },
+ { message: "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
+
+ it "When the checksum has invalid chars" 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 "5cf6e1ae0a645b426c0k7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a"
+
+ resource "foo-package" do
+ url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
+ sha256 "5cf6e1ae0a645b426x047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9"
+ end
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "sha256 contains invalid characters",
+ severity: :convention,
+ line: 5,
+ column: 31,
+ source: source },
+ { message: "sha256 contains invalid characters",
+ severity: :convention,
+ line: 9,
+ column: 31,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+end
+
+describe RuboCop::Cop::FormulaAudit::ChecksumCase do
+ subject(:cop) { described_class.new }
+
+ context "When auditing spec checksums" do
+ it "When the checksum has upper case 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 "5cf6e1ae0A645b426c0a7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a"
+
+ resource "foo-package" do
+ url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
+ sha256 "5cf6e1Ae0a645b426b047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9"
+ end
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "sha256 should be lowercase",
+ severity: :convention,
+ line: 5,
+ column: 21,
+ source: source },
+ { message: "sha256 should be lowercase",
+ severity: :convention,
+ line: 9,
+ column: 20,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "When auditing stable blocks outside spec blocks" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ url 'http://example.com/foo-1.0.tgz'
+ resource "foo-outside" do
+ url "https://github.com/foo-lang/foo-outside/archive/0.18.0.tar.gz"
+ sha256 "A4cc7cd3f7d1605ffa1ac5755cf6e1ae0a645b426b047a6a39a8b2268ddc7ea9"
+ end
+ stable do
+ url "https://github.com/foo-lang/foo-compiler/archive/0.18.0.tar.gz"
+ sha256 "5cf6e1ae0a645b426c0a7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a"
+
+ resource "foo-package" do
+ url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
+ sha256 "5cf6e1ae0a645b426b047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9"
+ end
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "sha256 should be lowercase",
+ severity: :convention,
+ line: 5,
+ column: 12,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ end
+
+ context "When auditing checksum with autocorrect" do
+ it "When there is uppercase sha256" 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 "5cf6e1ae0A645b426c0a7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a"
+
+ resource "foo-package" do
+ url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
+ sha256 "5cf6e1Ae0a645b426b047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9"
+ end
+ end
+ end
+ EOS
+
+ corrected_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 "5cf6e1ae0a645b426c0a7cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea0e9a"
+
+ resource "foo-package" do
+ url "https://github.com/foo-lang/foo-package/archive/0.18.0.tar.gz"
+ sha256 "5cf6e1ae0a645b426b047aa4cc7cd3f7d1605ffa1ac5756a39a8b2268ddc7ea9"
+ end
+ end
+ end
+ EOS
+
+ new_source = autocorrect_source(cop, source)
+ expect(new_source).to eq(corrected_source)
+ end
+ end
+end