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
2 changes: 1 addition & 1 deletion PSWriteColor.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Description = 'Write-Color is a wrapper around Write-Host allowing you to create nice looking scripts, with colorized output. It provides easy manipulation of colors, logging output to file (log) and nice formatting options out of the box.'
FunctionsToExport = 'Write-Color'
GUID = '0b0ba5c5-ec85-4c2b-a718-874e55a8bc3f'
ModuleVersion = '1.0.6'
ModuleVersion = '1.0.7'
PowerShellVersion = '5.1'
PrivateData = @{
PSData = @{
Expand Down
2 changes: 1 addition & 1 deletion Public/Write-Color.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function Write-Color {
$TextToFile = $Text -join ''
# Handle Ignore at this boundary: Windows PowerShell 5.1 cannot pass an inherited
# Ignore preference through to nested Write-Host calls.
$SuppressConsole = $NoConsoleOutput -or $PSBoundParameters['InformationAction'] -eq [System.Management.Automation.ActionPreference]::Ignore
$SuppressConsole = $NoConsoleOutput -or $PSBoundParameters['InformationAction'] -eq [System.Management.Automation.ActionPreference]::Ignore -or $InformationPreference -eq [System.Management.Automation.ActionPreference]::Ignore
if (-not $NoConsoleOutput -and $OutputStream -ne 'Host') {
$Message = $TextToFile
if ($ShowTime) {
Expand Down
19 changes: 19 additions & 0 deletions Tests/Write-Color.Streams.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ BeforeAll {
}

Describe 'Write-Color message streams' {
It 'honors inherited information suppression for <Stream> without losing file logs' -ForEach @(
@{ Stream = 'Host' }, @{ Stream = 'Information' }
) {
$log = Join-Path $TestDrive "$Stream-inherited.log"
$records = @(& (Get-Module PSWriteColor) {
param($Stream, $LogPath)
function Invoke-NestedColor {
[CmdletBinding()]
param($Stream, $LogPath)
Write-Color 'one', 'two' -OutputStream $Stream -LogFile $LogPath -LogTime $false
}
Invoke-NestedColor -Stream $Stream -LogPath $LogPath -InformationAction Ignore *>&1
} $Stream $log)
$records.Count | Should -Be 0
Get-Content -LiteralPath $log | Should -BeExactly 'onetwo'
$after = @(Write-Color 'visible' -InformationAction Continue 6>&1)
($after.MessageData.Message -join '') | Should -Match 'visible'
}

It 'emits one plain success string without enabling diagnostic preferences' {
$records = @(Write-Color 'one', 'two' -OutputStream Output -Verbose:$false -InformationAction Ignore *>&1)
$records.Count | Should -Be 1
Expand Down
Loading