add test for env mod through system call
This commit is contained in:
parent
64a929184a
commit
d2a7314f53
@ -135,6 +135,7 @@ 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?)
|
||||
@ -142,11 +143,11 @@ module RuboCop
|
||||
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"
|
||||
# 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"
|
||||
end
|
||||
|
||||
# find_every_method_call_by_name(body_node, :depends_on).each do |m|
|
||||
# next unless modifier?(m)
|
||||
# dep, option = hash_dep(m)
|
||||
|
@ -1073,6 +1073,28 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
end
|
||||
end
|
||||
|
||||
it "with setting env manually" do
|
||||
source = <<-EOS.undent
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'http://example.com/foo-1.0.tgz'
|
||||
system "export", "var=value"
|
||||
end
|
||||
EOS
|
||||
|
||||
expected_offenses = [{ message: "Use ENV instead of invoking 'export' to modify the environment",
|
||||
severity: :convention,
|
||||
line: 4,
|
||||
column: 10,
|
||||
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])
|
||||
|
Loading…
x
Reference in New Issue
Block a user