-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Make -NoTypeInformation Default on Export-Csv and ConvertTo-Csv #5164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2d5e6f7
6a5c134
afbcd45
1fec825
81e4e7f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ Describe "ConvertTo-Csv DRT Unit Tests" -Tags "CI" { | |
| $inputObject = [pscustomobject]@{ First = 1; Second = 2 } | ||
|
|
||
| It "Test convertto-csv with psobject pipelined" { | ||
| $returnObject = $inputObject | ConvertTo-Csv | ||
| $returnObject = $inputObject | ConvertTo-Csv -IncludeTypeInformation | ||
| $returnObject.Count | Should Be 3 | ||
| $returnObject[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject" | ||
| $returnObject[1] | Should Be "`"First`",`"Second`"" | ||
|
|
@@ -18,7 +18,7 @@ Describe "ConvertTo-Csv DRT Unit Tests" -Tags "CI" { | |
|
|
||
| It "Test convertto-csv with a useculture flag" { | ||
| #The default value is ',' | ||
| $returnObject = $inputObject | ConvertTo-Csv -UseCulture | ||
| $returnObject = $inputObject | ConvertTo-Csv -UseCulture -IncludeTypeInformation | ||
| $returnObject.Count | Should Be 3 | ||
| $returnObject[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject" | ||
| $returnObject[1] | Should Be "`"First`",`"Second`"" | ||
|
|
@@ -27,7 +27,7 @@ Describe "ConvertTo-Csv DRT Unit Tests" -Tags "CI" { | |
|
|
||
| It "Test convertto-csv with Delimiter" { | ||
| #The default value is ',' | ||
| $returnObject = $inputObject | ConvertTo-Csv -Delimiter ";" | ||
| $returnObject = $inputObject | ConvertTo-Csv -Delimiter ";" -IncludeTypeInformation | ||
| $returnObject.Count | Should Be 3 | ||
| $returnObject[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject" | ||
| $returnObject[1] | Should Be "`"First`";`"Second`"" | ||
|
|
@@ -50,22 +50,47 @@ Describe "ConvertTo-Csv" -Tags "CI" { | |
| } | ||
|
|
||
| It "Should return the type of data in the first element of the output array" { | ||
| $result = $testObject | ConvertTo-Csv | ||
| $result = $testObject | ConvertTo-Csv -IncludeTypeInformation | ||
|
|
||
| $result[0] | Should Be "#TYPE System.Management.Automation.PSCustomObject" | ||
| } | ||
|
|
||
| It "Should return the column info in the second element of the output array" { | ||
| $result = $testObject | ConvertTo-Csv | ||
| $result = $testObject | ConvertTo-Csv -IncludeTypeInformation | ||
|
|
||
| $result[1] | Should Match "`"FirstColumn`"" | ||
| $result[1] | Should Match "`"SecondColumn`"" | ||
| } | ||
|
|
||
| It "Should return the data as a comma-separated list in the third element of the output array" { | ||
| $result = $testObject | ConvertTo-Csv | ||
| $result = $testObject | ConvertTo-Csv -IncludeTypeInformation | ||
| $result[2] | Should Match "`"Hello`"" | ||
| $result[2] | Should Match "`"World`"" | ||
| } | ||
|
|
||
| It "Includes type information when -IncludeTypeInformation is supplied" { | ||
| $result = $testObject | ConvertTo-Csv -IncludeTypeInformation | ||
|
|
||
| ($result -split ([Environment]::NewLine))[0] | Should BeExactly "#TYPE System.Management.Automation.PSCustomObject" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we need add reverse test to check that ""#TYPE " is absent if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure I'll add those and do the same for the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed |
||
| } | ||
|
|
||
| It "Does not include type information by default" { | ||
| $result = $testObject | ConvertTo-Csv | ||
|
|
||
| $result | Should Not Match ([regex]::Escape('System.Management.Automation.PSCustomObject')) | ||
| $result | Should Not Match ([regex]::Escape('#TYPE')) | ||
| } | ||
|
|
||
| It "Does not include type information with -NoTypeInformation" { | ||
| $result = $testObject | ConvertTo-Csv -NoTypeInformation | ||
|
|
||
| $result | Should Not Match ([regex]::Escape('System.Management.Automation.PSCustomObject')) | ||
| $result | Should Not Match ([regex]::Escape('#TYPE')) | ||
| } | ||
|
|
||
| It "Does not support -IncludeTypeInformation and -NoTypeInformation at the same time" { | ||
| { $testObject | ConvertTo-Csv -IncludeTypeInformation -NoTypeInformation } | | ||
| ShouldBeErrorId "CannotSpecifyIncludeTypeInformationAndNoTypeInformation,Microsoft.PowerShell.Commands.ConvertToCsvCommand" | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove the test - it is dup test in line 28.
Or it is better move the checks and next test to the test in line 28 - there we can check a type, a header and data.
It is minor comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iSazonov Which test do you want to remove? the one you comment is on (lin 58) is not a duplicate of any of the tests. Line 28 is a delimiter test which needs to remain as its a different logic gate (parameter set).
the test on line 52 is now redundant with the the test on line 84, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we could try to refactor the tests but not in the PR.
So skip the minor comment.