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
5 changes: 4 additions & 1 deletion src/Format2.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ function Get-DisplayProperty2 ([Type]$Type) {
# and for types that do not exist

$propertyMap = @{
'System.Diagnostics.Process' = 'Id', 'Name'
'System.Diagnostics.Process' = 'Id', 'Name'
# DirectoryInfo and FileInfo have circular references (Root, Directory) that cause infinite recursion
'System.IO.DirectoryInfo' = 'Name', 'FullName'
'System.IO.FileInfo' = 'Name', 'FullName', 'Length'
}

$propertyMap[$Type.FullName]
Expand Down
29 changes: 29 additions & 0 deletions tst/Format2.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,22 @@ InPesterModuleScope {
) {
Format-Nicely2 -Value $Value | Verify-Equal $Expected
}

# Regression test for https://github.com/pester/Pester/issues/2474
# DirectoryInfo has circular references (Root -> DirectoryInfo) that caused
# infinite recursion. Verify formatting completes without hanging.
It "Formats DirectoryInfo without infinite recursion" {
$dir = [System.IO.DirectoryInfo]::new($TestDrive)
$job = Start-Job -ScriptBlock {
param($modulePath, $dirPath)
Import-Module $modulePath
$d = [System.IO.DirectoryInfo]::new($dirPath)
& (Get-Module Pester) { Format-Nicely2 -Value $args[0] } $d
} -ArgumentList (Get-Module Pester).Path, $TestDrive
$result = $job | Wait-Job -Timeout 10 | Receive-Job
$job | Remove-Job -Force
$result | Should -Not -BeNullOrEmpty
}
}

Describe "Get-DisplayProperty2" {
Expand All @@ -175,6 +191,19 @@ InPesterModuleScope {
$Actual = Get-DisplayProperty2 -Type $Type
"$Actual" | Verify-Equal "$Expected"
}

# Regression tests for https://github.com/pester/Pester/issues/2474
# DirectoryInfo and FileInfo have circular references (Root, Directory)
# that cause infinite recursion without an explicit property map.
It "Returns 'Name FullName' for DirectoryInfo" {
$Actual = Get-DisplayProperty2 -Type ([System.IO.DirectoryInfo])
"$Actual" | Verify-Equal "Name FullName"
}

It "Returns 'Name FullName Length' for FileInfo" {
$Actual = Get-DisplayProperty2 -Type ([System.IO.FileInfo])
"$Actual" | Verify-Equal "Name FullName Length"
}
}

Describe "Format-Type2" {
Expand Down
Loading