Exclude directories, not just files, in ExcludePath#2885
Merged
Conversation
Filter-Excluded only matched discovered test files against each ExcludePath entry with -like, so a directory path never matched any file inside it and directory exclusions were silently ignored, even though Run.ExcludePath is documented as "Directories or files to be excluded from the run." Keep the existing wildcard/exact -like matching and additionally treat a non-wildcard exclusion as a directory prefix: a file is excluded when its full path starts with the exclusion plus a directory separator. Trailing separators are trimmed so 'dir' and 'dir\' behave the same, and the prefix comparison is case-insensitive on Windows and case-sensitive on Linux/macOS. Co-authored-by: Copilot App <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.
Fix #1575
Problem
Run.ExcludePathis documented as "Directories or files to be excluded from the run.", but directory exclusions were silently ignored — only file paths and wildcard patterns actually excluded anything.The cause is in
Filter-Excluded(src/Pester.RSpec.ps1): each discovered test file's full path was only tested against every exclusion with-like. When the exclusion is a directory (e.g.C:\proj\excluded), no file inside that directory matches, because-likeneeds an exact/glob match against the whole file path. SoInvoke-Pester -Path <root> -ExcludePath <root>\excludedstill ran the tests underexcluded.Fix
Keep the existing wildcard/exact
-likebehavior, and additionally treat a non-wildcard exclusion as a directory prefix: a file is excluded when its normalized full path starts with the exclusion plus a directory separator.diranddir\behave the same.*/excluded/*) are left entirely to-like, so existing glob behavior is unchanged.Tests
Added a regression block in
tst/Pester.RSpec.ts.ps1(Excluding directories from a run) with a two-subdirectory layout, asserting that:Both fail on
mainand pass with this change. The rest ofPester.RSpec.ts.ps1is unaffected (the 3 remaining failures in that file are pre-existing and unrelated —SkipRemainingOnFailureCount). PSScriptAnalyzer with the repo settings reports no new findings on the changed lines.Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com