-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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: refactor formula file creation #370
tests: refactor formula file creation #370
Conversation
EOS | ||
alias_file = repo.alias_dir/"bar" | ||
include_formula_file | ||
alias_file = CoreTap.new.alias_dir/"balltest" |
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.
Where is balltest
coming from? A typo?
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.
balltest
is an alias for the testball
formula that is being set up here and in the following two lines, if I'm not misreading the code.
A few comments but generally looking great 😍 |
The de-duplication of this stuff is good, but may I suggest a somewhat different approach? Here is what I'd hope this refactoring would yield:
I hope I was somewhat convincing. 😸 I strongly believe this will combine the benefits of less boilerplate (already achieved in the current code) with greater clarity (explicitly requesting certain formulae by name and getting their path in return while avoiding implicitly defined instance variables). To accommodate the currently unhandled cases where a more customized formula is needed, the method could be extended with a second argument to accept something like: baz_path = setup_test_formula "baz", <<-EOS.undent
desc "The baz formula"
url "http://example.com/baz-0.1.tar.gz"
depends_on "foo"
depends_on "bar" => :optional
EOS This would allow to still benefit from the auto-cleanup logic suggested above and the method could further reduce the necessary boilerplate code by providing the surrounding |
a83dc88
to
893ec73
Compare
sha256 "#{TESTBALL_SHA256}" | ||
|
||
option "with-foo", "Build with foo" | ||
#{content} |
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.
I added this line solely for test_options
, but only now realized that it seems wrong to nest #{content}
inside a declaration for content
. Still, the test seems to pass without error...
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.
That's perfectly fine. You're not doing anything different from modifying an existing variable, e.g. content = "a prefix: #{content} and some extra test"
is basically the same thing, its just not using a “here document”.
Thanks for the suggestions, @UniqMartin! This was a fun challenge. I have:
I have also:
I hope it's OK that I made those extra changes even if they weren't strictly related to the task at hand; I figured I might as well. |
end | ||
EOS | ||
setup_test_formula "foo" | ||
setup_test_formula "bar" |
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.
Would it be preferable to use setup_test_formula "foo" && setup_test_formula "bar"
instead of
setup_test_formula "foo"
setup_test_formula "bar"
?
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.
I'm definitely in favor of the latter. Intuitively, using &&
here has the same effect but doesn't make much sense, but maybe I'm just missing the point.
Unsurprisingly, I really like the approach. 😂 But in all seriousness, I think this is a very nice improvement to the testing code and a nice consolidation of the test formula setup logic. 👍 The diff statistics are also quite encouraging (we got rid of 166 basically redundant lines):
Ideally, these would have been separate commits, but I don't mind accepting this as-is (modulo the minor indentation fixes pointed out in the code comments). |
👍 Thank you! I'll keep this in mind for future reference. I've made the indentation fixes, but I'm having trouble with This may be because I blindly ran |
I'm assuming you're talking about Or use
Don't do that, unless you know exactly what it is doing or someone else (me) has advised to use it in very specific circumstances after having tested it does the right thing. 😛 You almost always want to use a regular |
And if you're stuck with a borked local branch: The easiest fix in this case would be to throw away the local branch with |
c664404
to
aa8ab8e
Compare
Thanks @UniqMartin! Yup! I ought not to have done that; I guess I often throw caution to the wind when things seem desperate. 😬
I went ahead with this route, did |
I'm happy with this refactoring and think it's ready to be merged, but will keep it open a bit longer (maybe a day or two) so that @MikeMcQuaid and other maintainers have a chance to voice their opinions. |
😍 @eirinikos! |
brew tests
with your changes locally?This change consolidates almost all of the instances of
formula_file = CoreTap.new.formula_dir/"testball.rb"
into the methodinclude_formula_file
, which makes use of@formula_file
.For tests that involve at least two formula files, the method
include_formula_files
creates@foo_file
and@bar_file
.@baz_file
.The
url
for@formula_file
is now solely"file://#{File.expand_path("..", __FILE__)}/tarballs/testball-0.1.tbz"
."file://#{File.expand_path..."
or"https://example.com/testball-0.1.tar.gz"
.Some tests
ensure
only@formula_file.unlink
, whereas othersensure
@formula_file.unlink unless @formula_file.nil?
ensure
block?test_create
was left as-is -- I wasn't sure how to improve upon it, given thaturl
is not an accessible attribute on formula instances.test_options
has also been (mostly) left as-is for now.depends_on "bar" => :recommended
should not be included in the default@formula_file
, though maybe I could append this to the formula from withintest_options
?test_options
as shown below, and this error is raised withincmd_output
:Error: undefined method 'depends_on' for Formulary::FormulaNamespace2d3ec45e3a12a54ca19cb33c3b0cddbf:Module
🎈