-
-
Save RamblingCookieMonster/05552112507db8a04246 to your computer and use it in GitHub Desktop.
Variable Scope Tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Run this ps1, or just copy and paste the code... it will fail pester tests. | |
Remove-Variable -Name __DummyVariable -ErrorAction SilentlyContinue | |
"In SomeScript.ps1 via call operator" | |
& .\SomeScript.ps1 | |
Remove-Variable -Name __DummyVariable -ErrorAction SilentlyContinue | |
"In SomeScript.ps1 via dot source operator" | |
. .\SomeScript.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Import-Module .\Test-Variable.psm1 -force | |
$__DummyVariable = "hi!" | |
Describe "Test-Variable" { | |
Context 'Module' { | |
It 'should see _DummyVariable' { | |
( Test-Variable ) -contains "__DummyVariable" | Should be $True | |
} | |
} | |
} | |
Import-Module .\Test-Variable.ps1 -force | |
Describe "Test-Variable" { | |
Context 'Function' { | |
It 'should see _DummyVariable' { | |
( Test-Variable ) -contains "__DummyVariable" | Should be $True | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#This is a script to abstract out pester tests | |
Invoke-Pester .\Pester.Tests.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A simple function, not in a module | |
function Test-Variable { | |
echo 0,1,2,local,script,global | %{Get-Variable -Scope $_ -ErrorAction SilentlyContinue} | Select -ExpandProperty Name | sort -Unique | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#A simple module | |
function Test-Variable { | |
echo 0,1,2,local,script,global | %{Get-Variable -Scope $_ -ErrorAction SilentlyContinue} | Select -ExpandProperty Name | sort -Unique | |
} | |
Export-ModuleMember Test-Variable |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment