mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Add migrated files
This commit is contained in:
1 parent
721ad34c62
commit
7305b82b73
22 files changed
+4658
No files matched your search
@@ -0,0 +1,64 @@
|
||||
Describe "FormatData" -tags "P1", "RI" {
|
||||
|
||||
Context "Export" {
|
||||
It "can export all types" {
|
||||
try
|
||||
{
|
||||
$expectAllFormat = Get-FormatData -typename *
|
||||
$expectAllFormat | Export-FormatData -path $env:temp\allformat.ps1xml -IncludeScriptBlock
|
||||
|
||||
$sessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault()
|
||||
$sessionState.Formats.Clear()
|
||||
$sessionState.Types.Clear()
|
||||
|
||||
$runspace = [System.Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace($sessionState)
|
||||
$runspace.Open()
|
||||
|
||||
$runspace.CreatePipeline("Update-FormatData -AppendPath $env:temp\allformat.ps1xml").Invoke()
|
||||
$actualAllFormat = $runspace.CreatePipeline("Get-FormatData -TypeName *").Invoke()
|
||||
|
||||
$expectAllFormat.Count | Should Be $actualAllFormat.Count
|
||||
Compare-Object $expectAllFormat $actualAllFormat | Should Be $null
|
||||
$runspace.Close()
|
||||
}
|
||||
finally
|
||||
{
|
||||
Remove-Item -Path $env:temp\allformat.ps1xml -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
It "works with literal path" {
|
||||
$filename = 'TestDrive:\[formats.ps1xml'
|
||||
Get-FormatData -TypeName * | Export-FormatData -LiteralPath $filename
|
||||
(Test-Path -LiteralPath $filename) | Should Be $true
|
||||
}
|
||||
|
||||
It "should overwrite the destination file" {
|
||||
$filename = 'TestDrive:\ExportFormatDataWithForce.ps1xml'
|
||||
$unexpected = "SHOULD BE OVERWRITTEN"
|
||||
$unexpected | Out-File -FilePath $filename -Force
|
||||
$file = Get-Item $filename
|
||||
$file.IsReadOnly = $true
|
||||
Get-FormatData -TypeName * | Export-FormatData -Path $filename -Force
|
||||
|
||||
$actual = @(Get-Content $filename)[0]
|
||||
$actual | Should Not Be $unexpected
|
||||
}
|
||||
|
||||
It "should not overwrite the destination file with NoClobber" {
|
||||
$filename = "TestDrive:\ExportFormatDataWithNoClobber.ps1xml"
|
||||
Get-FormatData -TypeName * | Export-FormatData -LiteralPath $filename
|
||||
|
||||
try
|
||||
{
|
||||
Get-FormatData -TypeName * | Export-FormatData -LiteralPath $filename -NoClobber
|
||||
}
|
||||
catch
|
||||
{
|
||||
$exportFormatError = $_
|
||||
}
|
||||
|
||||
$exportFormatError.FullyQualifiedErrorId | Should Be 'NoClobber,Microsoft.PowerShell.Commands.ExportFormatDataCommand'
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user