Skip to content

Commit 7a26d8d

Browse files
jessehouwingCopilot
andcommitted
Fix Linux CI: restrict backslash-separator test cases to Windows
Backslash is not a path separator on Linux/macOS, so a backslash- separated dot-source literal never resolves to a file there (matching real dot-sourcing behavior) - the rule correctly produced no diagnostic, but the test still expected one. Also moved the test-case array out of BeforeAll into the Describe body, since -TestCases is bound during Pester's discovery phase, before BeforeAll runs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 63b4e71 commit 7a26d8d

1 file changed

Lines changed: 12 additions & 24 deletions

File tree

‎Tests/Rules/UseCorrectCasingForDotSourcedFiles.tests.ps1‎

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
# Licensed under the MIT License.
33

44
Describe "UseCorrectCasingForDotSourcedFiles" {
5+
# Backslash is only a path separator on Windows; on other platforms it is just a
6+
# character in the file name, so a backslash-separated path never resolves to a file
7+
# and is therefore excluded from the case-mismatch scenarios there. This must be evaluated
8+
# at discovery time (outside BeforeAll) since -TestCases is bound during discovery.
9+
$separatorTestCases = if ($IsWindows) { @(@{ Separator = '\' }, @{ Separator = '/' }) } else { @(@{ Separator = '/' }) }
10+
511
BeforeAll {
612
$settings = @{
713
IncludeRules = @('PSUseCorrectCasingForDotSourcedFiles')
@@ -23,10 +29,7 @@ Describe "UseCorrectCasingForDotSourcedFiles" {
2329
}
2430

2531
Context "`$PSScriptRoot-relative path" {
26-
It "flags a dot-sourced path whose casing does not match the file on disk (separator: '<Separator>')" -TestCases @(
27-
@{ Separator = '\' }
28-
@{ Separator = '/' }
29-
) {
32+
It "flags a dot-sourced path whose casing does not match the file on disk (separator: '<Separator>')" -TestCases $separatorTestCases {
3033
param($Separator)
3134
$callerPath = NewWorkload -FileNames @('Helpers.ps1') -CallerContent ". `$PSScriptRoot${Separator}HELPERS.ps1"
3235

@@ -39,10 +42,7 @@ Describe "UseCorrectCasingForDotSourcedFiles" {
3942
$diagnostics[0].SuggestedCorrections[0].Text | Should -Match 'Helpers\.ps1'
4043
}
4144

42-
It "does not flag a dot-sourced path whose casing matches the file on disk (separator: '<Separator>')" -TestCases @(
43-
@{ Separator = '\' }
44-
@{ Separator = '/' }
45-
) {
45+
It "does not flag a dot-sourced path whose casing matches the file on disk (separator: '<Separator>')" -TestCases $separatorTestCases {
4646
param($Separator)
4747
$callerPath = NewWorkload -FileNames @('Helpers.ps1') -CallerContent ". `$PSScriptRoot${Separator}Helpers.ps1"
4848

@@ -51,10 +51,7 @@ Describe "UseCorrectCasingForDotSourcedFiles" {
5151
}
5252

5353
Context "Relative path" {
54-
It "flags a dot-sourced path whose casing does not match the file on disk (separator: '<Separator>')" -TestCases @(
55-
@{ Separator = '\' }
56-
@{ Separator = '/' }
57-
) {
54+
It "flags a dot-sourced path whose casing does not match the file on disk (separator: '<Separator>')" -TestCases $separatorTestCases {
5855
param($Separator)
5956
$callerPath = NewWorkload -FileNames @('Helpers.ps1') -CallerContent ". .${Separator}HELPERS.ps1"
6057

@@ -65,10 +62,7 @@ Describe "UseCorrectCasingForDotSourcedFiles" {
6562
$diagnostics[0].SuggestedCorrections[0].Text | Should -Match 'Helpers\.ps1'
6663
}
6764

68-
It "does not flag a dot-sourced path whose casing matches the file on disk (separator: '<Separator>')" -TestCases @(
69-
@{ Separator = '\' }
70-
@{ Separator = '/' }
71-
) {
65+
It "does not flag a dot-sourced path whose casing matches the file on disk (separator: '<Separator>')" -TestCases $separatorTestCases {
7266
param($Separator)
7367
$callerPath = NewWorkload -FileNames @('Helpers.ps1') -CallerContent ". .${Separator}Helpers.ps1"
7468

@@ -87,10 +81,7 @@ Describe "UseCorrectCasingForDotSourcedFiles" {
8781
}
8882

8983
Context "Absolute path" {
90-
It "flags a dot-sourced path whose casing does not match the file on disk (separator: '<Separator>')" -TestCases @(
91-
@{ Separator = '\' }
92-
@{ Separator = '/' }
93-
) {
84+
It "flags a dot-sourced path whose casing does not match the file on disk (separator: '<Separator>')" -TestCases $separatorTestCases {
9485
param($Separator)
9586
$callerPath = NewWorkload -FileNames @('Helpers.ps1') -CallerContent 'PLACEHOLDER'
9687
$root = Split-Path $callerPath -Parent
@@ -104,10 +95,7 @@ Describe "UseCorrectCasingForDotSourcedFiles" {
10495
$diagnostics[0].SuggestedCorrections[0].Text | Should -Match 'Helpers\.ps1'
10596
}
10697

107-
It "does not flag a dot-sourced path whose casing matches the file on disk (separator: '<Separator>')" -TestCases @(
108-
@{ Separator = '\' }
109-
@{ Separator = '/' }
110-
) {
98+
It "does not flag a dot-sourced path whose casing matches the file on disk (separator: '<Separator>')" -TestCases $separatorTestCases {
11199
param($Separator)
112100
$callerPath = NewWorkload -FileNames @('Helpers.ps1') -CallerContent 'PLACEHOLDER'
113101
$root = Split-Path $callerPath -Parent

0 commit comments

Comments
 (0)