aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorGautham Goli2017-08-15 00:05:50 +0530
committerGautham Goli2017-08-15 00:27:09 +0530
commitcfc423e1839442f605072db14aac42f6f5fa6174 (patch)
tree8ac198886cfc56e3da87cb5ab365c5cd15ab7ba0 /Library
parentd2a7314f538f919e9b09e4b27c1f86b7d3d2eda2 (diff)
downloadbrew-cfc423e1839442f605072db14aac42f6f5fa6174.tar.bz2
add tests for dependencies
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/rubocops/lines_cop.rb23
-rw-r--r--Library/Homebrew/test/rubocops/lines_cop_spec.rb22
2 files changed, 35 insertions, 10 deletions
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb
index e20fa9f8b..0c465f9f5 100644
--- a/Library/Homebrew/rubocops/lines_cop.rb
+++ b/Library/Homebrew/rubocops/lines_cop.rb
@@ -148,13 +148,15 @@ module RuboCop
problem "Use ENV instead of invoking '#{match[1]}' to modify the environment"
end
- # find_every_method_call_by_name(body_node, :depends_on).each do |m|
- # next unless modifier?(m)
- # dep, option = hash_dep(m)
- # next if dep.nil? || option.nil?
- # problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
- # end
- #
+ find_every_method_call_by_name(body_node, :depends_on).each do |m|
+ next if modifier?(m.parent)
+ param = parameters(m).first
+ dep, option = hash_dep(param)
+ next if dep.nil? || option.nil?
+ offending_node(param)
+ problem "Dependency #{string_content(dep)} should not use option #{string_content(option)}"
+ end
+
# find_instance_method_call(body_node, :version, :==) do |m|
# next unless parameters_passed?(m, "HEAD")
# problem "Use 'build.head?' instead of inspecting 'version'"
@@ -328,6 +330,7 @@ module RuboCop
end
def modifier?(node)
+ return false unless node.if_type?
node.modifier_form?
end
@@ -340,9 +343,9 @@ module RuboCop
EOS
# Match depends_on with hash as argument
- def_node_search :hash_dep, <<-EOS.undent
- {$(hash (pair $(str _) $(str _)))
- $(hash (pair $(str _) (array $(str _) ...)))}
+ def_node_matcher :hash_dep, <<-EOS.undent
+ {(hash (pair $(str _) $(str _)))
+ (hash (pair $(str _) (array $(str _) ...)))}
EOS
def_node_matcher :destructure_hash, <<-EOS.undent
diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
index be2b63c47..1273ef9c9 100644
--- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
@@ -1095,6 +1095,28 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
end
end
+ it "with dependencies with invalid options" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ depends_on "foo" => "with-bar"
+ end
+ EOS
+
+ expected_offenses = [{ message: "Dependency foo should not use option with-bar",
+ severity: :convention,
+ line: 4,
+ column: 13,
+ 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])