Skip to content

Fix the test filter dropping tests it should run - #190

Merged
sheredom merged 1 commit into
sheredom:mainfrom
bernardladenthin:fix-filter-trailing-wildcard
Aug 18, 2026
Merged

Fix the test filter dropping tests it should run#190
sheredom merged 1 commit into
sheredom:mainfrom
bernardladenthin:fix-filter-trailing-wildcard

Conversation

@bernardladenthin

Copy link
Copy Markdown
Contributor

utest_should_filter_test gets two things wrong. Both fail the same way: the
test is silently skipped, and nothing is reported — the run just comes back
green with fewer tests than you asked for.

A trailing wildcard never matches the empty remainder

--filter=*bar runs foo.bar
--filter=ba runs foo.bar
--filter=bar does not

Once the name is exhausted, a wildcard still left in the filter is treated as a mismatch rather than as standing for nothing. It bites in two places: when the inner wildcard loop runs out of name, and when the outer loop does.

A wildcard cannot give characters back

On a mismatch the filter position is reset to the wildcard, but the name position is not, so the retry resumes partway through the name instead of one character on from where the attempt began. This is not an edge case:

--filter=o.b does not match foo.bar

The change

Replaced with the usual iterative glob match — remember the wildcard and the position to resume from, and on a mismatch let the wildcard swallow one more character. It handles both defects, and utest.h comes out 24 lines shorter than before.

Measured over 21 filter/name pairs: the current implementation answers 6 of them wrongly, the replacement none. Patching only the trailing-wildcard case still leaves 3 wrong, which is why this replaces the function rather than guarding it.

Tests

Six tests covering exact names, leading and trailing wildcards, literals after an exhausted name, and backtracking. They call the function directly instead of spawning a binary, so unlike the utest_cmdline suite they also run under MinGW.

Five of the six fail against the current implementation — checked, so they are known to have teeth rather than assumed to.

new tests, current header red
new tests, this change green
whole suite, untouched main green, 2161
whole suite, this change green, 2167

Independent of #188 and #189; applies to main on its own.

utest_should_filter_test got two things wrong, and both silently skip a test
rather than report anything.

A trailing wildcard never matched the empty remainder, so --filter=*bar* did
not run foo.bar although --filter=*bar and --filter=*ba* both did. The name
being exhausted was treated as a mismatch even with only wildcards left to
consume.

Worse, a wildcard could not give characters back. On a mismatch the filter
position was reset to the wildcard but the name position was not, so the
retry resumed midway through the name. That is not an edge case:
--filter=*o.b* does not match foo.bar today.

Replaced with the usual iterative glob match, which records where to resume
and backtracks properly. It handles both, and is 24 lines shorter than what
it replaces.

Six tests added for the filter, covering exact names, leading and trailing
wildcards, literals after an exhausted name, and backtracking. They call the
function directly rather than spawning a binary, so unlike the utest_cmdline
suite they also run on MinGW. Against the old implementation five of the six
fail; the rest of the suite is unchanged at 2161 tests, 2167 with these.
@sheredom

Copy link
Copy Markdown
Owner

Great find!

@sheredom
sheredom merged commit 8db1cbd into sheredom:main Aug 18, 2026
28 checks passed
@bernardladenthin
bernardladenthin deleted the fix-filter-trailing-wildcard branch August 22, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants