From ea7c2bddbe43183d15f31b3aa66ee0bd191cd43a Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 13 Sep 2017 14:14:08 -0700 Subject: [PATCH] Update travis-ci script so that PRs can fail due to pester tests (#4830) * Add a switch to force tests to fail for testing CI system to Start-PSPester * [includeFailingTest] Add commit tag to force tests to fail for testing CI system --- build.psm1 | 13 +++++++++++-- tools/failingTests/fail.tests.ps1 | 5 +++++ tools/travis.ps1 | 6 ++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tools/failingTests/fail.tests.ps1 diff --git a/build.psm1 b/build.psm1 index c7f593ed58..8d260f41f9 100644 --- a/build.psm1 +++ b/build.psm1 @@ -843,9 +843,15 @@ function Start-PSPester { [switch]$Unelevate, [switch]$Quiet, [Parameter(ParameterSetName='PassThru',Mandatory=$true)] - [switch]$PassThru + [switch]$PassThru, + [switch]$IncludeFailingTest ) + if ($IncludeFailingTest.IsPresent) + { + $Path += "$PSScriptRoot/tools/failingTests" + } + # we need to do few checks and if user didn't provide $ExcludeTag explicitly, we should alternate the default if ($Unelevate) { @@ -1079,14 +1085,17 @@ function Test-PSPesterResults { if ($ResultObject.TotalCount -le 0) { - logerror 'NO TESTS RUN' + throw 'NO TESTS RUN' } elseif ($ResultObject.FailedCount -gt 0) { logerror 'TEST FAILURES' + $ResultObject.TestResult | Where-Object {$_.Passed -eq $false} | ForEach-Object { Show-PSPesterError -testFailureObject $_ } + + throw "$($ResultObject.FailedCount) tests in $TestArea failed" } } } diff --git a/tools/failingTests/fail.tests.ps1 b/tools/failingTests/fail.tests.ps1 new file mode 100644 index 0000000000..ed4d5ac37e --- /dev/null +++ b/tools/failingTests/fail.tests.ps1 @@ -0,0 +1,5 @@ +Describe "Failing test used to test CI Scripts" -Tags 'CI' { + It "Should fail" { + 1 | should be 2 + } +} diff --git a/tools/travis.ps1 b/tools/travis.ps1 index b1116934ec..d1cf06fdee 100644 --- a/tools/travis.ps1 +++ b/tools/travis.ps1 @@ -114,6 +114,7 @@ else # Run a full build if the build was trigger via cron, api or the commit message contains `[Feature]` $hasFeatureTag = $commitMessage -match '\[feature\]' +$hasRunFailingTestTag = $commitMessage -match '\[includeFailingTest\]' $isDailyBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' -or $env:TRAVIS_EVENT_TYPE -eq 'api' # only update the build badge for the cron job $cronBuild = $env:TRAVIS_EVENT_TYPE -eq 'cron' @@ -167,6 +168,11 @@ else $pesterParam['ThrowOnFailure'] = $true } + if ($hasRunFailingTestTag) + { + $pesterParam['IncludeFailingTest'] = $true + } + # Remove telemetry semaphore file in CI $telemetrySemaphoreFilepath = Join-Path $output DELETE_ME_TO_DISABLE_CONSOLEHOST_TELEMETRY if ( Test-Path "${telemetrySemaphoreFilepath}" ) {