PageMatch: Expand #find_versions tests #11889
Merged
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.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?This is a follow-up to #11888, where I modified the early return conditions for
PageMatch#find_versions
to allow astrategy
block to [temporarily] act as a substitution for aregex
. That PR was a fix for an issue affecting some casks that don't follow established patterns, so I wanted to get it merged quickly. This PR contains related changes that I would have handled in #11888 if I had more time.This adds a test to ensure that
PageMatch#find_versions
works when a block is provided but a regex isn't. I've added comments to explain that this is temporary and the pattern in the test shouldn't be followed.Similarly, I've updated related method signatures and documentation comments to reflect that the
regex
parameter is technically nilable for now. The method signature changes were required for this to pass.Looking forward
Existing cask
livecheck
blocks that don't use#regex
to establish a regex and pass it into astrategy
block should be updated to do so. This has long been the pattern in homebrew/core and homebrew/cask should be brought up to standard (in many other ways as well).One challenge is that there are some cask
strategy
blocks that require more than one regex but#regex
currently only works with one regex. With some of thesestrategy
blocks, there's a clear primary regex that can be established using#regex
and any secondary regexes can be inlined in the strategy block. We do this with a few complexstrategy
blocks in homebrew/core (e.g.,bash
).The issue is that some of the cask
strategy
blocks with more than one regex don't have a primary regex that can be reasonably extracted into a#regex
call. These exceptions would prevent us from eventually getting to a point where we standardize on always establishing regexes using#regex
and passing it into a strategy block.One solution to this could be to modify the
#regex
DSL to allow either a hash withRegexp
values or an array ofRegexps
. These would both achieve the same purpose but there are benefits/detriments to each.Either way, we would only allow a non-
Regexp
value when astrategy
block is present (as the strategy wouldn't know what to do with a non-Regexp
value by default). However, we want#regex
to appear before#strategy
in alivecheck
block (to make it clear that it's the same regex being passed into thestrategy
block), so this would need to be enforced somewhere outside of the#regex
DSL method.Allowing for multiple regexes when using
#regex
would also let us avoid having to determine which regex is a primary regex and which are secondary. This is currently a bit subjective, so it would be nice to avoid this question entirely.This shouldn't be difficult to implement, so I'll investigate it and work on creating a PR.