Skip to content

Commit 6a4cc32

Browse files
Copilotbergmeister
andauthored
Add Test-ScriptAnalyzer path selection tests
Co-authored-by: bergmeister <9250262+bergmeister@users.noreply.github.com>
1 parent 40453a5 commit 6a4cc32

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

‎Tests/Build/BuildModule.tests.ps1‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,56 @@ Describe "Build Module Tests" {
4848
}
4949
}
5050

51+
Context "Test-ScriptAnalyzer test path selection" {
52+
BeforeEach {
53+
Mock Invoke-Pester { $Path } -ModuleName build
54+
}
55+
56+
It "selects only the supplied test file" {
57+
$testPath = Join-Path $TestDrive "single.tests.ps1"
58+
New-Item -Path $testPath -ItemType File | Out-Null
59+
60+
$selectedPaths = @(Test-ScriptAnalyzer -InProcess -TestPath $testPath)
61+
62+
$selectedPaths.Count | Should -Be 1
63+
$selectedPaths[0] | Should -Be (Resolve-Path -LiteralPath $testPath).Path
64+
}
65+
66+
It "passes test paths containing apostrophes intact" {
67+
$testPath = Join-Path $TestDrive "one'two.tests.ps1"
68+
New-Item -Path $testPath -ItemType File | Out-Null
69+
70+
$selectedPaths = @(Test-ScriptAnalyzer -InProcess -TestPath $testPath)
71+
72+
$selectedPaths.Count | Should -Be 1
73+
$selectedPaths[0] | Should -Be (Resolve-Path -LiteralPath $testPath).Path
74+
}
75+
76+
It "fails when the supplied test path does not exist" {
77+
{ Test-ScriptAnalyzer -InProcess -TestPath (Join-Path $TestDrive "missing.tests.ps1") } | Should -Throw
78+
}
79+
80+
It "fails when the supplied test path is a directory" {
81+
{ Test-ScriptAnalyzer -InProcess -TestPath $TestDrive } | Should -Throw "TestPath must point to a test file."
82+
}
83+
84+
It "selects the four default test suite directories when no path is supplied" {
85+
$selectedPaths = @(Test-ScriptAnalyzer -InProcess)
86+
$repoRoot = (Resolve-Path -LiteralPath (Join-Path $PSScriptRoot "..\..")).Path
87+
$expectedPaths = @(
88+
"${repoRoot}\Tests\Build"
89+
"${repoRoot}\Tests\Engine"
90+
"${repoRoot}\Tests\Rules"
91+
"${repoRoot}\Tests\Documentation"
92+
)
93+
94+
$selectedPaths.Count | Should -Be 4
95+
foreach ($expectedPath in $expectedPaths) {
96+
$selectedPaths | Should -Contain $expectedPath
97+
}
98+
}
99+
}
100+
51101
Context "Test result functions" {
52102
BeforeAll {
53103
$xmlFile = @'

0 commit comments

Comments
 (0)