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
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,7 @@ protected override void ProcessRecord()
}
}

var originalFormats = Context.InitialSessionState.Formats;
try
{
// Always rebuild the format information
Expand Down Expand Up @@ -984,6 +985,9 @@ protected override void ProcessRecord()
}
catch (RuntimeException e)
{
// revert Formats if there is a failure
Context.InitialSessionState.Formats.Clear();
Context.InitialSessionState.Formats.Add(originalFormats);
this.WriteError(new ErrorRecord(e, "FormatXmlUpdateException", ErrorCategory.InvalidOperation, null));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private void LoadData(XmlDocument doc, TypeInfoDataBase db)
bool viewDefinitionsFound = false;
bool controlDefinitionsFound = false;

if (MatchNodeName(documentElement, XmlTags.ConfigurationNode))
if (MatchNodeNameWithAttributes(documentElement, XmlTags.ConfigurationNode))
{
// load the various sections
using (this.StackFrame(documentElement))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ Describe "Format-Table" -Tags "CI" {
</Configuration>
"@

$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "test.format.ps1xml"
$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "alignment.format.ps1xml"
Set-Content -Path $ps1xmlPath -Value $ps1xml
# run in own runspace so not affect global sessionstate
$ps = [powershell]::Create()
Expand Down Expand Up @@ -315,7 +315,7 @@ Left Center Right
</Configuration>
"@

$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "test.format.ps1xml"
$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "truncation.format.ps1xml"
Set-Content -Path $ps1xmlPath -Value $ps1xml
# run in own runspace so not affect global sessionstate
$ps = [powershell]::Create()
Expand Down Expand Up @@ -456,7 +456,7 @@ er
</Configuration>
"@
$ps1xml = $ps1xml.Replace("{0}", $widths[0]).Replace("{1}", $widths[1]).Replace("{2}", $widths[2])
$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "test.format.ps1xml"
$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "span.format.ps1xml"
Set-Content -Path $ps1xmlPath -Value $ps1xml
# run in own runspace so not affect global sessionstate
$ps = [powershell]::Create()
Expand Down Expand Up @@ -662,7 +662,7 @@ er
</Configuration>
"@
$ps1xml = $ps1xml.Replace("{0}", $widths[0]).Replace("{1}", $widths[1]).Replace("{2}", $widths[2])
$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "test.format.ps1xml"
$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "render.format.ps1xml"
Set-Content -Path $ps1xmlPath -Value $ps1xml
# run in own runspace so not affect global sessionstate
$ps = [powershell]::Create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,60 @@
# Licensed under the MIT License.
Describe "Update-FormatData" -Tags "CI" {

BeforeAll {
$path = Join-Path -Path $TestDrive -ChildPath "outputfile.ps1xml"
$ps = [powershell]::Create()
$iss = [system.management.automation.runspaces.initialsessionstate]::CreateDefault2()
$rs = [system.management.automation.runspaces.runspacefactory]::CreateRunspace($iss)
$rs.Open()
$ps.Runspace = $rs
}
AfterAll {
$rs.Close()
$ps.Dispose()
BeforeEach {
$ps = [PowerShell]::Create()
}

Context "Validate Update-FormatData update correctly" {

It "Should not throw upon reloading previous formatting file" {
{ Update-FormatData } | Should -Not -throw
}

It "Should validly load formatting data" {
$path = Join-Path -Path $TestDrive -ChildPath "outputfile.ps1xml"
Get-FormatData -typename System.Diagnostics.Process | Export-FormatData -Path $path
$null = $ps.AddScript("Update-FormatData -prependPath $path")
$ps.Invoke()
$ps.HadErrors | Should -BeFalse
}

It "Update with atributes on Configuration node should be ignored" {
$xmlContent = @"
<Configuration xmlns:foo="bar">
<ViewDefinitions>
<View>
<Name>Test</Name>
<ViewSelectedBy>
<TypeName>Test</TypeName>
</ViewSelectedBy>
<ListControl>
<ListEntries>
<ListEntry>
<ListItems>
<ListItem>
<PropertyName>Test</PropertyName>
</ListItem>
</ListItems>
</ListEntry>
</ListEntries>
</ListControl>
</View>
</ViewDefinitions>
</Configuration>
"@
$path = "$testdrive\rootattribute.format.ps1xml"
Set-Content -Path $path -Value $xmlContent
$null = $ps.AddScript("Update-FormatData -prependPath $path")
$ps.Invoke()
$ps.HadErrors | Should -BeFalse
$ps.Commands.Clear()
$null = $ps.AddScript("Get-FormatData test")
$formatData = $ps.Invoke()
$formatData | Should -HaveCount 1
$formatData.TypeNames | Should -BeExactly "Test"
$formatData.FormatViewDefinition.Name | Should -BeExactly "Test"
}
}
}

Expand Down Expand Up @@ -59,7 +89,7 @@ Describe "Update-FormatData basic functionality" -Tags "CI" {
{ Update-FormatData -Prepend $testfile -WhatIf } | Should -Not -Throw
}

It "Update with invalid format xml should fail" -Pending {
It "Update with invalid format xml should fail" {
$xmlContent = @"
<Configuration>
<ViewDefinitions>
Expand All @@ -69,8 +99,8 @@ Describe "Update-FormatData basic functionality" -Tags "CI" {
</ViewDefinitions>
</Configuration>
"@
$xmlContent | Out-File -FilePath "$testdrive\test.format.ps1xml" -Encoding ascii
{ Update-FormatData -Path "$testdrive\test.format.ps1xml" -ErrorAction Stop } | Should -Throw -ErrorId "FormatXmlUpdateException,Microsoft.PowerShell.Commands.UpdateFormatDataCommand"
$xmlContent | Out-File -FilePath "$testdrive\invalid.format.ps1xml" -Encoding ascii
{ Update-FormatData -Path "$testdrive\invalid.format.ps1xml" -ErrorAction Stop } | Should -Throw -ErrorId "FormatXmlUpdateException,Microsoft.PowerShell.Commands.UpdateFormatDataCommand"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,33 @@ Describe "Update-TypeData basic functionality" -Tags "CI" {
$ps.Dispose()
}

It "Update-TypeData with Invalid TypesXml should throw Exception" {
It "Update-TypeData with attributes on root node should succeed" {
$xmlContent = @"
<Types xmlns:foo="bar">
<Type>
<Name>Test</Name>
<Members>
<AliasProperty>
<Name>Yada</Name>
<ReferencedMemberName>Length</ReferencedMemberName>
</AliasProperty>
</Members>
</Type>
</Types>
"@
$path = "$testdrive\test.types.ps1xml"
Set-Content -Value $xmlContent -Path $path
$null = $ps.AddScript("Update-TypeData -AppendPath $path")
$ps.Invoke()
$ps.HadErrors | Should -BeFalse
$ps.Commands.Clear()
$null = $ps.AddScript("Get-TypeData test")
$typeData = $ps.Invoke()
$typeData | Should -HaveCount 1
$typeData.TypeName | Should -BeExactly "Test"
}

It "Update-TypeData with Invalid TypesXml should throw Exception" {
$null = $ps.AddScript("Update-TypeData -PrependPath $testfile")
$ps.Invoke()
$ps.HadErrors | Should -BeTrue
Expand Down