@@ -165,6 +165,22 @@ InPesterModuleScope {
165165 ) {
166166 Format-Nicely2 - Value $Value | Verify- Equal $Expected
167167 }
168+
169+ # Regression test for https://github.com/pester/Pester/issues/2474
170+ # DirectoryInfo has circular references (Root -> DirectoryInfo) that caused
171+ # infinite recursion. Verify formatting completes without hanging.
172+ It " Formats DirectoryInfo without infinite recursion" {
173+ $dir = [System.IO.DirectoryInfo ]::new($TestDrive )
174+ $job = Start-Job - ScriptBlock {
175+ param ($modulePath , $dirPath )
176+ Import-Module $modulePath
177+ $d = [System.IO.DirectoryInfo ]::new($dirPath )
178+ & (Get-Module Pester) { Format-Nicely2 - Value $args [0 ] } $d
179+ } - ArgumentList (Get-Module Pester).Path, $TestDrive
180+ $result = $job | Wait-Job - Timeout 10 | Receive-Job
181+ $job | Remove-Job - Force
182+ $result | Should -Not - BeNullOrEmpty
183+ }
168184 }
169185
170186 Describe " Get-DisplayProperty2" {
@@ -175,6 +191,19 @@ InPesterModuleScope {
175191 $Actual = Get-DisplayProperty2 - Type $Type
176192 " $Actual " | Verify- Equal " $Expected "
177193 }
194+
195+ # Regression tests for https://github.com/pester/Pester/issues/2474
196+ # DirectoryInfo and FileInfo have circular references (Root, Directory)
197+ # that cause infinite recursion without an explicit property map.
198+ It " Returns 'Name FullName' for DirectoryInfo" {
199+ $Actual = Get-DisplayProperty2 - Type ([System.IO.DirectoryInfo ])
200+ " $Actual " | Verify- Equal " Name FullName"
201+ }
202+
203+ It " Returns 'Name FullName Length' for FileInfo" {
204+ $Actual = Get-DisplayProperty2 - Type ([System.IO.FileInfo ])
205+ " $Actual " | Verify- Equal " Name FullName Length"
206+ }
178207 }
179208
180209 Describe " Format-Type2" {
0 commit comments