Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brew
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
brew
Commits
77468fda
Commit
77468fda
authored
7 years ago
by
Gautham Goli
Browse files
Options
Downloads
Patches
Plain Diff
add tests for hard coded compilers in system calls
parent
af5cd1a1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Library/Homebrew/rubocops/lines_cop.rb
+9
-9
9 additions, 9 deletions
Library/Homebrew/rubocops/lines_cop.rb
Library/Homebrew/test/rubocops/lines_cop_spec.rb
+48
-0
48 additions, 0 deletions
Library/Homebrew/test/rubocops/lines_cop_spec.rb
with
57 additions
and
9 deletions
Library/Homebrew/rubocops/lines_cop.rb
+
9
−
9
View file @
77468fda
...
...
@@ -99,15 +99,15 @@ module RuboCop
problem
"
\"
#{
m
.
source
}
\"
should be
\"
#{
match
[
0
]
}
\"
"
end
#
#
Avoid hard-coding compilers
#
find_every_method_call_by_name(body_node, :system).each do |m|
#
param = parameters(m).first
#
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
# Avoid hard-coding compilers
find_every_method_call_by_name
(
body_node
,
:system
).
each
do
|
m
|
param
=
parameters
(
m
).
first
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
#
# find_instance_method_call(body_node, :ENV, :[]=) do |m|
# param = parameters(m)[1]
...
...
This diff is collapsed.
Click to expand it.
Library/Homebrew/test/rubocops/lines_cop_spec.rb
+
48
−
0
View file @
77468fda
...
...
@@ -859,6 +859,54 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do
expect_offense
(
expected
,
actual
)
end
end
it
"with hardcoded compiler 1 "
do
source
=
<<-
EOS
.
undent
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
def test
system "/usr/bin/gcc", "foo"
end
end
EOS
expected_offenses
=
[{
message:
"Use
\"\#
{ENV.cc}
\"
instead of hard-coding
\"
gcc
\"
"
,
severity: :convention
,
line:
5
,
column:
12
,
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 2 "
do
source
=
<<-
EOS
.
undent
class Foo < Formula
desc "foo"
url 'http://example.com/foo-1.0.tgz'
def test
system "/usr/bin/g++", "-o", "foo", "foo.cc"
end
end
EOS
expected_offenses
=
[{
message:
"Use
\"\#
{ENV.cxx}
\"
instead of hard-coding
\"
g++
\"
"
,
severity: :convention
,
line:
5
,
column:
12
,
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
])
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment