Skip to content

Commit 9791116

Browse files
SteveL-MSFTTravisEz13
authored andcommitted
reduce output of pester for CI (PowerShell#4855)
1 parent 7c8b7ef commit 9791116

File tree

3 files changed

+78
-5
lines changed

3 files changed

+78
-5
lines changed

build.psm1

Lines changed: 75 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,7 @@ function Start-PSPester {
824824
[Parameter(ParameterSetName='Unelevate',Mandatory=$true)]
825825
[switch]$Unelevate,
826826
[switch]$Quiet,
827+
[switch]$Terse,
827828
[Parameter(ParameterSetName='PassThru',Mandatory=$true)]
828829
[switch]$PassThru,
829830
[switch]$IncludeFailingTest
@@ -865,6 +866,10 @@ function Start-PSPester {
865866

866867
# All concatenated commands/arguments are suffixed with the delimiter (space)
867868
$Command = ""
869+
if ($Terse)
870+
{
871+
$Command += "`$ProgressPreference = 'silentlyContinue'; "
872+
}
868873

869874
# Autoload (in subprocess) temporary modules used in our tests
870875
$Command += '$env:PSModulePath = '+"'$TestModulePath$TestModulePathSeparator'" + '+$($env:PSModulePath);'
@@ -907,6 +912,49 @@ function Start-PSPester {
907912

908913
Write-Verbose $Command
909914

915+
$script:nonewline = $true
916+
$script:inerror = $false
917+
function Write-Terse([string] $line)
918+
{
919+
$trimmedline = $line.Trim()
920+
if ($trimmedline.StartsWith("[+]")) {
921+
Write-Host "+" -NoNewline -ForegroundColor Green
922+
$script:nonewline = $true
923+
$script:inerror = $false
924+
}
925+
elseif ($trimmedline.StartsWith("[?]")) {
926+
Write-Host "?" -NoNewline -ForegroundColor Cyan
927+
$script:nonewline = $true
928+
$script:inerror = $false
929+
}
930+
elseif ($trimmedline.StartsWith("[!]")) {
931+
Write-Host "!" -NoNewline -ForegroundColor Gray
932+
$script:nonewline = $true
933+
$script:inerror = $false
934+
}
935+
else {
936+
if ($script:nonewline) {
937+
Write-Host "`n" -NoNewline
938+
}
939+
if ($trimmedline.StartsWith("[-]") -or $script:inerror) {
940+
Write-Host $line -ForegroundColor Red
941+
$script:inerror = $true
942+
}
943+
elseif ($trimmedline.StartsWith("VERBOSE:")) {
944+
Write-Host $line -ForegroundColor Yellow
945+
$script:inerror = $false
946+
}
947+
elseif ($trimmedline.StartsWith("Describing") -or $trimmedline.StartsWith("Context")) {
948+
Write-Host $line -ForegroundColor Magenta
949+
$script:inerror = $false
950+
}
951+
else {
952+
Write-Host $line -ForegroundColor Gray
953+
}
954+
$script:nonewline = $false
955+
}
956+
}
957+
910958
# To ensure proper testing, the module path must not be inherited by the spawned process
911959
try {
912960
$originalModulePath = $env:PSModulePath
@@ -917,7 +965,17 @@ function Start-PSPester {
917965
while ($true)
918966
{
919967
$lines = Get-Content $outputBufferFilePath | Select-Object -Skip $currentLines
920-
$lines | Write-Host
968+
if ($Terse)
969+
{
970+
foreach ($line in $lines)
971+
{
972+
Write-Terse -line $line
973+
}
974+
}
975+
else
976+
{
977+
$lines | Write-Host
978+
}
921979
if ($lines | Where-Object { $_ -eq '__UNELEVATED_TESTS_THE_END__'})
922980
{
923981
break
@@ -942,7 +1000,14 @@ function Start-PSPester {
9421000
try
9431001
{
9441002
$Command += "|Export-Clixml -Path '$passThruFile' -Force"
945-
Start-NativeExecution -sb {& $powershell -noprofile -c $Command} | ForEach-Object { Write-Host $_}
1003+
if ($Terse)
1004+
{
1005+
Start-NativeExecution -sb {& $powershell -noprofile -c $Command} | ForEach-Object { Write-Terse $_}
1006+
}
1007+
else
1008+
{
1009+
Start-NativeExecution -sb {& $powershell -noprofile -c $Command} | ForEach-Object { Write-Host $_}
1010+
}
9461011
Import-Clixml -Path $passThruFile | Where-Object {$_.TotalCount -is [Int32]}
9471012
}
9481013
finally
@@ -952,7 +1017,14 @@ function Start-PSPester {
9521017
}
9531018
else
9541019
{
955-
Start-NativeExecution -sb {& $powershell -noprofile -c $Command}
1020+
if ($Terse)
1021+
{
1022+
Start-NativeExecution -sb {& $powershell -noprofile -c $Command} | ForEach-Object { Write-Terse -line $_ }
1023+
}
1024+
else
1025+
{
1026+
Start-NativeExecution -sb {& $powershell -noprofile -c $Command}
1027+
}
9561028
}
9571029
}
9581030
} finally {

tools/appveyor.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,11 @@ function Invoke-AppVeyorTest
348348
Remove-Item -Force ${telemetrySemaphoreFilepath}
349349
}
350350

351-
Start-PSPester -bindir $env:CoreOutput -outputFile $testResultsNonAdminFile -Unelevate -Tag @() -ExcludeTag ($ExcludeTag + @('RequireAdminOnWindows'))
351+
Start-PSPester -Terse -bindir $env:CoreOutput -outputFile $testResultsNonAdminFile -Unelevate -Tag @() -ExcludeTag ($ExcludeTag + @('RequireAdminOnWindows'))
352352
Write-Host -Foreground Green 'Upload CoreCLR Non-Admin test results'
353353
Update-AppVeyorTestResults -resultsFile $testResultsNonAdminFile
354354

355-
Start-PSPester -bindir $env:CoreOutput -outputFile $testResultsAdminFile -Tag @('RequireAdminOnWindows') -ExcludeTag $ExcludeTag
355+
Start-PSPester -Terse -bindir $env:CoreOutput -outputFile $testResultsAdminFile -Tag @('RequireAdminOnWindows') -ExcludeTag $ExcludeTag
356356
Write-Host -Foreground Green 'Upload CoreCLR Admin test results'
357357
Update-AppVeyorTestResults -resultsFile $testResultsAdminFile
358358

tools/travis.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ else
158158
$pesterParam = @{
159159
'binDir' = $output
160160
'PassThru' = $true
161+
'Terse' = $true
161162
}
162163

163164
if ($isFullBuild) {

0 commit comments

Comments
 (0)