aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorGautham Goli2017-08-14 22:44:28 +0530
committerGautham Goli2017-08-14 22:44:28 +0530
commit063cbe7acdb0af0a4cd9bd35f29f89bc0d638d4a (patch)
tree81cd69f1566309db1e984225cbfa9fc68b54c7b7 /Library
parent9c9c280c8aeb97a6ec8956242727208d80247826 (diff)
downloadbrew-063cbe7acdb0af0a4cd9bd35f29f89bc0d638d4a.tar.bz2
add tests for formula path shortucut 3
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/rubocops/lines_cop.rb15
-rw-r--r--Library/Homebrew/test/rubocops/lines_cop_spec.rb72
2 files changed, 80 insertions, 7 deletions
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb
index 49eff510d..d3640c9ef 100644
--- a/Library/Homebrew/rubocops/lines_cop.rb
+++ b/Library/Homebrew/rubocops/lines_cop.rb
@@ -124,15 +124,15 @@ module RuboCop
problem "\"\#\{share}#{match[1]}\" should be \"\#{#{match[2]}}\""
end
- formula_path_strings(body_node, :share) do |p|
- if match = regex_match_group(p, %r{/(bin|include|libexec|lib|sbin|share|Frameworks)}i)
- problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[1].downcase}}\""
+ formula_path_strings(body_node, :prefix) do |p|
+ if match = regex_match_group(p, %r{(/share/(info|man))$})
+ problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
end
- if match = regex_match_group(p, %r{((/share/man/|\#\{man\}/)(man[1-8]))})
+ if match = regex_match_group(p, %r{((/share/man/)(man[1-8]))})
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\""
end
- if match = regex_match_group(p, %r{(/share/(info|man))})
- problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
+ if match = regex_match_group(p, %r{(/(bin|include|libexec|lib|sbin|share|Frameworks))}i)
+ problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2].downcase}}\""
end
end
@@ -350,7 +350,8 @@ module RuboCop
EOS
def_node_search :formula_path_strings, <<-EOS.undent
- (dstr (begin (send nil %1)) $(str _ ))
+ {(dstr (begin (send nil %1)) $(str _ ))
+ (dstr _ (begin (send nil %1)) $(str _ ))}
EOS
def_node_matcher :negation?, '(send ... :!)'
diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
index 63ae88dd9..1d25c4721 100644
--- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
@@ -979,6 +979,78 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
expect_offense(expected, actual)
end
end
+
+ it "with formula path shortcut long form 1" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ mv "\#{prefix}/libexec", share
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"\#\{prefix}/libexec\" should be \"\#{libexec}\"",
+ severity: :convention,
+ line: 5,
+ column: 18,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with formula path shortcut long form 2" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ system "./configure", "--INFODIR=\#{prefix}/share/info"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"\#\{prefix}/share/info\" should be \"\#{info}\"",
+ severity: :convention,
+ line: 5,
+ column: 47,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+ it "with formula path shortcut long form 3" do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ system "./configure", "--MANDIR=\#{prefix}/share/man/man8"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "\"\#\{prefix}/share/man/man8\" should be \"\#{man8}\"",
+ severity: :convention,
+ line: 5,
+ column: 46,
+ 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])