Revert "Update formatter to not write newlines if content is empty (#11193)" (#11342)

This reverts commit 51d2523f5f.
This commit is contained in:
Ilya
2019-12-18 00:53:19 +05:00
committed by GitHub
parent e78cb8302d
commit dfb5b047b1
3 changed files with 8 additions and 82 deletions
@@ -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
}
}