Skip to content

Conversation

@jeffbi
Copy link
Contributor

@jeffbi jeffbi commented Jul 25, 2017

Addresses part of #4148.

Using the -Name parameter on Get-ChildItem exercises a part of the file system provider code not previously covered by tests.


It "Verity Get-ChildItem can get the name of a specified item." {
$fileName = Get-ChildItem $testFile -Name
$fileName | Should BeExactly $fileName
Copy link
Contributor

Choose a reason for hiding this comment

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

This compares to itself.
I suggest calling Get-ChildItem twice, once with -Name to get the name string and once without to get the fileinfo. The test would look something like the following:
$filename | Should BeExactly $fileInfo.Name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yikes! Bad typo on my part. That should have been $filename | Should BeExactly $testFile. Is making that change sufficient, or would you prefer the dual-call method?

@dantraMSFT
Copy link
Contributor

You're better off comparing the returned value against the name property since, I believe, that's the intent.

@jeffbi
Copy link
Contributor Author

jeffbi commented Jul 25, 2017

Well, the intent was to check that I got the item I asked for, which is why I was comparing against $testFile. But I'll go ahead with your recommendation.

@dantraMSFT
Copy link
Contributor

Sorry jeffbi; I should have been clearer. When I said the intent of -Name, I mean the intent is to return the Name property of the FileInfo object.
The current implementation of FileInfo 'does' preserve the file name as it was passed in; however, since it's not documented explicitly, I avoid depending on it.
Additionally, I would expect the test to succeed with other values, such as .\filename.txt, ./filename.txt, and /etc/filename.txt
I hope that clarifies my feedback.

@adityapatwardhan adityapatwardhan merged commit 10a27b8 into PowerShell:master Aug 1, 2017
@jeffbi jeffbi deleted the tests-4148-gci branch August 1, 2017 20:27
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