diff options
| author | Gautham Goli | 2017-08-14 23:32:06 +0530 |
|---|---|---|
| committer | Gautham Goli | 2017-08-14 23:32:06 +0530 |
| commit | d2a7314f538f919e9b09e4b27c1f86b7d3d2eda2 (patch) | |
| tree | ee580c10310cc63c0e0c2947be0f95631f297cf1 /Library | |
| parent | 64a929184a45f530a49af7b047d5b6605b50b1f8 (diff) | |
| download | brew-d2a7314f538f919e9b09e4b27c1f86b7d3d2eda2.tar.bz2 | |
add test for env mod through system call
Diffstat (limited to 'Library')
| -rw-r--r-- | Library/Homebrew/rubocops/lines_cop.rb | 11 | ||||
| -rw-r--r-- | Library/Homebrew/test/rubocops/lines_cop_spec.rb | 22 |
2 files changed, 28 insertions, 5 deletions
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index 6520018ac..e20fa9f8b 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -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) diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index f3626cdce..be2b63c47 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -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]) |
