Skip to content

Make Measure-Object property test independent of the filesystem - #15879

Merged
Rob Holt (rjmholt) merged 3 commits into
PowerShell:masterfrom
rjmholt:fix-measureobject-test
Aug 9, 2021
Merged

Rob Holt (rjmholt) merged 3 commits into
PowerShell:masterfrom
rjmholt:fix-measureobject-test

Conversation

@rjmholt

Copy link
Copy Markdown
Collaborator

PR Summary

Fixes a recent CI failure where the expected and actual results of this test disagree because there's a directory in the $TestDrive.

PR Context

PR Checklist

@rjmholt Rob Holt (rjmholt) added the CL-Test Indicates that a PR should be marked as a test change in the Change Log label Aug 5, 2021
@rjmholt
Rob Holt (rjmholt) enabled auto-merge (squash) August 5, 2021 17:39
@SteveL-MSFT

Copy link
Copy Markdown
Member

Is this a race condition between getting the count of objects and than using measure-object? I'm not able to repro this with even an empty sub-folder?

@iSazonov

Ilya (iSazonov) commented Aug 7, 2021 •

Copy link
Copy Markdown
Collaborator

I can reproduce:

PS> $(Get-ChildItem C:\temp\ | Measure-Object -Property Length).Count
Measure-Object: Cannot process argument because the value of argument "Property" is not valid. Change the value of the "Property" argument and run the operation again.
0
PS > Get-ChildItem C:\temp\ -Recurse

    Directory: C:\temp

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d----          12.05.2021    17:22                52293_original

My current folder is not c:\temp\.

@SteveL-MSFT

Steve Lee (SteveL-MSFT) commented Aug 7, 2021 •

Copy link
Copy Markdown
Member

I see, this doesn't repro on macOS. Got a repro on my Windows machine. I think Measure-Object shouldn't fail here and should ignore it.

@iSazonov

Copy link
Copy Markdown
Collaborator

I don't understand the design:

Statistics stat = _statistics[propertyName];
if (stat.count == 0 && Property != null)
{
// Why are there two different ids for this error?
string errorId = (IsMeasuringGeneric) ? "GenericMeasurePropertyNotFound" : "TextMeasurePropertyNotFound";
WritePropertyNotFoundError(propertyName, errorId);
continue;
}

@SteveL-MSFT

Copy link
Copy Markdown
Member

It looks like the design is to only return that error which is effectively terminating if the result is 0 and the property doesn't match. So if you have a folder that ONLY has an empty folder, then this will fail, but if it has any files it should succeed (which still doesn't make sense to me why the test fails unless it's a race condition).

Is there a repro where there are other items in the folder other than a single empty folder?

@iSazonov

Ilya (iSazonov) commented Aug 7, 2021 •

Copy link
Copy Markdown
Collaborator

It seems my bad. DirectoryInfo hasn't Length property. FileInfo has.

The PR is correct.

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Aug 7, 2021
@ghost ghost removed the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label Aug 9, 2021
@rjmholt
Rob Holt (rjmholt) marked this pull request as ready for review August 9, 2021 20:36
@rjmholt Rob Holt (rjmholt) changed the title Make Measure-Object property test only look for files Make Measure-Object property test independent of the filesystem Aug 9, 2021

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

@rjmholt
Rob Holt (rjmholt) dismissed Steve Lee (SteveL-MSFT)’s stale review August 9, 2021 22:26

Addressed the filesystem dependency issue

@rjmholt
Rob Holt (rjmholt) merged commit 2f5150f into PowerShell:master Aug 9, 2021
@rjmholt
Rob Holt (rjmholt) deleted the fix-measureobject-test branch August 9, 2021 22:27
@ghost

Copy link
Copy Markdown

🎉v7.2.0-preview.9 has been released which incorporates this pull request.:tada:

Handy links:

@ghost

Copy link
Copy Markdown

🎉v7.2.0-preview.10 has been released which incorporates this pull request.:tada:

Handy links:

@kilasuit Ryan Yates (kilasuit) added WG-Cmdlets general cmdlet issues and removed WG-Cmdlets-Utility labels Jul 17, 2026
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

CL-Test Indicates that a PR should be marked as a test change in the Change Log WG-Cmdlets general cmdlet issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants