This file contains hidden or 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
$syncHash = [hashtable]::Synchronized(@{ | |
Browser = $null | |
Window = $null | |
}) | |
$psCmd = [powershell]::Create() | |
$newRunspace = [RunspaceFactory]::CreateRunspace() | |
$newRunspace.Open() | |
$newRunspace.SessionStateProxy.SetVariable('syncHash', $syncHash) |
This file contains hidden or 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
function k () { | |
write-host function k from file | |
} | |
$b = "from file" |
This file contains hidden or 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
function ItWithTag ( | |
$Name, | |
$Body, | |
$Tag | |
) { | |
if ($null -eq $global:Tags -or 0 -eq $global:Tags.Length -or $global:Tags -contains $Tag) { | |
It $Name $Body | |
} | |
} |
This file contains hidden or 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
# getting a piece of code from a user that we want to wrap, | |
# and execute, we often need to pass in additional parameters | |
# at least the script itself, and this poses a problem because | |
# the parameter name will conflict with the user script. | |
# (we want to add a wrapper for example to run two pieces of code | |
# in the same scope, without leaking variables into a parent scope) | |
# here for simplicity all the scriptblocks are running in the | |
# same session state, and we chose variable $A to pass the user |
This file contains hidden or 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
function a () { | |
b | |
} | |
function b () { | |
c | |
} | |
function c () { | |
throw "error" |
This file contains hidden or 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
# Logging verbose info to screen is useful for debugging | |
# but the info is hidden 99% of the time. Problem is that | |
# evaluating a string to get the verbose message will run | |
# even if we never actually print it, adding overhead to | |
# every run, not just runs that are verbose. | |
# to avoid this passing a script block that evaluates to the | |
# message string conditionally seems to work well | |
This file contains hidden or 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
# runs tests with summary | |
i { | |
b "Basic" { | |
t "Given a scriptblock with 1 test in it, it finds 1 test" { | |
$true | |
} | |
} | |
} | |
# runs tests without summary |
This file contains hidden or 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
# Apply a remedy after a Pester test fails to fix the problem that caused | |
# the test to fails (eg. all inactive AD users should be disabled, | |
# so a remedy is to disable all inactive users) | |
function RetryAndFix ([scriptBlock]$Test, [scriptBlock]$Fix, $Wait) { | |
try { | |
& $Test | |
} | |
catch { |
This file contains hidden or 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
Get-Module Pester, A, B | Remove-Module | |
Import-Module C:\Projects\Pester_main\Pester.psd1 | |
New-Module A { } | Import-Module | |
New-Module B { | |
function Greet ($Name) { Hello -Name $Name } | |
function Hello ($Name) { "Hello, $Name" } | |
Export-ModuleMember -Function WrapWrapWrap, Greet | |
} | Import-Module |
This file contains hidden or 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
# in module scope | |
$script:pester | |
function describe () { | |
$script:pester.EnterBlock("describe") | |
} | |
function it () { |