Skip to content

Commit 4766205

Browse files
author
Kapil Borle
committed
Merge pull request #311 from kapilmb/psdrivebugfix
Fixes PSDrive and wildcard matching bugs
2 parents f5cb4fc + e9b1417 commit 4766205

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System;
1515
using System.ComponentModel;
1616
using System.Collections.Generic;
17+
using System.Collections.ObjectModel;
1718
using System.Diagnostics.CodeAnalysis;
1819
using System.Globalization;
1920
using System.Linq;
@@ -159,9 +160,12 @@ protected override void BeginProcessing()
159160
/// </summary>
160161
protected override void ProcessRecord()
161162
{
162-
// throws Item Not Found Exception
163-
path = this.SessionState.Path.GetResolvedPSPathFromPSPath(path).First().ToString();
164-
ProcessPath(path);
163+
// throws Item Not Found Exception
164+
Collection<PathInfo> paths = this.SessionState.Path.GetResolvedPSPathFromPSPath(path);
165+
foreach (PathInfo p in paths)
166+
{
167+
ProcessPath(this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(p.Path));
168+
}
165169
}
166170

167171
#endregion

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,42 @@ Describe "Test Path" {
7070
}
7171
}
7272

73+
if (!$testingLibraryUsage)
74+
{
75+
#There is probably a more concise 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+
}
107+
}
108+
73109
Context "When given a directory" {
74110
$withoutPathWithDirectory = Invoke-ScriptAnalyzer -Recurse $directory\RecursionDirectoryTest
75111
$withPathWithDirectory = Invoke-ScriptAnalyzer -Recurse -Path $directory\RecursionDirectoryTest

0 commit comments

Comments
 (0)