Skip to content

Commit b79e2f5

Browse files
authored
Merge pull request #1040 from PowerShell/add_exclude_switch
Allow paths to be pipelined to Invoke-ScriptAnalyzer
2 parents a4f3fe4 + a5c84bb commit b79e2f5

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,9 @@ protected override void BeginProcessing()
279279
this.SessionState,
280280
recurseCustomRulePath);
281281

282-
if (IsFileParameterSet())
282+
if (IsFileParameterSet() && Path != null)
283283
{
284+
// just used to obtain the directory to use to find settings below
284285
ProcessPath();
285286
}
286287

@@ -350,6 +351,11 @@ protected override void ProcessRecord()
350351
return;
351352
}
352353

354+
if (IsFileParameterSet())
355+
{
356+
ProcessPath();
357+
}
358+
353359
#if !PSV3
354360
// TODO Support dependency resolution for analyzing script definitions
355361
if (saveDscDependency)

Tests/Engine/CustomizedRule.tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (-not (Test-PSEditionCoreCLR))
99
$null,"Wow6432Node" | ForEach-Object {
1010
try
1111
{
12-
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force
12+
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue
1313
}
1414
catch
1515
{
@@ -66,7 +66,7 @@ Describe "Test importing correct customized rules" {
6666
$null,"Wow6432Node" | ForEach-Object {
6767
try
6868
{
69-
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force
69+
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -EA SilentlyContinue
7070
}
7171
catch
7272
{

Tests/Engine/InvokeScriptAnalyzer.tests.ps1

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,22 @@ Describe "Test Path" {
180180
Remove-PSDrive $freeDriveName
181181
$numFilesResult | Should -Be $numFilesExpected
182182
}
183-
}
183+
}
184+
185+
Context "When piping in files" {
186+
It "Can be piped in from a string" {
187+
$piped = ("$directory\TestScript.ps1" | Invoke-ScriptAnalyzer)
188+
$explicit = Invoke-ScriptAnalyzer -Path $directory\TestScript.ps1
189+
190+
$piped.Count | Should Be $explicit.Count
191+
}
192+
193+
It "Can be piped from Get-ChildItem" {
194+
$piped = ( Get-ChildItem -Path $directory -Filter TestTestPath*.ps1 | Invoke-ScriptAnalyzer)
195+
$explicit = Invoke-ScriptAnalyzer -Path $directory\TestTestPath*.ps1
196+
$piped.Count | Should Be $explicit.Count
197+
}
198+
}
184199
}
185200

186201
Context "When given a directory" {

Tests/Engine/LibraryUsage.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ $testingLibraryUsage = $true
191191
$null,"Wow6432Node" | ForEach-Object {
192192
try
193193
{
194-
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force
194+
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue
195195
}
196196
catch
197197
{

0 commit comments

Comments
 (0)