@@ -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