mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
With this commit, users who invoke a command with -Debug will no longer be presented with a prompt asking them if they want to enter a nested prompt, continue execution, or halt execution entirely. Instead, any messages sent to the debug stream will simply be sent to the debug stream and the script will continue execution.
34 lines
1.3 KiB
PowerShell
34 lines
1.3 KiB
PowerShell
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
# Licensed under the MIT License.
|
|
Describe "Write-Debug tests" -Tags "CI" {
|
|
It "Should not have added line breaks" {
|
|
$text = "0123456789"
|
|
while ($text.Length -lt [Console]::WindowWidth) {
|
|
$text += $text
|
|
}
|
|
$origDebugPref = $DebugPreference
|
|
$DebugPreference = "Continue"
|
|
try {
|
|
$out = Write-Debug $text 5>&1
|
|
$out | Should -BeExactly $text
|
|
}
|
|
finally {
|
|
$DebugPreference = $origDebugPref
|
|
}
|
|
}
|
|
|
|
It "Should not prompt the user" {
|
|
# This script generates an error if Write-Debug prompts the user
|
|
# (i.e. if $DebugPreference is set to Inquire, the old v1 way)
|
|
$p = [Diagnostics.Process]::new()
|
|
$p.StartInfo.FileName = (Get-Process -Id $PID).Path
|
|
$encoded = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes("Write-Debug -Message 'A debug message' -Debug"))
|
|
$p.StartInfo.Arguments = "-EncodedCommand $encoded -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -OutputFormat text"
|
|
$p.StartInfo.UseShellExecute = $false
|
|
$p.StartInfo.RedirectStandardError = $true
|
|
$p.Start() | Out-Null
|
|
$out = $p.StandardError.ReadToEnd()
|
|
$out | Should -BeNullOrEmpty
|
|
}
|
|
}
|