Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for #1504 PSUseUsingScopeModifierInNewRunspaces #2005

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all 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