Add common aliases for all write-* commands default message parameter (#5816)

* add common write aliases

* add Message alias to the MessageData parameter for Write-Information
add  Msg and Message alias to the Object perameter for Write-Host

* Add tests for new aliases
This commit is contained in:
Kevin Marquette
2018-02-22 11:07:51 -08:00
committed by Aditya Patwardhan
parent acf0dcdc6d
commit 93a5fed375
4 changed files with 25 additions and 4 deletions
@@ -28,6 +28,7 @@ namespace Microsoft.PowerShell.Commands
/// </summary>
[Parameter(Position = 0, ValueFromRemainingArguments = true, ValueFromPipeline = true)]
[Alias("Msg", "Message")]
public object Object { get; set; } = null;
/// <summary>
@@ -141,4 +142,4 @@ namespace Microsoft.PowerShell.Commands
private Boolean _notAppendNewline = false;
}
} // namespace Microsoft.PowerShell.Commands
} // namespace Microsoft.PowerShell.Commands
@@ -168,7 +168,7 @@ namespace Microsoft.PowerShell.Commands
/// Object to be sent to the Information stream.
/// </summary>
[Parameter(Position = 0, Mandatory = true, ValueFromPipeline = true)]
[Alias("Msg")]
[Alias("Msg", "Message")]
public Object MessageData { get; set; }
/// <summary>
@@ -59,6 +59,8 @@ Describe "Write-Host with TestHostCS" -Tags "CI" {
$testHostCSData = @(
@{ Name = 'defaults'; Command = "Write-Host a,b,c"; returnCount = 1; returnValue = @("White:Black:a b c:NewLine"); returnInfo = @("a b c") }
@{ Name = '-Object'; Command = "Write-Host -Object a,b,c"; returnCount = 1; returnValue = @("White:Black:a b c:NewLine"); returnInfo = @("a b c") }
@{ Name = '-Message'; Command = "Write-Host -Message a,b,c"; returnCount = 1; returnValue = @("White:Black:a b c:NewLine"); returnInfo = @("a b c") }
@{ Name = '-Msg'; Command = "Write-Host -Msg a,b,c"; returnCount = 1; returnValue = @("White:Black:a b c:NewLine"); returnInfo = @("a b c") }
@{ Name = '-Separator'; Command = "Write-Host a,b,c -Separator '+'"; returnCount = 1; returnValue = @("White:Black:a+b+c:NewLine"); returnInfo = @("a+b+c") }
@{ Name = '-Separator, colors and -NoNewLine'; Command = "Write-Host a,b,c -Separator ',' -ForegroundColor Yellow -BackgroundColor DarkBlue -NoNewline"; returnCount = 1; returnValue = @("Yellow:DarkBlue:a,b,c:NoNewLine"); returnInfo = @("a,b,c") }
@{ Name = '-NoNewline:$true and colors'; Command = "Write-Host a,b -NoNewline:`$true -ForegroundColor Red -BackgroundColor Green;Write-Host a,b"; returnCount = 2; returnValue = @("Red:Green:a b:NoNewLine", "White:Black:a b:NewLine"); returnInfo = @("a b", "a b") }
@@ -85,11 +87,11 @@ Describe "Write-Host with TestHostCS" -Tags "CI" {
$result = $th.ui.Streams.ConsoleOutput
$result.Count | Should Be $returnCount
(Compare-Object $result $returnValue -SyncWindow 0).length -eq 0 | Should Be $true
(Compare-Object $result $returnValue -SyncWindow 0).length | Should Be 0
$result = $th.ui.Streams.Information
$result.Count | Should Be $returnCount
(Compare-Object $result $returnInfo -SyncWindow 0).length -eq 0 | Should Be $true
(Compare-Object $result $returnInfo -SyncWindow 0).length | Should Be 0
}
}
@@ -57,6 +57,14 @@ Describe "Stream writer tests" -Tags "CI" {
Context "Write-Information cmdlet" {
BeforeAll {
$ps = [powershell]::Create()
$testInfoData = @(
@{ Name = 'defaults'; Command = "Write-Information TestMessage"; returnCount = 1; returnValue = 'TestMessage' }
@{ Name = '-Object'; Command = "Write-Information -MessageData TestMessage"; returnCount = 1; returnValue = 'TestMessage' }
@{ Name = '-Message'; Command = "Write-Information -Message TestMessage"; returnCount = 1; returnValue = 'TestMessage' }
@{ Name = '-Msg'; Command = "Write-Information -Msg TestMessage"; returnCount = 1; returnValue = 'TestMessage' }
@{ Name = '-Tag'; Command = "Write-Information TestMessage -Tag Test"; returnCount = 1; returnValue = 'TestMessage' }
)
}
BeforeEach {
@@ -96,5 +104,15 @@ Describe "Stream writer tests" -Tags "CI" {
$result[0].MessageData | Should be "teststring"
$result[1].MessageData | Should be "12345"
}
It "Write-Information works with <Name>" -TestCases:$testInfoData {
param($Command, $returnCount, $returnValue)
$ps.AddScript($Command).Invoke()
$result = $ps.Streams.Information
$result.Count | Should Be $returnCount
(Compare-Object $result $returnValue -SyncWindow 0).length | Should Be 0
}
}
}