Skip to content

Commit 1fe5a77

Browse files
author
kborle
committed
fixes PSDrive and wildcard matching test cases failure
1 parent 534c78e commit 1fe5a77

File tree

1 file changed

+34
-16
lines changed

1 file changed

+34
-16
lines changed

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,23 +70,41 @@ Describe "Test Path" {
7070
}
7171
}
7272

73-
Context "When given a glob" {
74-
It "Invokes on all the matching files" {
75-
$numFilesResult = (Invoke-ScriptAnalyzer -Path $directory\Rule*.ps1 | Select-Object -Property ScriptName -Unique).Count
76-
$numFilesExpected = (Get-ChildItem -Path $directory\Rule*.ps1).Count
77-
$numFilesResult | Should be $numFilesExpected
78-
}
79-
}
80-
81-
Context "When given a FileSystem PSDrive" {
82-
It "Recognizes the path" {
83-
$freeDrive = 69..90 | %{([char]$_)+":"} | ?{!(Test-Path $_)} | Select-Object -First 1
84-
New-PSDrive -Name $freeDrive[0] -PSProvider FileSystem -Root $directory
85-
$numFilesExpected = (Get-ChildItem -Path $freeDrive\R*.ps1).Count
86-
$numFilesResult = (Invoke-ScriptAnalyzer -Path $freeDrive\Rule*.ps1 | Select-Object -Property ScriptName -Unique).Count
87-
$numFilesResult | Should Be $numFilesExpected
73+
if (!$testingLibraryUsage)
74+
{
75+
#There is probably a more consice way to do this but for now we will settle for this!
76+
Function GetFreeDrive ($freeDriveLen) {
77+
$ordA = 65
78+
$ordZ = 90
79+
$freeDrive = ""
80+
$freeDriveName = ""
81+
do{
82+
$freeDriveName = (1..$freeDriveLen | %{[char](Get-Random -Maximum $ordZ -Minimum $ordA)}) -join ''
83+
$freeDrive = $freeDriveName + ":"
84+
}while(Test-Path $freeDrive)
85+
$freeDrive, $freeDriveName
86+
}
87+
88+
Context "When given a glob" {
89+
It "Invokes on all the matching files" {
90+
$numFilesResult = (Invoke-ScriptAnalyzer -Path $directory\Rule*.ps1 | Select-Object -Property ScriptName -Unique).Count
91+
$numFilesExpected = (Get-ChildItem -Path $directory\Rule*.ps1).Count
92+
$numFilesResult | Should be $numFilesExpected
93+
}
94+
}
95+
96+
Context "When given a FileSystem PSDrive" {
97+
It "Recognizes the path" {
98+
$freeDriveNameLen = 2
99+
$freeDrive, $freeDriveName = GetFreeDrive $freeDriveNameLen
100+
New-PSDrive -Name $freeDriveName -PSProvider FileSystem -Root $directory
101+
$numFilesExpected = (Get-ChildItem -Path $freeDrive\R*.ps1).Count
102+
$numFilesResult = (Invoke-ScriptAnalyzer -Path $freeDrive\Rule*.ps1 | Select-Object -Property ScriptName -Unique).Count
103+
Remove-PSDrive $freeDriveName
104+
$numFilesResult | Should Be $numFilesExpected
105+
}
106+
}
88107
}
89-
}
90108

91109
Context "When given a directory" {
92110
$withoutPathWithDirectory = Invoke-ScriptAnalyzer -Recurse $directory\RecursionDirectoryTest

0 commit comments

Comments
 (0)