mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
-Verbose should not override $ErrorActionPreference (#5113)
* -Verbose should not override $ErrorActionPreference * apply same fix to -debug and added test case * address Aditya's feedback
This commit is contained in:
1 parent
282deb7ee1
commit
b1af9ea230
2 files changed
+19
-7
No files matched your search
@@ -3212,13 +3212,6 @@ namespace System.Management.Automation
|
||||
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;
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user