add tests for formula path shortucut 3
This commit is contained in:
parent
9c9c280c8a
commit
063cbe7acd
@ -124,15 +124,15 @@ module RuboCop
|
|||||||
problem "\"\#\{share}#{match[1]}\" should be \"\#{#{match[2]}}\""
|
problem "\"\#\{share}#{match[1]}\" should be \"\#{#{match[2]}}\""
|
||||||
end
|
end
|
||||||
|
|
||||||
formula_path_strings(body_node, :share) do |p|
|
formula_path_strings(body_node, :prefix) do |p|
|
||||||
if match = regex_match_group(p, %r{/(bin|include|libexec|lib|sbin|share|Frameworks)}i)
|
if match = regex_match_group(p, %r{(/share/(info|man))$})
|
||||||
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[1].downcase}}\""
|
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
|
||||||
end
|
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]}}\""
|
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\""
|
||||||
end
|
end
|
||||||
if match = regex_match_group(p, %r{(/share/(info|man))})
|
if match = regex_match_group(p, %r{(/(bin|include|libexec|lib|sbin|share|Frameworks))}i)
|
||||||
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\""
|
problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2].downcase}}\""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -350,7 +350,8 @@ module RuboCop
|
|||||||
EOS
|
EOS
|
||||||
|
|
||||||
def_node_search :formula_path_strings, <<-EOS.undent
|
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
|
EOS
|
||||||
|
|
||||||
def_node_matcher :negation?, '(send ... :!)'
|
def_node_matcher :negation?, '(send ... :!)'
|
||||||
|
|||||||
@ -979,6 +979,78 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
|||||||
expect_offense(expected, actual)
|
expect_offense(expected, actual)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
def expect_offense(expected, actual)
|
def expect_offense(expected, actual)
|
||||||
expect(actual.message).to eq(expected[:message])
|
expect(actual.message).to eq(expected[:message])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user