New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tests: fix code style issues #587
tests: fix code style issues #587
Conversation
@@ -154,7 +154,7 @@ def test_git_variant | |||
|
|||
assert_equal "e1893a6bd191ba895c71b652ff8376a6114c7fa7", @tap.git_head | |||
assert_equal "e189", @tap.git_short_head | |||
assert_match %r{years ago}, @tap.git_last_commit | |||
assert_match /years ago/, @tap.git_last_commit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this just be "years ago"
& avoid //
entirely given we're not actually using a regex here or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to me!
Sorry if I'm being a bit pedantic here, but “bugs” feels like to strong of a word. There's nothing inherently wrong or broken about the code, it's just that it doesn't fully conform to certain code style guidelines. Aside from this there's also a minor issue with the commit subject (and PR title). The way I tend to read them is
This is one of those cases where refactoring is unlikely to make sense and RuboCop suggests a solution that doesn't apply because it fails to understand the full context of the surrounding code. Depending on whether this affects individual lines or short blocks of code, the best solution is to suppress those complaints by temporarily disabling one or more cops, as detailed in the RuboCop documentation.
True. Silencing the relevant cop is the best way to address this and to drop the violation count.
This mostly sounds like a misunderstanding to me, i.e. in which contexts this suggestion applies.
Indeed, they are guidelines and where possible, we have tweaked the settings because our preferred style doesn't fully align with what RuboCop considers to be the best default. It can sometimes make sense to tweak a rule instead of “fixing” our code, though most suggestions and defaults are good (and just show how old and diverse some of our code base is). |
@@ -142,7 +142,7 @@ def test_check_user_path_bin | |||
def test_check_user_path_sbin | |||
sbin = HOMEBREW_PREFIX/"sbin" | |||
ENV["PATH"] = "#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" + | |||
ENV["PATH"].gsub(%r{(?:^|#{File::PATH_SEPARATOR})#{sbin}}, "") | |||
ENV["PATH"].gsub(/(?:^|File::PATH_SEPARATOR.to_s)sbin.to_s/, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The substitution of #{File::PATH_SEPARATOR}
with File::PATH_SEPARATOR.to_s
is wrong and the same applies to the #{sbin}
and sbin.to_s
pair. A relatively easy way to check this is to enter both regular expressions into brew irb
(though we'll need to also provide sbin
):
$ brew irb
==> Interactive Homebrew Shell
Example commands available with: brew irb --examples
irb(main):001:0> sbin = HOMEBREW_PREFIX/"sbin"
=> #<Pathname:/opt/homebrew/sbin>
irb(main):002:0> %r{(?:^|#{File::PATH_SEPARATOR})#{sbin}}
=> /(?:^|:)\/opt\/homebrew\/sbin/
irb(main):003:0> /(?:^|File::PATH_SEPARATOR.to_s)sbin.to_s/
=> /(?:^|File::PATH_SEPARATOR.to_s)sbin.to_s/
The correct substitution should be:
/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/
(Regexp.escape
makes additionally sure to properly handle any characters that we want to be interpreted literally, but that have special meaning when used inside a regular expression.)
Sorry -- I accidentally closed this PR when I decided to rename my local and remote branches (without realizing the effect this would have on the PR). 😳 Working on addressing the feedback... |
5f6df5d
to
556af40
Compare
No worries, that makes sense to me. I thought I remembered hearing these issues referred to as "bugs" some time ago, but I see that that isn't the most accurate way to refer to them. I've updated the commit and PR title, though the branch still carries the old name. 😬 Thanks for pointing me to the Rubocop documentation on temporarily disabling cops. I've done this for the I also removed the string interpolation in It's probably obvious that I approached this task with haste and impatience, so I've learned my lesson. Thank you @UniqMartin and @DomT4 for taking a closer look here! 😁 9 Rubocop offenses remain in
|
@@ -193,7 +193,7 @@ def test_cellar_formula | |||
end | |||
|
|||
def test_env | |||
assert_match %r{CMAKE_PREFIX_PATH="#{HOMEBREW_PREFIX}[:"]}, | |||
assert_match /CMAKE_PREFIX_PATH="#{Regexp.escape(HOMEBREW_PREFIX)}[:"]/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be wrapped with ()
: http://bot.brew.sh/job/Brew%20Pull%20Requests/1111/version=el_capitan/testReport/junit/brew-test-bot/el_capitan/readall___syntax/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Got it. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...though now Rubocop is saying Don't use parentheses around a literal
... 😑
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, needs to be this line and the next
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean like this?
assert_match(/CMAKE_PREFIX_PATH="#{Regexp.escape(HOMEBREW_PREFIX)}[:"]/,
cmd("--env"))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep!
@eirinikos Nice work! Added a few comments and then we can 🚢 this. |
556af40
to
914893c
Compare
@MikeMcQuaid Thanks! |
|
||
# `formula do` uses nested method definitions | ||
Style/NestedMethodDefinition: | ||
Enabled: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a newline at the end of this file (ideally configure your editor to do this automagically!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it! 👍
914893c
to
2a67d70
Compare
Merged in 8ec5925. Thank you for another great contribution to Homebrew, @eirinikos! 🎉 |
Nice work @eirinikos 👏 |
brew tests
with your changes locally?This change fixes many of the existing bugs reported by
brew style
forHomebrew/test
.33 bugs remain; many of them are one of the following:
Method definitions must not be nested. Use lambda instead.
formula do
blocks; does it make sense to convert these to lambdas? (I haven't yet figured out a way to do so that passesbrew tests
.)Use snake_case for method names.
test_check_DYLD_vars
andtest_create_DATA
; it seems like these acronyms are best kept as-is.Prefer to_s over string interpolation.
brew style
(e.g., intest_integration_cmds
; why is that?I'm sensing that Rubocop's opinions are meant to be guidelines (rather than gospel), but maybe I'm wrong!
🎈