Repository navigation
Add a typed test filter model and a VSTest-conformant filter parser with legacy fallback - #1553
Open
PanzerFowst wants to merge 15 commits into
Open
PanzerFowst wants to merge 15 commits into
PanzerFowst wants to merge 15 commits into
Conversation
…VSTest first, and add the FilterParser setting
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds a typed test filter model and a VSTest-conformant filter parser, and routes the adapter's filter parsing through them. By default, filters keep working as before: the VSTest parser is tried first, and a filter it rejects goes to the existing (now
LegacyTestFilterParser) parser.Related to #505. Went over original design with @OsirisTerje in call.
The design is described in
docs/VSTestFilterParserDesign.md(which I will delete before completing the PR).Pipeline
What changes
TestFilterConverter/FilterModel/): expression / term / factor / group / negation / condition nodes.TestFilterComparison { Exact, Contains }.!=and!~are a negation node around a condition, not separate operators.ITestFilterVisitor<T>, withNUnitFilterXmlWriterand aToNUnitXml()extension producing NUnit filter XML. This design allows for other outputs, such as JSON or an MTP evaluator, to be added later as new visitors without touching the model or the parsers.ITestFilterParser:VSTestFilterParser: new. It follows VSTest's escaping and grouping rules, rejects malformed input, and reports an error position.LegacyTestFilterParser: the existingTestFilterParser, renamed. Its behavior is unchanged.DefaultTestFilterParser: tries an ordered list of parsers (VSTest first, then Legacy) and returns the first result.NUnitTestFilterBuilder.FilterByNamesnow builds name filters through the model.TestNameFilteris reduced to the internalTestNameRegex.XmlEscaperHelperis removed.NUnitTestFilterBuilderand the discoverer receive the parser instead of creating one. It is chosen once, inNUnitTestAdapter.Initialize.RunTestsand again for every test assembly. Both conversions have existed since 2020. The per-assembly one always produced the same result, soVsTestExecutionnow uses the filter it is given.New run setting:
FilterParserDefault(default)VSTestLegacyUnder MTP it can currently only be set through a runsettings file (
--settings).Compatibility
Behaviour: I ran 17 representative filters through both parsers.
(in a name such asFullyQualifiedName=A.B(1,2), and!(Name=A).So the new default is not expected to change which tests a filter selects. Making strict VSTest the default would be breaking and is left for a major version.
API: these public types change, which is binary-breaking for anyone using them directly:
NUnitTestFilterBuilderconstructor now takes anITestFilterParser;IExecutionContextandIAdapterSettingsgain a member each;TestFilterParseris renamedLegacyTestFilterParser.The new model and parser types are public. Happy to make them
internalif you prefer a smaller public surface.Testing
FilterModelTests: model and XML writer, including everyTestFilterComparisonvalue;TestFilterParserConformanceTests: VSTest vs Legacy, intended differences, error positions;DefaultTestFilterParserTests;FilterParsersetting inAdapterSettingsTests;NUnitTestFilterBuilderTests;VsTestExecutionTests: the filter is not parsed again for each assembly.build -t test: net462 767 passed / 45 skipped; net8.0 764 passed / 42 skipped.build -t acceptance: 227 passed.dotnet testagainst the built package. With the default parser, a VSTest-invalid filter logs one Info line and still selects the right test.FilterParser=VSTestreports the VSTest error, andFilterParser=Legacybehaves as before.Use of AI
I designed this and drove it commit by commit, using GitHub Copilot to draft code, tests, and docs. I reviewed every change and ran the unit and acceptance tests after each step.
Possible follow-ups
FullyQualifiedNamefast path throughITestFilterParser.FilterParserin nunit/docs.Review guide
The commits are designed to be read one at a time; each one builds and passes its tests. Suggested order:
324d9c1,cc53f42: filter model interfaces and types (no behaviour change)7cb9614,3363eae,4c9eca1:VSTestFilterParserand its tests (not wired in yet)329b0c8: renameTestFilterParser→LegacyTestFilterParser(rename only)bc0eccb,f1cba8f: the legacy parser produces the model;!(...)becomes a negation node54424b0,981767c: comparison enum; XML output moves into a visitor236862c: name filters built through the model14f644d: parser injection,DefaultTestFilterParser,FilterParsersettingf6fd156: parse the filter once per run instead of once per assemblyIn the combined diff,
TestFilterParser.cs→LegacyTestFilterParser.csshows as a delete plus an add. Commit 3 shows it as a rename.Final Note
This is a large PR. If you would prefer it split (e.g., model + XML writer in one PR and the parsers and the setting in a second), I'm happy to do that.