8000 -Verbose should not override $ErrorActionPreference by SteveL-MSFT · Pull Request #5113 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content
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
7 changes: 0 additions & 7 deletions src/System.Management.Automation/engine/MshCommandRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3212,13 +3212,6 @@ internal ActionPreference ErrorAction
if (IsErrorActionSet)
return _errorAction;

// Debug takes preference over Verbose
if (Debug)
return ActionPreference.Inquire;
if (Verbose)
return ActionPreference.Continue;

// fall back to $ErrorAction
if (!_isErrorActionPreferenceCached)
{
bool defaultUsed = false;
Expand Down
19 changes: 19 additions & 0 deletions test/powershell/Language/Scripting/ActionPreference.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,23 @@
}
$num | Should Be 2
}

It '<switch> does not take precedence over $ErrorActionPreference' -TestCases @(
@{switch="-Verbose"},
@{switch="-Debug"}
) {
param($switch)
$ErrorActionPreference = "SilentlyContinue"
$params = @{
ItemType = "File";
Path = "$testdrive\test.txt";
Confirm = $false
}
New-Item @params > $null
$params += @{$switch=$true}
{ New-Item @params } | Should Not Throw
$ErrorActionPreference = "Stop"
{ New-Item @params } | ShouldBeErrorId "NewItemIOError,Microsoft.PowerShell.Commands.NewItemCommand"
Remove-Item "$testdrive\test.txt" -Force
}
}
0