Skip to content
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

Handle Minitest flags that accept values, like --seed #19

Merged
merged 1 commit into from
Feb 26, 2024

Conversation

mattbrictson
Copy link
Owner

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 internal process_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 with optparse.

I decided to "brute force" the parsing of the few flags that mighty_test understands, rather than pull in a third-party gem.

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
internal `process_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 with `optparse`.

I decided to "brute force" the parsing of the few flags that mighty_test
understands, rather than pull in a third-party gem.
@mattbrictson mattbrictson added the ✨ Feature Adds a new feature label Feb 26, 2024
@mattbrictson mattbrictson changed the title Handle minitest flags that accept values, like --seed Handle Minitest flags that accept values, like --seed Feb 26, 2024
@mattbrictson mattbrictson merged commit 64739a8 into main Feb 26, 2024
6 checks passed
@mattbrictson mattbrictson deleted the better-opt-parse branch February 26, 2024 05:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature Adds a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant