mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add -NoHeader parameter to ConvertTo-Csv and Export-Csv cmdlets (#19108)
This commit is contained in:
@@ -91,6 +91,11 @@ Describe "ConvertTo-Csv" -Tags "CI" {
|
||||
$result | Should -Not -Match ([regex]::Escape('#TYPE'))
|
||||
}
|
||||
|
||||
It "Does not include headers with -NoHeader" {
|
||||
$result = $testObject | ConvertTo-Csv -NoHeader
|
||||
$result | Should -BeExactly '"Hello","World"'
|
||||
}
|
||||
|
||||
It "Does not support -UseQuotes and -QuoteFields at the same time" {
|
||||
{ $testObject | ConvertTo-Csv -UseQuotes Always -QuoteFields "TestFieldName" } |
|
||||
Should -Throw -ErrorId "CannotSpecifyQuoteFieldsAndUseQuotes,Microsoft.PowerShell.Commands.ConvertToCsvCommand"
|
||||
|
||||
@@ -68,6 +68,21 @@ Describe "Export-Csv" -Tags "CI" {
|
||||
$results[0] | Should -Not -Match ([regex]::Escape("#TYPE"))
|
||||
}
|
||||
|
||||
It "Does not include headers with -NoHeader when exported and can imported with headers" {
|
||||
$P1 | Export-Csv -Path $testCsv -NoHeader
|
||||
$results = Get-Content -Path $testCsv
|
||||
$results | Should -BeExactly '"first"'
|
||||
$results = Import-Csv -Path $testCsv -Header "P1"
|
||||
$results[0].P1 | Should -BeExactly "first"
|
||||
}
|
||||
|
||||
It "Does not include headers when imported with headers and exported using -NoHeader" {
|
||||
$P1 | Export-Csv -Path $testCsv
|
||||
(Import-Csv -Path $testCsv) | Export-Csv -Path $testCsv -NoHeader
|
||||
$results = Get-Content -Path $testCsv
|
||||
$results | Should -BeExactly '"first"'
|
||||
}
|
||||
|
||||
It "Includes type information when -IncludeTypeInformation is supplied" {
|
||||
$testObject | Export-Csv -Path $testCsv -IncludeTypeInformation
|
||||
$results = Get-Content -Path $testCsv
|
||||
|
||||
Reference in New Issue
Block a user