mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
This reverts commit 51d2523f5f.
This commit is contained in:
@@ -49,24 +49,14 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
||||
// we always start with no indentation
|
||||
_indentationManager.Clear();
|
||||
|
||||
bool hasContent = false;
|
||||
foreach (FormatEntry fe in formatValueList)
|
||||
{
|
||||
if (fe.formatValueList.Count > 0)
|
||||
{
|
||||
hasContent = true;
|
||||
|
||||
// operate on each directive inside the list,
|
||||
// carrying the indentation from invocation to invocation
|
||||
GenerateFormatEntryDisplay(fe, 0);
|
||||
}
|
||||
// operate on each directive inside the list,
|
||||
// carrying the indentation from invocation to invocation
|
||||
GenerateFormatEntryDisplay(fe, 0);
|
||||
}
|
||||
|
||||
// make sure that, if we have pending text in the buffer it gets flushed
|
||||
if (hasContent)
|
||||
{
|
||||
WriteToScreen();
|
||||
}
|
||||
WriteToScreen();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
+4
-2
@@ -281,10 +281,11 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
||||
// do the formatting and we will be done
|
||||
if (cpt.control == null || cpt.control is FieldControlBody)
|
||||
{
|
||||
// Since it is a leaf node we just consider it an empty string and go
|
||||
// on with formatting
|
||||
if (val == null)
|
||||
{
|
||||
// Since it is a leaf node we just ignore it
|
||||
return;
|
||||
val = string.Empty;
|
||||
}
|
||||
|
||||
FieldFormattingDirective fieldFormattingDirective = null;
|
||||
@@ -779,3 +780,4 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
|
||||
private int _enumerationLimit;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -438,69 +438,3 @@ SelectScriptBlock
|
||||
$ps.Streams.Error | Should -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Describe "Custom formatting returning nothing" -Tags "CI" {
|
||||
BeforeAll {
|
||||
$formatFilePath = Join-Path $TestDrive 'UpdateFormatDataTests.format.ps1xml'
|
||||
$xmlContent = @'
|
||||
<Configuration>
|
||||
<ViewDefinitions>
|
||||
<View>
|
||||
<Name>Test</Name>
|
||||
<ViewSelectedBy>
|
||||
<TypeName>MyTestObject</TypeName>
|
||||
</ViewSelectedBy>
|
||||
<CustomControl>
|
||||
<CustomEntries>
|
||||
<CustomEntry>
|
||||
<CustomItem>
|
||||
<ExpressionBinding>
|
||||
<ScriptBlock>
|
||||
$null
|
||||
</ScriptBlock>
|
||||
</ExpressionBinding>
|
||||
</CustomItem>
|
||||
</CustomEntry>
|
||||
</CustomEntries>
|
||||
</CustomControl>
|
||||
</View>
|
||||
</ViewDefinitions>
|
||||
</Configuration>
|
||||
'@
|
||||
|
||||
Set-Content -Path $formatFilePath -Value $xmlContent
|
||||
$ps = [powershell]::Create()
|
||||
$iss = [initialsessionstate]::CreateDefault2()
|
||||
$iss.Formats.Add($formatFilePath)
|
||||
$rs = [runspacefactory]::CreateRunspace($iss)
|
||||
$rs.Open()
|
||||
$ps.Runspace = $rs
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
$rs.Dispose()
|
||||
$ps.Dispose()
|
||||
}
|
||||
|
||||
It 'Newlines are not written if nothing is returned by custom format' {
|
||||
$script = {
|
||||
[PSCustomObject]@{
|
||||
PSTypeName = 'MyTestObject'
|
||||
Name = 'testing'
|
||||
}
|
||||
}
|
||||
|
||||
$null = $ps.AddScript($script).AddCommand('Out-String')
|
||||
$ps.Streams.Error.Clear()
|
||||
|
||||
# one newline for start, one for grouping, and one for end
|
||||
$expectedOutput = @'
|
||||
|
||||
|
||||
|
||||
'@ -replace '\r?\n', "^"
|
||||
|
||||
$ps.Invoke() -replace '\r?\n', "^" | Should -BeExactly $expectedOutput
|
||||
$ps.Streams.Error | Should -BeNullOrEmpty
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user