diff options
| author | Mike McQuaid | 2017-04-05 08:37:43 +0100 |
|---|---|---|
| committer | GitHub | 2017-04-05 08:37:43 +0100 |
| commit | 3f5140621223780f03fd37c0c3ba3b883eb318ba (patch) | |
| tree | 333d1de82180ebe1b773edbe4741642517ce634f /Library/Homebrew/test | |
| parent | dbc9cd7aa37f3215efa834345445fc0af4df33e2 (diff) | |
| parent | a693ca332efcc56e0d7dbb3f43952226225ccf75 (diff) | |
| download | brew-3f5140621223780f03fd37c0c3ba3b883eb318ba.tar.bz2 | |
Merge pull request #2242 from GauthamGoli/audit_custom_cops
Port audit_desc audit rules to a cop
Diffstat (limited to 'Library/Homebrew/test')
| -rw-r--r-- | Library/Homebrew/test/Gemfile | 1 | ||||
| -rw-r--r-- | Library/Homebrew/test/Gemfile.lock | 14 | ||||
| -rw-r--r-- | Library/Homebrew/test/dev-cmd/audit_spec.rb | 30 | ||||
| -rw-r--r-- | Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb | 67 | ||||
| -rw-r--r-- | Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb | 121 |
5 files changed, 203 insertions, 30 deletions
diff --git a/Library/Homebrew/test/Gemfile b/Library/Homebrew/test/Gemfile index bc9bccfbc..f3c16c710 100644 --- a/Library/Homebrew/test/Gemfile +++ b/Library/Homebrew/test/Gemfile @@ -2,6 +2,7 @@ source "https://rubygems.org" gem "parallel_tests" gem "rspec" +gem "rubocop" gem "rspec-its", require: false gem "rspec-wait", require: false diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock index 64561be71..4d4eefd7d 100644 --- a/Library/Homebrew/test/Gemfile.lock +++ b/Library/Homebrew/test/Gemfile.lock @@ -1,6 +1,7 @@ GEM remote: https://rubygems.org/ specs: + ast (2.3.0) codecov (0.1.9) json simplecov @@ -11,6 +12,10 @@ GEM parallel (1.10.0) parallel_tests (2.13.0) parallel + parser (2.4.0.0) + ast (~> 2.2) + powerpack (0.1.1) + rainbow (2.2.1) rspec (3.5.0) rspec-core (~> 3.5.0) rspec-expectations (~> 3.5.0) @@ -29,11 +34,19 @@ GEM rspec-support (3.5.0) rspec-wait (0.0.9) rspec (>= 3, < 4) + rubocop (0.47.1) + parser (>= 2.3.3.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.8.1) simplecov (0.13.0) docile (~> 1.1.0) json (>= 1.8, < 3) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) + unicode-display_width (1.1.3) url (0.3.2) PLATFORMS @@ -45,6 +58,7 @@ DEPENDENCIES rspec rspec-its rspec-wait + rubocop simplecov BUNDLED WITH diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index ec1a34fb4..a6bb22837 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -344,10 +344,6 @@ describe FormulaAuditor do end EOS - fa.audit_desc - expect(fa.problems.shift) - .to eq("Description shouldn't include the formula name") - fa.audit_line 'ohai "#{share}/foolibc++"', 3 expect(fa.problems.shift) .to eq("Use \#{pkgshare} instead of \#{share}/foolibc++") @@ -413,32 +409,6 @@ describe FormulaAuditor do .to eq(["Don't recommend setuid in the caveats, suggest sudo instead."]) end - specify "#audit_desc" do - formula_descriptions = [ - { name: "foo", desc: nil, - problem: "Formula should have a desc" }, - { name: "bar", desc: "bar" * 30, - problem: "Description is too long" }, - { name: "baz", desc: "Baz commandline tool", - problem: "Description should use \"command-line\"" }, - { name: "qux", desc: "A tool called Qux", - problem: "Description shouldn't start with an indefinite article" }, - ] - - formula_descriptions.each do |formula| - content = <<-EOS.undent - class #{Formulary.class_s(formula[:name])} < Formula - url "http://example.com/#{formula[:name]}-1.0.tgz" - desc "#{formula[:desc]}" - end - EOS - - fa = formula_auditor formula[:name], content, strict: true - fa.audit_desc - expect(fa.problems.first).to match(formula[:problem]) - end - end - describe "#audit_homepage" do specify "homepage URLs" do fa = formula_auditor "foo", <<-EOS.undent, online: true diff --git a/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb new file mode 100644 index 000000000..5be2d6cf5 --- /dev/null +++ b/Library/Homebrew/test/rubocops/bottle_block_cop_spec.rb @@ -0,0 +1,67 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/bottle_block_cop" + +describe RuboCop::Cop::Homebrew::CorrectBottleBlock do + subject(:cop) { described_class.new } + + context "When auditing Bottle Block" do + it "When there is revision in bottle block" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + bottle do + cellar :any + revision 2 + end + end + EOS + + expected_offenses = [{ message: "Use rebuild instead of revision in bottle block", + severity: :convention, + line: 5, + column: 4, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end + end + + context "When auditing Bottle Block with auto correct" do + it "When there is revision in bottle block" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + bottle do + cellar :any + revision 2 + end + end + EOS + corrected_source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + bottle do + cellar :any + rebuild 2 + end + end + EOS + + new_source = autocorrect_source(cop, source) + expect(new_source).to eq(corrected_source) + end + end +end diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb new file mode 100644 index 000000000..04c4c27da --- /dev/null +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -0,0 +1,121 @@ +require "rubocop" +require "rubocop/rspec/support" +require_relative "../../extend/string" +require_relative "../../rubocops/formula_desc_cop" + +describe RuboCop::Cop::Homebrew::FormulaDesc do + subject(:cop) { described_class.new } + + context "When auditing formula desc" do + it "When there is no desc" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + end + EOS + + expected_offenses = [{ message: "Formula should have a desc (Description).", + severity: :convention, + line: 1, + column: 0, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When desc is too long" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc '#{"bar"*30}' + end + EOS + + msg = <<-EOS.undent + Description is too long. "name: desc" should be less than 80 characters. + Length is calculated as Foo + desc. (currently 95) + EOS + expected_offenses = [{ message: msg, + severity: :convention, + line: 3, + column: 2, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When wrong \"command-line\" usage in desc" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc 'command line' + end + EOS + + expected_offenses = [{ message: "Description should use \"command-line\" instead of \"command line\"", + severity: :convention, + line: 3, + column: 8, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When an article is used in desc" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc 'An ' + end + EOS + + expected_offenses = [{ message: "Description shouldn't start with an indefinite article (An )", + severity: :convention, + line: 3, + column: 8, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "When formula name is in desc" do + source = <<-EOS.undent + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + desc 'Foo' + end + EOS + + expected_offenses = [{ message: "Description shouldn't include the formula name", + severity: :convention, + line: 3, + column: 8, + source: source }] + + inspect_source(cop, source) + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + def expect_offense(expected, actual) + expect(actual.message).to eq(expected[:message]) + expect(actual.severity).to eq(expected[:severity]) + expect(actual.line).to eq(expected[:line]) + expect(actual.column).to eq(expected[:column]) + end + end +end |
