modify Start-PSPester to accept -Quiet to eliminate Pester output (#2795)

* modify Start-PSPester to accept -Quiet to eliminate Pester output

also modify travis.ps1 to include -Quiet for Pester args to reduce
stdout log size which should hopefully allow daily builds to run
without being cancelled due to too much output

* Add error detail information as part of Test-PSPesterResults

Test-PSPesterResults will now also emit information about the errors
found during a test run rather than just the number of failed tests.
Created a new errorlog function so the output of errors will be red.
This commit is contained in:
James Truher [MSFT] 2016-12-01 11:23:14 -08:00 committed by Jason Shirk
parent b51b52d6b2
commit 8e360bffb1
2 changed files with 37 additions and 2 deletions

View file

@ -667,7 +667,8 @@ function Start-PSPester {
[string]$binDir = (Split-Path (New-PSOptions -FullCLR:$FullCLR).Output),
[string]$powershell = (Join-Path $binDir 'powershell'),
[string]$Pester = ([IO.Path]::Combine($binDir, "Modules", "Pester")),
[switch]$Unelevate
[switch]$Unelevate,
[switch]$Quiet
)
# we need to do few checks and if user didn't provide $ExcludeTag explicitly, we should alternate the default
@ -726,6 +727,11 @@ function Start-PSPester {
if ($Tag) {
$Command += "-Tag @('" + (${Tag} -join "','") + "') "
}
# sometimes we need to eliminate Pester output, especially when we're
# doing a daily build as the log file is too large
if ( $Quiet ) {
$Command += "-Quiet "
}
$Command += "'" + $Path + "'"
if ($Unelevate)
@ -799,6 +805,17 @@ function script:Start-UnelevatedProcess
runas.exe /trustlevel:0x20000 "$process $arguments"
}
function Show-PSPesterError
{
param ( [Xml.XmlElement]$testFailure )
logerror ("Description: " + $testFailure.description)
logerror ("Name: " + $testFailure.name)
logerror "message:"
logerror $testFailure.failure.message
logerror "stack-trace:"
logerror $testFailure.failure."stack-trace"
}
#
# Read the test result file and
# Throw if a test failed
@ -806,7 +823,7 @@ function Test-PSPesterResults
{
param(
[string]$TestResultsFile = "pester-tests.xml",
[string] $TestArea = 'test/powershell'
[string]$TestArea = 'test/powershell'
)
if(!(Test-Path $TestResultsFile))
@ -817,6 +834,11 @@ function Test-PSPesterResults
$x = [xml](Get-Content -raw $testResultsFile)
if ([int]$x.'test-results'.failures -gt 0)
{
logerror "TEST FAILURES"
foreach ( $testfail in $x.SelectNodes('.//test-case[@result = "Failure"]'))
{
Show-PSPesterError $testfail
}
throw "$($x.'test-results'.failures) tests in $TestArea failed"
}
}
@ -2053,6 +2075,12 @@ function script:log([string]$message) {
[console]::ResetColor()
}
function script:logerror([string]$message) {
Write-Host -Foreground Red $message
#reset colors for older package to at return to default after error message on a compilation error
[console]::ResetColor()
}
function script:precheck([string]$command, [string]$missedMessage) {
$c = Get-Command $command -ErrorAction SilentlyContinue
if (-not $c) {

View file

@ -17,6 +17,13 @@ $pesterParam = @{ 'binDir' = $output }
if ($isFullBuild) {
$pesterParam['Tag'] = @('CI','Feature','Scenario')
$pesterParam['ExcludeTag'] = @()
# cron jobs create log files which include the stdout of Pester
# which creates too much data for travis to put in the log file
# and the job is then cancelled. Add Quiet to reduce the log size
# the xunit log created by pester is what is important
if ( $env:TRAVIS_EVENT_TYPE -eq 'cron' ) {
$pesterParam['Quiet'] = $true
}
} else {
$pesterParam['Tag'] = @('CI')
$pesterParam['ThrowOnFailure'] = $true