Improve code coverage in Export-Csv.Tests.ps1.#6795
Improve code coverage in Export-Csv.Tests.ps1.#6795adityapatwardhan merged 6 commits intoPowerShell:masterfrom
Conversation
| BeforeAll { | ||
| $filePath = Join-Path $TestDrive -ChildPath "test.csv" | ||
| $newLine = [environment]::NewLine | ||
| It "Should be able to use -LiteralPath parameter" { |
There was a problem hiding this comment.
Should be able to use -> Should support
| $results = Import-Csv -Path $testCsv | ||
|
|
||
| $results.P2 | Should -BeExactly "second" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } |
There was a problem hiding this comment.
perhaps:
$property = $results.PSObject.Properties.Name| $results = Import-Csv -Path $testCsv | ||
|
|
||
| $results.P1 | Should -BeExactly "first" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } |
| $results = Import-Csv -Path $testCsv | ||
|
|
||
| $results.P1 | Should -BeExactly "first" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } |
| $results = Import-Csv -Path $testCsv | ||
|
|
||
| $results.P2 | Should -BeExactly "second" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } |
|
|
||
| $results.P1 | Should -BeExactly "first" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } | ||
| $property | Should -BeExactly P1 |
|
|
||
| $results.P2 | Should -BeExactly "second" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } | ||
| $property | Should -BeExactly P2 |
| $results[0].P1 | Should -BeExactly "first" | ||
| $results[1].P1 | Should -BeExactly "eleventh" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } | ||
| $property | Should -BeExactly P1 |
|
|
||
| $results[0].P1 | Should -BeExactly "eleventh" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } | ||
| $property | Should -BeExactly P1 |
|
|
||
| $results[0].P1 | Should -BeExactly "first" | ||
| $property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name } | ||
| $property | Should -BeExactly P1 |
|
Fixed. |
|
|
||
| $results.P2 | Should -BeExactly "second" | ||
| $property = $results.PSObject.Properties.Name | ||
| $property | Should -BeExactly "P2" |
There was a problem hiding this comment.
Seems it is a duplicate line 91 and should be removed- the line failed if we haven't "P2" property and we never reach line 93. Below too.
There was a problem hiding this comment.
Maybe better remove 92 and 93, since line 91 covers both property name and value?
| $property | Should -BeExactly "P1" | ||
| } | ||
|
|
||
| It "Should append to empty file if -Append parameter specified" { |
There was a problem hiding this comment.
I believe we should remove the tests - it repeats the previous test.
There was a problem hiding this comment.
There is a branch in code that this test covers.
There was a problem hiding this comment.
Please add the comment that it does not duplicate the previous test and checks another branch of the code.
|
|
||
| $contents.Count | Should -Be 2 | ||
| $contents[0].Contains($delimiter) | Should -BeTrue | ||
| $contents[1].Contains($delimiter) | Should -BeTrue |
There was a problem hiding this comment.
We could use Should -Contain
There was a problem hiding this comment.
No. If the delimiter is comma, Should treats input as array, so $contents[0] | Should -Contain $delimiter will fail.
There was a problem hiding this comment.
$contents[0] is a string not a language operator.
I think it is passed:
"," | Should -Contain ","
There was a problem hiding this comment.
It "Test export-csv with a useculture flag" {
$outputFilesDir = Join-Path -Path $TestDrive -ChildPath "Monad"
$fileToGenerate = Join-Path -Path $outputFilesDir -ChildPath "CSVTests.csv"
$delimiter = (Get-Culture).TextInfo.ListSeparator
New-Item -Path $outputFilesDir -ItemType Directory -Force
Get-Item -Path $outputFilesDir | Export-Csv -Path $fileToGenerate -UseCulture -NoTypeInformation
$contents = Get-Content -Path $fileToGenerate
$contents.Count | Should -Be 2
$contents[0] | Should -Contain $delimiter
}
[-] Test export-csv with a useculture flag 144ms
Expected ',' to be found in collection "PSPath","PSParentPath","PSChildName","PSDrive","PSProvider","PSIsContainer","Mode","BaseName","Target","LinkType","Name","Parent","Exists","Root","FullName","Extension","CreationTime","CreationTimeUtc","LastAccessTime","LastAccessTimeUtc","LastWriteTime","LastWriteTimeUtc","Attributes", but it was not found.
186: $contents[0] | Should -Contain $delimiter
There was a problem hiding this comment.
Thanks for the repo! This is my misconception. Closed.
|
|
||
| # This test is not a duplicate of previous one, since it covers a separate branch in code. | ||
| It "Should append to empty file if -Append parameter specified" { | ||
| New-Item -Path $testCsv -ItemType File |
|
@sethvs Thanks for your contribution! |
PR Summary
Improve code coverage in Export-Csv.Tests.ps1.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests