Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public SwitchParameter Debug
/// This parameter tells the command what to do when an error occurs.
/// </remarks>
[Parameter]
[ValidateNotNull]
[Alias("ea")]
public ActionPreference ErrorAction
{
Expand All @@ -94,6 +95,7 @@ public ActionPreference ErrorAction
/// occurs.
/// </remarks>
[Parameter]
[ValidateNotNull]
[Alias("wa")]
public ActionPreference WarningAction
{
Expand All @@ -115,6 +117,7 @@ public ActionPreference WarningAction
/// was added to PowerShell, so "infa" was chosen instead.
/// -->
[Parameter]
[ValidateNotNull]
[Alias("infa")]
public ActionPreference InformationAction
{
Expand Down
7 changes: 7 additions & 0 deletions test/powershell/Language/Scripting/ActionPreference.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ Describe "Tests for (error, warning, etc) action preference" -Tags "CI" {
{ New-Item @params } | Should -Throw -ErrorId "NewItemIOError,Microsoft.PowerShell.Commands.NewItemCommand"
Remove-Item "$testdrive\test.txt" -Force
}

It "Parameter binding throws correctly (no NRE) if argument is null" {
$NullVariable = $null
{ Test-Path .\noexistfile.ps1 -ErrorAction $NullVariable } | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestPathCommand"
{ Test-Path .\noexistfile.ps1 -InformationAction $NullVariable } | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestPathCommand"
{ Test-Path .\noexistfile.ps1 -WarningAction $NullVariable } | Should -Throw -ErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.TestPathCommand"
}
}

Describe 'ActionPreference.Break tests' -tag 'CI' {
Expand Down