From 13310ea39dfca44ba595a9d735fa923bd98f95ca Mon Sep 17 00:00:00 2001 From: Edwin Young Date: Mon, 16 Jul 2018 21:29:27 -0700 Subject: [PATCH 1/6] suppress errors running test cases when not admin --- Tests/Engine/CustomizedRule.tests.ps1 | 4 ++-- Tests/Engine/LibraryUsage.tests.ps1 | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/Engine/CustomizedRule.tests.ps1 b/Tests/Engine/CustomizedRule.tests.ps1 index 2062f995a..753a82d05 100644 --- a/Tests/Engine/CustomizedRule.tests.ps1 +++ b/Tests/Engine/CustomizedRule.tests.ps1 @@ -9,7 +9,7 @@ if (-not (Test-PSEditionCoreCLR)) $null,"Wow6432Node" | ForEach-Object { try { - Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force + Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue } catch { @@ -66,7 +66,7 @@ Describe "Test importing correct customized rules" { $null,"Wow6432Node" | ForEach-Object { try { - Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force + Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -EA SilentlyContinue } catch { diff --git a/Tests/Engine/LibraryUsage.tests.ps1 b/Tests/Engine/LibraryUsage.tests.ps1 index a33d4fa3f..47930561f 100644 --- a/Tests/Engine/LibraryUsage.tests.ps1 +++ b/Tests/Engine/LibraryUsage.tests.ps1 @@ -191,7 +191,7 @@ $testingLibraryUsage = $true $null,"Wow6432Node" | ForEach-Object { try { - Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force + Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue } catch { From 669a1a9833251e05ae30a900b798788c5b55ebec Mon Sep 17 00:00:00 2001 From: Edwin Young Date: Mon, 16 Jul 2018 21:29:56 -0700 Subject: [PATCH 2/6] Support piping files to Invoke-ScriptAnalyzer --- Engine/Commands/InvokeScriptAnalyzerCommand.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Engine/Commands/InvokeScriptAnalyzerCommand.cs b/Engine/Commands/InvokeScriptAnalyzerCommand.cs index ae2e0858e..641ceae59 100644 --- a/Engine/Commands/InvokeScriptAnalyzerCommand.cs +++ b/Engine/Commands/InvokeScriptAnalyzerCommand.cs @@ -279,8 +279,9 @@ protected override void BeginProcessing() this.SessionState, recurseCustomRulePath); - if (IsFileParameterSet()) + if (IsFileParameterSet() && Path != null) { + // just used to obtain the directory to use to find settings below ProcessPath(); } @@ -350,6 +351,11 @@ protected override void ProcessRecord() return; } + if (IsFileParameterSet()) + { + ProcessPath(); + } + #if !PSV3 // TODO Support dependency resolution for analyzing script definitions if (saveDscDependency) From 7c8bcc0d948a55c54f47c0b5783f496000ab794c Mon Sep 17 00:00:00 2001 From: Edwin Young Date: Mon, 16 Jul 2018 23:20:50 -0700 Subject: [PATCH 3/6] add test cases for piping --- Tests/Engine/InvokeScriptAnalyzer.tests.ps1 | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 index 049b0f682..2c2db82a8 100644 --- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 +++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 @@ -180,7 +180,22 @@ Describe "Test Path" { Remove-PSDrive $freeDriveName $numFilesResult | Should -Be $numFilesExpected } - } + } + + Context "When piping in files" { + It "Can be piped in from a string" { + $piped = ("$directory\TestScript.ps1" | Invoke-ScriptAnalyzer) + $explicit = Invoke-ScriptAnalyzer -Path $directory\TestScript.ps1 + + $piped.Count -eq $explicit.Count | Should -BeTrue + } + + It "Can be piped from Get-ChildItem" { + $piped = ( Get-ChildItem -Path $directory -Filter TestTestPath*.ps1 | Invoke-ScriptAnalyzer) + $explicit = Invoke-ScriptAnalyzer -Path $directory\TestTestPath*.ps1 + $piped.Count -eq $explicit.Count | Should -BeTrue + } + } } Context "When given a directory" { From b035b4d6d3bc06ac04e90e0abcd8311563ebc898 Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Tue, 17 Jul 2018 22:53:47 +0100 Subject: [PATCH 4/6] restart CI From 6208566d74522bdd792a7f7c63ad8464448cc6ec Mon Sep 17 00:00:00 2001 From: Edwin Young Date: Tue, 17 Jul 2018 21:26:08 -0700 Subject: [PATCH 5/6] PR feedback: use Should better --- Tests/Engine/InvokeScriptAnalyzer.tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 index 2c2db82a8..c43cac665 100644 --- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 +++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 @@ -187,13 +187,13 @@ Describe "Test Path" { $piped = ("$directory\TestScript.ps1" | Invoke-ScriptAnalyzer) $explicit = Invoke-ScriptAnalyzer -Path $directory\TestScript.ps1 - $piped.Count -eq $explicit.Count | Should -BeTrue + $piped.Count | Should Be $explicit.Count } It "Can be piped from Get-ChildItem" { $piped = ( Get-ChildItem -Path $directory -Filter TestTestPath*.ps1 | Invoke-ScriptAnalyzer) $explicit = Invoke-ScriptAnalyzer -Path $directory\TestTestPath*.ps1 - $piped.Count -eq $explicit.Count | Should -BeTrue + $piped.Count | Should Be $explicit.Count } } } From a5c84bbcde4305d00550eb67edb73747b4a8a31f Mon Sep 17 00:00:00 2001 From: Christoph Bergmeister Date: Wed, 18 Jul 2018 23:09:04 +0100 Subject: [PATCH 6/6] restart ci