Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improve code coverage in Export-Csv.Tests.ps1.#6795

Merged
adityapatwardhan merged 6 commits intoPowerShell:masterfrom
sethvs:ExportCsvTests
May 4, 2018
Merged

Improve code coverage in Export-Csv.Tests.ps1.#6795
adityapatwardhan merged 6 commits intoPowerShell:masterfrom
sethvs:ExportCsvTests

Conversation

@sethvs
Copy link
Contributor

@sethvs sethvs commented May 2, 2018

PR Summary

Improve code coverage in Export-Csv.Tests.ps1.

PR Checklist

BeforeAll {
$filePath = Join-Path $TestDrive -ChildPath "test.csv"
$newLine = [environment]::NewLine
It "Should be able to use -LiteralPath parameter" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

$results = Import-Csv -Path $testCsv

$results.P1 | Should -BeExactly "first"
$property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

$results = Import-Csv -Path $testCsv

$results.P2 | Should -BeExactly "second"
$property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above


$results.P1 | Should -BeExactly "first"
$property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name }
$property | Should -BeExactly P1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 should be quoted


$results.P2 | Should -BeExactly "second"
$property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name }
$property | Should -BeExactly P2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 should be quoted

$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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 should be quoted


$results[0].P1 | Should -BeExactly "eleventh"
$property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name }
$property | Should -BeExactly P1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 should be quoted


$results[0].P1 | Should -BeExactly "first"
$property = $results | Get-Member | Where-Object { $_.MemberType -eq "NoteProperty" } | ForEach-Object { $_.Name }
$property | Should -BeExactly P1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 should be quoted

@sethvs
Copy link
Contributor Author

sethvs commented May 2, 2018

Fixed.


$results.P2 | Should -BeExactly "second"
$property = $results.PSObject.Properties.Name
$property | Should -BeExactly "P2"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe better remove 92 and 93, since line 91 covers both property name and value?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

$property | Should -BeExactly "P1"
}

It "Should append to empty file if -Append parameter specified" {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should remove the tests - it repeats the previous test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a branch in code that this test covers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the comment that it does not duplicate the previous test and checks another branch of the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closed.


$contents.Count | Should -Be 2
$contents[0].Contains($delimiter) | Should -BeTrue
$contents[1].Contains($delimiter) | Should -BeTrue
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use Should -Contain

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. If the delimiter is comma, Should treats input as array, so $contents[0] | Should -Contain $delimiter will fail.

Copy link
Collaborator

@iSazonov iSazonov May 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$contents[0] is a string not a language operator.
I think it is passed:
"," | Should -Contain ","

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New-Item … > $null

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@sethvs sethvs changed the title Improve code coverage in Export-Csv.Tests.ps1. WIP: Improve code coverage in Export-Csv.Tests.ps1. May 3, 2018
@sethvs sethvs changed the title WIP: Improve code coverage in Export-Csv.Tests.ps1. Improve code coverage in Export-Csv.Tests.ps1. May 3, 2018
@adityapatwardhan adityapatwardhan merged commit 1be0594 into PowerShell:master May 4, 2018
@adityapatwardhan
Copy link
Member

@sethvs Thanks for your contribution!

@sethvs sethvs deleted the ExportCsvTests branch May 21, 2018 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants