Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,9 @@ private void WritePropertyNotFoundError(string propertyName, string errorId)
{
Diagnostics.Assert(Property != null, "no property and no InputObject should have been addressed");
ErrorRecord errorRecord = new(
PSTraceSource.NewArgumentException("Property"),
PSTraceSource.NewArgumentException(propertyName),
errorId,
ErrorCategory.InvalidArgument,
ErrorCategory.ObjectNotFound,
null);
errorRecord.ErrorDetails = new ErrorDetails(
this, "MeasureObjectStrings", "PropertyNotFound", propertyName);
Expand All @@ -820,9 +820,12 @@ protected override void EndProcessing()
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);
if (Context.IsStrictVersion(2))
{
string errorId = (IsMeasuringGeneric) ? "GenericMeasurePropertyNotFound" : "TextMeasurePropertyNotFound";
WritePropertyNotFoundError(propertyName, errorId);
}

continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,26 @@ Describe "Measure-Object" -Tags "CI" {
}
}

Context "Empty folder tests" {
BeforeAll {
$repoPath = Join-Path -Path $TESTDRIVE -ChildPath "my_folder"
$testEmptyFolder = New-Item $repoPath -ItemType "directory"
$propertyName = "Length"
}

AfterAll {
Set-StrictMode -off
}

It "Should not throw an invalid property error when not in StrictMode" {
{ Set-StrictMode -off; Get-Item $testEmptyFolder | Measure-Object $propertyName -ErrorAction Stop -sum } | Should -Not -Throw
}

It "Should throw an invalid property error when in StrictMode" {
{ Set-StrictMode -version 3.0; Get-Item $testEmptyFolder | Measure-Object $propertyName -ErrorAction Stop -sum } | Should -Throw -ErrorId 'GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand'
}
}

Context "String tests" {
BeforeAll {
$nl = [Environment]::NewLine
Expand Down