Skip to content

Export-Csv Test Improvements - #5150

Merged
Ilya (iSazonov) merged 5 commits into
PowerShell:masterfrom
Marusyk:master
Oct 26, 2017
Merged

Ilya (iSazonov) merged 5 commits into
PowerShell:masterfrom
Marusyk:master

Conversation

@Marusyk

@Marusyk Roman Marusyk (Marusyk) commented Oct 17, 2017 •

Copy link
Copy Markdown
Contributor

Fix #5139

@@ -3,71 +3,69 @@ Describe "Export-Csv" -Tags "CI" {
$testCsv = Join-Path -Path $TestDrive -ChildPath "output.csv"

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Collaborator

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 Stop

Copy link
Copy Markdown
Contributor Author

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"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please use -ErrorAction Stop.

Copy link
Copy Markdown
Contributor Author

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"

Copy link
Copy Markdown
Collaborator

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" 

@Marusyk Roman Marusyk (Marusyk) Oct 18, 2017 •

Copy link
Copy Markdown
Contributor Author

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"

Copy link
Copy Markdown
Collaborator

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" 

@Marusyk Roman Marusyk (Marusyk) Oct 18, 2017 •

Copy link
Copy Markdown
Contributor Author

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
}

Copy link
Copy Markdown
Collaborator

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" {

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@iSazonov Ilya (iSazonov) self-assigned this Oct 18, 2017
}
}

It "Should have the same information when using the alias vs the cmdlet" {

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

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++) {

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Collaborator

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]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please correct indentation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@markekraus Mark Kraus (markekraus) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@iSazonov

Copy link
Copy Markdown
Collaborator

Roman Marusyk (@Marusyk) Please resolve merge conflicts.

@Marusyk

Copy link
Copy Markdown
Contributor Author

Ilya (@iSazonov) Done

@markekraus

Copy link
Copy Markdown
Contributor

appveyor build fail due to #5201

@markekraus

Copy link
Copy Markdown
Contributor

Roman Marusyk (@Marusyk) Right. that's what I said. the AppVeyor failure is due to the issue noted in #5201

@daxian-dbw

Copy link
Copy Markdown
Member

#5118 has been merged, and I restarted AppVeyor CI for this PR.

@markekraus Mark Kraus (markekraus) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@iSazonov

Copy link
Copy Markdown
Collaborator

Dongbo Wang (@daxian-dbw) Can we merge the PR?

@daxian-dbw

Copy link
Copy Markdown
Member

Ilya (@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 :)

@iSazonov
Ilya (iSazonov) merged commit 282deb7 into PowerShell:master Oct 26, 2017
@iSazonov

Copy link
Copy Markdown
Collaborator

Roman Marusyk (@Marusyk) Thanks for your contribution! Welcome back with new PRs.

@iSazonov Ilya (iSazonov) added the Hacktoberfest Potential candidate to participate in Hacktoberfest label Oct 26, 2017
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hacktoberfest Potential candidate to participate in Hacktoberfest

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants