Add better error message for empty and null -UFormat arg (#5055)

Add better error message for empty and null -UFormat arg
This commit is contained in:
David Weber 2017-10-09 23:19:02 -04:00 committed by Ilya
parent 68f318364c
commit aea561f08d
2 changed files with 9 additions and 1 deletions

View file

@ -199,6 +199,7 @@ namespace Microsoft.PowerShell.Commands
/// Unix format string
/// </summary>
[Parameter(ParameterSetName = "UFormat")]
[ValidateNotNullOrEmpty]
public string UFormat { get; set; }
@ -332,7 +333,6 @@ namespace Microsoft.PowerShell.Commands
int offset = 0;
StringBuilder sb = new StringBuilder();
// folks may include the "+" as part of the format string
if (UFormat[0] == '+')
{

View file

@ -37,6 +37,14 @@ Describe "Get-Date DRT Unit Tests" -Tags "CI" {
Get-date -Date 1/1/0030 -uformat %S%T%u%U%V%w%W%x%X%y%Y%% | Should be "0000:00:002012001/01/3000:00:00300030%"
}
It "Passing '<name>' to -uformat produces a descriptive error" -TestCases @(
@{ name = "`$null" ; value = $null }
@{ name = "empty string"; value = "" }
) {
param($value)
{ Get-date -Date 1/1/1970 -uformat $value -ErrorAction Stop } | ShouldBeErrorId "ParameterArgumentValidationError,Microsoft.PowerShell.Commands.GetDateCommand"
}
It "Get-date works with pipeline input" {
$x = new-object System.Management.Automation.PSObject
$x | add-member NoteProperty Date ([DateTime]::Now)