Skip to content

Commit 5c3f957

Browse files
nohwndCopilot
andcommitted
Fix #2635: ShowStartMarkers now shows expanded data-driven test names
Moved the start marker output from the EachTestSetupStart plugin step (which fires before name expansion) to a setup scriptblock that runs right after the template expansion in the runtime. This ensures data-driven test names like 'Iteration <_>' display as 'Iteration 1' instead of the raw template. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d6b2f15 commit 5c3f957

3 files changed

Lines changed: 46 additions & 12 deletions

File tree

src/Pester.Runtime.ps1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,21 @@ function Invoke-TestItem {
661661
$script:ScriptBlockSessionStateInternalProperty.SetValue($sb, $SessionStateInternal)
662662
$sb
663663
)
664+
# Write start marker after name expansion so it shows the
665+
# fully expanded test name (fixes #2635).
666+
{
667+
if ($PesterPreference.Debug.ShowStartMarkers.Value) {
668+
$level = $Test.Path.Count
669+
$margin = $ReportStrings.Margin * ($level)
670+
$out = "$($Test.ExpandedName)..."
671+
672+
if ($PesterPreference.Debug.ShowNavigationMarkers.Value) {
673+
$out += ", $($Test.ScriptBlock.File):$($Test.StartLine)"
674+
}
675+
676+
Write-PesterHostMessage -ForegroundColor $ReportTheme.Information "$margin[|] $out"
677+
}
678+
}
664679
) `
665680
-ScriptBlock $Test.ScriptBlock `
666681
-Teardown @(

src/functions/Output.ps1

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -613,18 +613,6 @@ function Get-WriteScreenPlugin ($Verbosity) {
613613
if ($_test.First) {
614614
Write-BlockToScreen $_test.Block
615615
}
616-
617-
if ($PesterPreference.Debug.ShowStartMarkers.Value) {
618-
$level = $_test.Path.Count
619-
$margin = $ReportStrings.Margin * ($level)
620-
$out = "$($_test.ExpandedName)..."
621-
622-
if ($PesterPreference.Debug.ShowNavigationMarkers.Value) {
623-
$out += ", $($_test.ScriptBlock.File):$($_test.StartLine)"
624-
}
625-
626-
Write-PesterHostMessage -ForegroundColor $ReportTheme.Information "$margin[|] $out"
627-
}
628616
}
629617
}
630618

tst/Pester.RSpec.Output.ts.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,37 @@ i -PassThru:$PassThru {
184184
$i3Start = $output | Select-String -Pattern '\[\|\] i3\.\.\.$'
185185
@($i3Start).Count | Verify-Equal 1
186186
}
187+
188+
t 'Start markers show expanded names for data-driven tests' {
189+
$sb = {
190+
$PesterPreference = [PesterConfiguration]::Default
191+
$PesterPreference.Output.Verbosity = 'Detailed'
192+
$PesterPreference.Debug.ShowStartMarkers = $true
193+
$PesterPreference.Output.CIFormat = 'None'
194+
$PesterPreference.Output.RenderMode = 'ConsoleColor'
195+
196+
$container = New-PesterContainer -ScriptBlock {
197+
Describe 'd1' {
198+
It 'Iteration <_>' -ForEach @(1, 2, 3) {
199+
1 | Should -Be 1
200+
}
201+
}
202+
}
203+
Invoke-Pester -Container $container
204+
}
205+
206+
$output = Invoke-InNewProcess $sb
207+
# only print the relevant part of output
208+
$null, $run = $output -join "`n" -split 'Running tests.'
209+
$run | Write-Host
210+
211+
$i1Start = $output | Select-String -Pattern '\[\|\] Iteration 1\.\.\.$'
212+
@($i1Start).Count | Verify-Equal 1
213+
$i2Start = $output | Select-String -Pattern '\[\|\] Iteration 2\.\.\.$'
214+
@($i2Start).Count | Verify-Equal 1
215+
$i3Start = $output | Select-String -Pattern '\[\|\] Iteration 3\.\.\.$'
216+
@($i3Start).Count | Verify-Equal 1
217+
}
187218
}
188219

189220
b 'Output for container names' {

0 commit comments

Comments
 (0)