Files
PowerShell/test/powershell/Write-Debug.Tests.ps1
T

46 lines
1.3 KiB
PowerShell
Raw Normal View History

2016-04-29 01:07:57 -07:00
Describe "Write-Debug DRT Unit Tests" -Tags DRT{
2016-04-27 01:08:53 -07:00
function unittest-writedebugline
{
2016-04-29 01:07:57 -07:00
$DebugPreference = 'continue'
Write-Debug "this is a test"
}
function unittest-writedebug
{
[cmdletbinding()]
Param (
[String]$Value
)
$PSBoundParameters.GetEnumerator() | ForEach {
2016-05-10 00:33:33 -07:00
Write-Verbose $_
2016-04-29 01:07:57 -07:00
}
Write-Verbose "DebugPreference: $DebugPreference"
If ($PSBoundParameters['Debug']) {
$DebugPreference = 'Continue'
}
Write-Debug $Value
2016-04-27 01:08:53 -07:00
}
2016-04-29 01:07:57 -07:00
It 'Write-Debug Test1: $DebugPreference is set' {
$ps = [PowerShell]::Create()
$null = $ps.AddScript("`$o = 'this is a test';`$DebugPreference = 'continue';Write-Debug `$o").Invoke()
$ps.Streams.Debug | Should Be 'this is a test'
2016-04-27 01:08:53 -07:00
}
2016-04-29 01:07:57 -07:00
It "Write-Debug Test2: Calling a cmdleting binding and passing -Debug " {
$ps = [PowerShell]::Create()
$null = $ps.AddScript("Write-Debug foo -debug").Invoke()
$ps.Streams.Debug | Should Be 'foo'
}
It "Write-Debug Test3: Calling a regular function" {
unittest-writedebugline 5>&1 | Should Be 'this is a test'
2016-04-27 01:08:53 -07:00
}
2016-04-29 01:07:57 -07:00
It "Write-Debug Test4: Redirecting the debug stream" {
unittest-writedebug -Value "foo" -Debug 5>&1 | Should Be 'foo'
2016-04-27 01:08:53 -07:00
}
2016-04-29 01:07:57 -07:00
}