Skip to content

Commit 5a1bd5b

Browse files
authored
Fix container name display when running non-file types (fixes #2639). (#2640)
Use a helper that formats the container name correctly for all container types, notably also for ScriptBlocks.
1 parent 48446f3 commit 5a1bd5b

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

src/csharp/Pester/ContainerInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static ContainerInfo Create()
1111
return new ContainerInfo();
1212
}
1313

14+
public string Name { get => ToStringConverter.ContainerItemToString(Type, Item); }
1415
private string _type = Constants.File;
1516
public string Type
1617
{

src/functions/Output.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,8 @@ function Get-WriteScreenPlugin ($Verbosity) {
560560
$p.ContainerRunStart = {
561561
param ($Context)
562562

563-
if ("file" -eq $Context.Block.BlockContainer.Type) {
564-
# write two spaces to separate each file
565-
Write-PesterHostMessage -ForegroundColor $ReportTheme.Container "`nRunning tests from '$($Context.Block.BlockContainer.Item)'"
566-
}
563+
# write two spaces to separate each container
564+
Write-PesterHostMessage -ForegroundColor $ReportTheme.Container "`nRunning tests from '$($Context.Block.BlockContainer.Name)'"
567565
}
568566
}
569567

tst/Pester.RSpec.Output.ts.ps1

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,34 @@ i -PassThru:$PassThru {
186186
}
187187
}
188188

189+
b 'Output for container names' {
190+
t 'Script Block container names are output' {
191+
$sb = {
192+
$PesterPreference = [PesterConfiguration]::Default
193+
$PesterPreference.Output.Verbosity = 'Detailed'
194+
$PesterPreference.Output.CIFormat = 'None'
195+
$PesterPreference.Output.RenderMode = 'ConsoleColor'
196+
197+
$container = New-PesterContainer -ScriptBlock {
198+
Describe 'd1' {
199+
It 'i1' {
200+
1 | Should -Be 1
201+
}
202+
}
203+
}
204+
Invoke-Pester -Container $container
205+
}
206+
207+
$output = Invoke-InNewProcess $sb
208+
# only print the relevant part of output
209+
$null, $run = $output -join "`n" -split 'Running tests.'
210+
$run | Write-Host
211+
212+
$d1Running = $output | Select-String -Pattern '^Running tests from.*\<ScriptBlock\>.*$'
213+
@($d1Running).Count | Verify-Equal 1
214+
}
215+
}
216+
189217
b 'Output for data-driven blocks' {
190218
t 'Each block generated from dataset is output' {
191219
# we incorrectly shared reference to the same framework data hashtable

0 commit comments

Comments
 (0)