diff --git a/src/csharp/Pester/ContainerInfo.cs b/src/csharp/Pester/ContainerInfo.cs index 00dfa2743..796153590 100644 --- a/src/csharp/Pester/ContainerInfo.cs +++ b/src/csharp/Pester/ContainerInfo.cs @@ -11,6 +11,7 @@ public static ContainerInfo Create() return new ContainerInfo(); } + public string Name { get => ToStringConverter.ContainerItemToString(Type, Item); } private string _type = Constants.File; public string Type { diff --git a/src/functions/Output.ps1 b/src/functions/Output.ps1 index 8ce6e74ed..b65797374 100644 --- a/src/functions/Output.ps1 +++ b/src/functions/Output.ps1 @@ -641,10 +641,8 @@ function Get-WriteScreenPlugin ($Verbosity) { $p.ContainerRunStart = { param ($Context) - if ("file" -eq $Context.Block.BlockContainer.Type) { - # write two spaces to separate each file - Write-PesterHostMessage -ForegroundColor $ReportTheme.Container "`nRunning tests from '$($Context.Block.BlockContainer.Item)'" - } + # write two spaces to separate each container + Write-PesterHostMessage -ForegroundColor $ReportTheme.Container "`nRunning tests from '$($Context.Block.BlockContainer.Name)'" } } diff --git a/tst/Pester.RSpec.Output.ts.ps1 b/tst/Pester.RSpec.Output.ts.ps1 index f921dd1e8..462df04b8 100644 --- a/tst/Pester.RSpec.Output.ts.ps1 +++ b/tst/Pester.RSpec.Output.ts.ps1 @@ -186,6 +186,34 @@ i -PassThru:$PassThru { } } + b 'Output for container names' { + t 'Script Block container names are output' { + $sb = { + $PesterPreference = [PesterConfiguration]::Default + $PesterPreference.Output.Verbosity = 'Detailed' + $PesterPreference.Output.CIFormat = 'None' + $PesterPreference.Output.RenderMode = 'ConsoleColor' + + $container = New-PesterContainer -ScriptBlock { + Describe 'd1' { + It 'i1' { + 1 | Should -Be 1 + } + } + } + Invoke-Pester -Container $container + } + + $output = Invoke-InNewProcess $sb + # only print the relevant part of output + $null, $run = $output -join "`n" -split 'Running tests.' + $run | Write-Host + + $d1Running = $output | Select-String -Pattern '^Running tests from.*\.*$' + @($d1Running).Count | Verify-Equal 1 + } + } + b 'Output for data-driven blocks' { t 'Each block generated from dataset is output' { # we incorrectly shared reference to the same framework data hashtable