aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorGautham Goli2017-08-14 20:10:45 +0530
committerGautham Goli2017-08-14 20:10:45 +0530
commit65ae6bacd8c92d718b259f7efd50fc3fe9f0838b (patch)
treec3e0e1e9eb6a3fc0496381c8a6b479b904f2b933 /Library
parent77468fdae36ee58580a643d8bc0fdd9f8b6e61c3 (diff)
downloadbrew-65ae6bacd8c92d718b259f7efd50fc3fe9f0838b.tar.bz2
add tests for hardcoded compilers in ENV
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/rubocops/lines_cop.rb20
-rw-r--r--Library/Homebrew/test/rubocops/lines_cop_spec.rb56
2 files changed, 62 insertions, 14 deletions
diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb
index 4d2d63cce..919b21243 100644
--- a/Library/Homebrew/rubocops/lines_cop.rb
+++ b/Library/Homebrew/rubocops/lines_cop.rb
@@ -108,16 +108,16 @@ module RuboCop
problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\""
end
end
- #
- # find_instance_method_call(body_node, :ENV, :[]=) do |m|
- # param = parameters(m)[1]
- # if match = regex_match_group(param, %r{(/usr/bin/)?(gcc|llvm-gcc|clang)\s?})
- # problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[3]}\""
- # elsif match = regex_match_group(param, %r{(/usr/bin/)?((g|llvm-g|clang)\+\+)\s?})
- # problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[3]}\""
- # end
- # end
- #
+
+ find_instance_method_call(body_node, "ENV", :[]=) do |m|
+ param = parameters(m)[1]
+ if match = regex_match_group(param, %r{(/usr/bin/)?(gcc|llvm-gcc|clang)\s?})
+ problem "Use \"\#{ENV.cc}\" instead of hard-coding \"#{match[2]}\""
+ elsif match = regex_match_group(param, %r{(/usr/bin/)?((g|llvm-g|clang)\+\+)\s?})
+ problem "Use \"\#{ENV.cxx}\" instead of hard-coding \"#{match[2]}\""
+ end
+ end
+
# # Prefer formula path shortcuts in strings
# formula_path_strings(body_node, :prefix) do |p|
# next unless match = regex_match_group(p, %r{(/(man))[/'"]})
diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
index 7e901f0e2..afe65e9ac 100644
--- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb
+++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb
@@ -817,7 +817,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
- def test
+ def install
verbose = ARGV.verbose?
end
end
@@ -841,7 +841,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
- def test
+ def install
man1.install man+"man8" => "faad.1"
end
end
@@ -865,7 +865,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
- def test
+ def install
system "/usr/bin/gcc", "foo"
end
end
@@ -889,7 +889,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
- def test
+ def install
system "/usr/bin/g++", "-o", "foo", "foo.cc"
end
end
@@ -907,6 +907,54 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
expect_offense(expected, actual)
end
end
+
+ it "with hardcoded compiler 3 " do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ ENV["COMPILER_PATH"] = "/usr/bin/llvm-g++"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use \"\#{ENV.cxx}\" instead of hard-coding \"llvm-g++\"",
+ severity: :convention,
+ line: 5,
+ column: 28,
+ source: source }]
+
+ inspect_source(cop, source)
+
+ expected_offenses.zip(cop.offenses).each do |expected, actual|
+ expect_offense(expected, actual)
+ end
+ end
+
+ it "with hardcoded compiler 4 " do
+ source = <<-EOS.undent
+ class Foo < Formula
+ desc "foo"
+ url 'http://example.com/foo-1.0.tgz'
+ def install
+ ENV["COMPILER_PATH"] = "/usr/bin/gcc"
+ end
+ end
+ EOS
+
+ expected_offenses = [{ message: "Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"",
+ severity: :convention,
+ line: 5,
+ column: 28,
+ 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])