Skip to content

Debug parameter now sets debugpreference to continue #8195

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

Merged
merged 4 commits into from
Nov 30, 2018
Merged
Show file tree
Hide file tree
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
20 changes: 5 additions & 15 deletions src/System.Management.Automation/engine/MshCommandRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2922,24 +2922,13 @@ internal ActionPreference DebugPreference
get
{
if (_isDebugPreferenceSet)
{
return _debugPreference;
}

if (IsDebugFlagSet)
{
if (Debug)
{
// If the host couldn't prompt for the debug action anyways, use 'Continue'.
// This lets hosts still see debug output without having to implement the prompting logic.
if (CBhost.ExternalHost.UI == null)
{
return ActionPreference.Continue;
}
else
{
return ActionPreference.Inquire;
}
}
else
return ActionPreference.SilentlyContinue;
return Debug ? ActionPreference.Continue : ActionPreference.SilentlyContinue;
}

if (!_isDebugPreferenceCached)
Expand All @@ -2957,6 +2946,7 @@ internal ActionPreference DebugPreference

_isDebugPreferenceCached = true;
}

return _debugPreference;
}
set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2163,7 +2163,7 @@ private void SetPreferenceVariables()
if (_commandRuntime.IsDebugFlagSet)
{
_localsTuple.SetPreferenceVariable(PreferenceVariable.Debug,
_commandRuntime.Debug ? ActionPreference.Inquire : ActionPreference.SilentlyContinue);
_commandRuntime.Debug ? ActionPreference.Continue : ActionPreference.SilentlyContinue);
}
if (_commandRuntime.IsVerboseFlagSet)
{
Expand Down
4 changes: 2 additions & 2 deletions test/powershell/Language/Scripting/ActionPreference.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ Describe "Tests for (error, warning, etc) action preference" -Tags "CI" {
}

It '<switch> does not take precedence over $ErrorActionPreference' -TestCases @(
@{switch="-Verbose"},
@{switch="-Debug"}
@{switch="Verbose"},
@{switch="Debug"}
) {
param($switch)
$ErrorActionPreference = "SilentlyContinue"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ Describe "Write-Debug tests" -Tags "CI" {
$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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Describe "Stream writer tests" -Tags "CI" {
[CmdletBinding()]

param()
If ($PSBoundParameters['Debug']) { $DebugPreference = 'Continue' }

Write-Verbose "Verbose message"

Write-Debug "Debug message"
Expand Down