Skip to content

Add exclusion pattern support to --test-modules glob expressions#54252

Open
Copilot wants to merge 8 commits into
mainfrom
copilot/add-exclusion-patterns-to-test-modules
Open

Add exclusion pattern support to --test-modules glob expressions#54252
Copilot wants to merge 8 commits into
mainfrom
copilot/add-exclusion-patterns-to-test-modules

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

New Feature

What does this feature do?

--test-modules now supports !-prefixed exclusion patterns in the semicolon-separated glob expression, consistent with VSTest behavior. Patterns with and without ! can be freely mixed:

dotnet test --test-modules "*.mstest.exe"
dotnet test --test-modules "!*.toexclude.exe"
dotnet test --test-modules "*.mstest.exe; !*.toexclude.mstest.exe"

Why is this feature needed?

Previously all patterns were treated as includes only, making it impossible to exclude specific assemblies from a broad glob match without listing every desired assembly explicitly.

Implementation details

  • TestModulesFilterHandler.GetMatchedModulePaths: Each ;-separated token is now trimmed of surrounding whitespace, then routed to either Matcher.AddExclude (if prefixed with !, stripping the prefix and any trailing whitespace) or Matcher.AddInclude.
  • Implicit include: When the expression contains only exclusion patterns, ** is implicitly added as an include so the result is "all files minus excluded."
  • Test: Added RunTestProjectsWithIncludeAndExcludeFilterOfDll_ShouldReturnExitCodeSuccess — builds two test projects, runs with a combined include+exclude filter that drops the failing project, and asserts only the passing project executed.

Copilot AI and others added 2 commits May 11, 2026 15:36
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
…(MTP) CLI

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for exclusion patterns in --test-modules for dotnet test Add exclusion pattern support to --test-modules glob expressions May 11, 2026
Copilot AI requested a review from Evangelink May 11, 2026 15:41
@Evangelink Evangelink marked this pull request as ready for review May 11, 2026 20:51
@Evangelink Evangelink requested a review from a team as a code owner May 11, 2026 20:51
Copilot AI review requested due to automatic review settings May 11, 2026 20:51
@Evangelink Evangelink requested a review from a team as a code owner May 11, 2026 20:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for !-prefixed exclusion patterns in dotnet test --test-modules glob expressions (MTP path filtering), aligning behavior with common globbing semantics and enabling “include broad, then exclude specific” scenarios.

Changes:

  • Update TestModulesFilterHandler.GetMatchedModulePaths to parse ;-separated patterns as includes vs excludes (leading !) and trim whitespace.
  • Add implicit include ("**") when only exclusion patterns are provided.
  • Add an integration test validating combined include+exclude module filtering.
Show a summary per file
File Description
test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTestBasedOnGlobbingFilter.cs Adds a test that validates include+exclude behavior for --test-modules.
src/Cli/dotnet/Commands/Test/MTP/TestModulesFilterHandler.cs Implements parsing and matching logic for exclusion patterns and exclusion-only expressions.
src/Microsoft.CodeAnalysis.NetAnalyzers/src/Microsoft.CodeAnalysis.NetAnalyzers.sarif Appears to change only file encoding/format (BOM/whitespace), unrelated to the feature.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 2

Comment thread src/Cli/dotnet/Commands/Test/MTP/TestModulesFilterHandler.cs
@Evangelink
Copy link
Copy Markdown
Member

@copilot address review comments

…s as internal

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 14, 2026

@copilot address review comments

Addressed both review comments:

  1. SARIF encoding change — was already reverted in a prior session (commit 437dc17); the file is back to its original encoding.

  2. Exclusion-only test coverageGetMatchedModulePaths is now internal (dotnet.Tests already has InternalsVisibleTo access), and two focused unit tests were added:

    • ExclusionOnlyFilterPattern_MatchesAllFilesExceptExcluded — creates a temp dir with three known files, uses !ExcludeMe.dll (exclusion-only), and asserts exactly the two non-excluded files are returned.
    • ExclusionOnlyFilterPattern_WithSpaceAfterBang_MatchesCorrectly — validates the ! ExcludeMe.dll (space after !) trimming edge case as well.

All 6 tests pass.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
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.

Add support for exclusion patterns in --test-modules for dotnet test (MTP) CLI

3 participants