diff --git a/Tests/Rules/UseUsingScopeModifierInNewRunspaces.tests.ps1 b/Tests/Rules/UseUsingScopeModifierInNewRunspaces.tests.ps1 index 65ba1fdec..687df807a 100644 --- a/Tests/Rules/UseUsingScopeModifierInNewRunspaces.tests.ps1 +++ b/Tests/Rules/UseUsingScopeModifierInNewRunspaces.tests.ps1 @@ -146,7 +146,6 @@ Describe "UseUsingScopeModifierInNewRunspaces" { } Context "Should not detect anything" { - It "should not emit anything for: " { [System.Array] $warnings = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptBlock -Settings $settings $warnings.Count | Should -Be 0 @@ -278,20 +277,41 @@ Describe "UseUsingScopeModifierInNewRunspaces" { # Issue 1492: https://github.com/PowerShell/PSScriptAnalyzer/issues/1492 @{ Description = 'Does not throw when the same variable name is used in two different sessions' - ScriptBlock = @' -function Get-One{ - Invoke-Command -Session $sourceRemoteSession { - $a = $sccmModule - foo $a - } -} -function Get-Two{ - Invoke-Command -Session $sourceRemoteSession { - $a = $sccmModule - foo $a - } -} -'@ + ScriptBlock = '{ + function Get-One { + Invoke-Command -Session -ScriptBlock $sourceRemoteSession { + $a = $sccmModule + foo $a + } + } + function Get-Two { + Invoke-Command -Session -ScriptBlock $sourceRemoteSession { + $a = $sccmModule + foo $a + } + } + }' + } + # ScriptBlock with variables in params(), issue #1504: https://github.com/PowerShell/PSScriptAnalyzer/issues/1504 + ## Microsoft.PowerShell.Core \ Start-Job + @{ + Description = 'Does not warn when variable is defined inside param() - Start-Job' + ScriptBlock = '{ + Start-Job -ScriptBlock { + Param($Foo) + $Foo + } -ArgumentList "Bar" | Receive-Job -Wait -AutoRemoveJob + }' + } + ## Microsoft.PowerShell.ThreadJob \ Start-ThreadJob + @{ + Description = 'Does not warn when variable is defined inside param() - Start-Job' + ScriptBlock = '{ + Start-ThreadJob -ScriptBlock { + Param($Foo) + $Foo + } -ArgumentList "Bar" | Receive-Job -Wait -AutoRemoveJob + }' } ) }