From aac584afb89629584b147cb63afa67cd6bc42e9f Mon Sep 17 00:00:00 2001 From: Dimitar Milov Date: Thu, 22 Apr 2021 09:48:13 +0300 Subject: [PATCH] Enable process exit in build.ps1 Signed-off-by: Dimitar Milov --- build.ps1 | 26 +++++++++++++++++++++----- test/RunTests.ps1 | 2 ++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/build.ps1 b/build.ps1 index ed6e638..eda60af 100644 --- a/build.ps1 +++ b/build.ps1 @@ -15,9 +15,12 @@ Target directory where the CloudEvents.Sdk will be created by the script. The default is the PS Script Root .PARAMETER TestsType - Specifies the type of the test to be run post build. Possible values are 'none','unit', 'integration', 'all'. + Specifies the type of the test to be run post build. Possible values are 'none','unit', 'integration', 'all'. The default is 'all' + .PARAMETER ExitProcess + Specifies whther to exit the running process. Exits with exit code equal to the number of failing tests. + #> param( @@ -28,7 +31,11 @@ param( [Parameter()] [ValidateSet('none','unit', 'integration', 'all')] [string] - $TestsType = 'all' + $TestsType = 'all', + + [Parameter()] + [switch] + $ExitProcess ) $moduleName = 'CloudEvents.Sdk' @@ -89,7 +96,10 @@ param( -PassThru ` -NoNewWindow - $testProcess | Wait-Process + $testProcess | Wait-Process | Out-Null + + # Return the number of failed tests + $testProcess.ExitCode } } #endregion @@ -107,12 +117,18 @@ dotnet publish -c Release -o $OutputDir $dotnetProjectPath # 3. Cleanup Unnecessary Outputs Get-ChildItem "$dotnetProjectName*" -Path $OutputDir | Remove-Item -Confirm:$false +$failedTests = 0 # 4. Run Unit Tests if ($TestsType -eq 'unit' -or $TestsType -eq 'all') { - Start-Tests -TestsType 'unit' + $failedTests += (Start-Tests -TestsType 'unit') } # 5. Run Integration Tests if ($TestsType -eq 'integration' -or $TestsType -eq 'all') { - Start-Tests -TestsType 'integration' + $failedTests += (Start-Tests -TestsType 'integration') } + +# 6. Set exit code +if ($ExitProcess.IsPresent) { + exit $failedTests +} \ No newline at end of file diff --git a/test/RunTests.ps1 b/test/RunTests.ps1 index 543829a..92f410a 100644 --- a/test/RunTests.ps1 +++ b/test/RunTests.ps1 @@ -27,6 +27,7 @@ if ($TestsType -eq 'unit' -or $TestsType -eq 'all') { $pesterConfiguration.Run.Path = (Join-Path $PSScriptRoot 'unit') $pesterConfiguration.Run.Container = $pesterContainer + $pesterConfiguration.Run.Exit = $EnableProcessExit.IsPresent Invoke-Pester -Configuration $pesterConfiguration } @@ -42,6 +43,7 @@ if ($TestsType -eq 'integration' -or $TestsType -eq 'all') { $pesterConfiguration.Run.Path = (Join-Path $PSScriptRoot 'integration') $pesterConfiguration.Run.Container = $pesterContainer + $pesterConfiguration.Run.Exit = $EnableProcessExit.IsPresent Invoke-Pester -Configuration $pesterConfiguration }