Skip to content
Draft
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions Tests/Rules/UseUsingScopeModifierInNewRunspaces.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ Describe "UseUsingScopeModifierInNewRunspaces" {
}

Context "Should not detect anything" {

It "should not emit anything for: <Description>" {
[System.Array] $warnings = Invoke-ScriptAnalyzer -ScriptDefinition $ScriptBlock -Settings $settings
$warnings.Count | Should -Be 0
Expand Down Expand Up @@ -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 = '{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for making it more readable :-)

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
}'
}
)
}
Expand Down
Loading