Handle Minitest flags that accept values, like --seed
#19
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
mighty_test needs an option parser to handle its own flags, like
--all
,--shard
, and--watch
. However, users can also pass in Minitest flags like--seed
or--fail-fast
and expect them to be passed to Minitest when tests are run.This is challenging, because the full range of flags that Minitest supports isn't known in advanced. Minitest plugins can add arbitrary flags as runtime. Therefore we can't write a single option parser that works for mighty_test and Minitest.
The implementation in this commit takes the following approach: First, parse the flags that mighty_test understands, like
--all
. Then check if there are any unrecognized flags remaining. If so, use Minitest's internalprocess_args
method to parse the remaining flags.The result isn't perfect (Minitest's error handling does a hard exit when it encounters at invalid option, so we don't have an opportunity to format or augment the help message), but it works for common cases.
I removed
optparse
because its design assumes a single parser that handles the entirety of ARGV. We need a parser that can decode flags one at a time, and then pass the remainder to Minitest, something that I couldn't get to work withoptparse
.I decided to "brute force" the parsing of the few flags that mighty_test understands, rather than pull in a third-party gem.