From 64a929184a45f530a49af7b047d5b6605b50b1f8 Mon Sep 17 00:00:00 2001 From: Gautham Goli Date: Mon, 14 Aug 2017 23:05:00 +0530 Subject: [PATCH] add tests for vendored deps --- Library/Homebrew/rubocops/lines_cop.rb | 17 +++++++------- .../Homebrew/test/rubocops/lines_cop_spec.rb | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index d3640c9efa..6520018acd 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -135,14 +135,13 @@ module RuboCop problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2].downcase}}\"" end end + find_every_method_call_by_name(body_node, :depends_on).each do |m| + key, value = destructure_hash(parameters(m).first) + next if (key.nil? || value.nil?) + next unless match = regex_match_group(value, %r{(lua|perl|python|ruby)(\d*)}) + problem "#{match[1]} modules should be vendored rather than use deprecated #{m.source}`" + end - # find_every_method_call_by_name(body_node, :depends_on) do |m| - # key, value = destructure_hash(paramters(m).first) - # next unless key.str_type? - # next unless match = regex_match_group(value, %r{(lua|perl|python|ruby)(\d*)}) - # problem "#{match[1]} modules should be vendored rather than use deprecated #{m.source}`" - # end - # # find_every_method_call_by_name(body_node, :system).each do |m| # next unless match = regex_match_group(parameters(m).first, %r{(env|export)(\s+)?}) # problem "Use ENV instead of invoking '#{match[1]}' to modify the environment" @@ -345,8 +344,8 @@ module RuboCop $(hash (pair $(str _) (array $(str _) ...)))} EOS - def_node_search :destructure_hash, <<-EOS.undent - (hash (pair $_ $_)) + def_node_matcher :destructure_hash, <<-EOS.undent + (hash (pair $(str _) $(sym _))) EOS def_node_search :formula_path_strings, <<-EOS.undent diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 1d25c47211..f3626cdce1 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -1051,6 +1051,28 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do end end + it "with dependecies which have to vendored" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + depends_on "lpeg" => :lua51 + end + EOS + + expected_offenses = [{ message: "lua modules should be vendored rather than use deprecated depends_on \"lpeg\" => :lua51`", + severity: :convention, + line: 4, + column: 24, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + end def expect_offense(expected, actual) expect(actual.message).to eq(expected[:message])