-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Export-Csv Test Improvements #5150
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
Conversation
| @@ -1,73 +1,71 @@ | |||
| Describe "Export-Csv" -Tags "CI" { | |||
| $testObject = @("test","object","array") | |||
| $testCsv = Join-Path -Path $TestDrive -ChildPath "output.csv" | |||
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.
Please put the two lines in BeforeAll block.
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.
Done
|
|
||
| It "Should be able to be called without error" { | ||
| { $testObject | Export-Csv $testCsv } | Should Not Throw | ||
| { $testObject | Export-Csv $testCsv } | Should Not Throw |
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.
Please add -ErrorAction Stop.
Export-Csv $testCsv -ErrorAction StopThere 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.
Done
|
|
||
| It "Should throw if an output file isn't specified" { | ||
| { $testObject | Export-Csv -ErrorAction SilentlyContinue } | Should Throw | ||
| { $testObject | Export-Csv -ErrorAction SilentlyContinue } | ShouldBeErrorId "CannotSpecifyPathAndLiteralPath,Microsoft.PowerShell.Commands.ExportCsvCommand" |
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.
Please use -ErrorAction Stop.
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.
Done
| $piped = Get-Content $testCsv | ||
|
|
||
| $piped[0] | Should Match ".String" | ||
| $piped[0] | Should be "#TYPE System.String" |
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.
Please use:
$piped[0] | Should BeExactly "#TYPE System.String" 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.
Done.
| $switch = Get-Content $testCsv | ||
|
|
||
| $switch[0] | Should Match ".Object" | ||
| $switch[0] | Should Match ".Object" |
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.
Please use something like:
$piped[0] | Should BeExactly "#TYPE System.Object" 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.
Done. But "#TYPE System.Object[]"
| It "Should be able to use the epcsv alias without error" { | ||
| { $testObject | Export-Csv -Path $testCsv } | Should Not Throw | ||
| { $testObject | epcsv -Path $testCsv } | Should Not Throw | ||
| } |
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.
Please remove the test at all - we have another file for alias tests.
| { $testObject | epcsv -Path $testCsv } | Should Not Throw | ||
| } | ||
|
|
||
| It "Should have the same information when using the alias vs the cmdlet" { |
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.
Please remove the test at all - we have another file for alias tests.
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.
Done
| } | ||
| } | ||
|
|
||
| It "Should have the same information when using the alias vs the cmdlet" { |
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.
Please remove the alias test.
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.
Done
|
|
||
| It "Should be able to use the epcsv alias without error" { | ||
| { $testObject | Export-Csv -Path $testCsv } | Should Not Throw | ||
| for ( $i = 0; $i -lt $testCsv.Length; $i++) { |
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.
I wonder why we use $testCsv.Length?
I'd expect $expected.Count.
Your thoughts?
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.
I agree and think it should be $expected.Count. I have no clue how the length of the temporary file path string is relevant to anything in this test.
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.
Is there even a need for looping logic here? would calling get-content once and perform 4 explicit tests be better? It seems like creating an array and looping through it (with a for loop no less) is just overkill.
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.
I think we should stop on $expected.Count
| # Clean up after yourself | ||
| Remove-Item $aliasObject -Force | ||
| for ( $i = 0; $i -lt $expected.Count; $i++) { | ||
| $(Get-Content $testCsv)[$i] | Should Be $expected[$i] |
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.
Please correct indentation.
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.
Done
markekraus
left a 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.
LGTM
|
@Marusyk Please resolve merge conflicts. |
|
@iSazonov Done |
|
appveyor build fail due to #5201 |
|
#5118 has been merged, and I restarted AppVeyor CI for this PR. |
markekraus
left a 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.
LGTM
|
@daxian-dbw Can we merge the PR? |
|
@iSazonov Sorry that I didn't get a chance to review this change (too many notifications since having the code owner filter ...). Please proceed as you see appropriate :) |
|
@Marusyk Thanks for your contribution! Welcome back with new PRs. |
Fix #5139