Enable process exit in build.ps1

Signed-off-by: Dimitar Milov <dmilov@vmware.com>
This commit is contained in:
Dimitar Milov 2021-04-22 09:48:13 +03:00
parent 84606b0ab9
commit aac584afb8
2 changed files with 23 additions and 5 deletions

View File

@ -18,6 +18,9 @@
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' 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( param(
@ -28,7 +31,11 @@ param(
[Parameter()] [Parameter()]
[ValidateSet('none','unit', 'integration', 'all')] [ValidateSet('none','unit', 'integration', 'all')]
[string] [string]
$TestsType = 'all' $TestsType = 'all',
[Parameter()]
[switch]
$ExitProcess
) )
$moduleName = 'CloudEvents.Sdk' $moduleName = 'CloudEvents.Sdk'
@ -89,7 +96,10 @@ param(
-PassThru ` -PassThru `
-NoNewWindow -NoNewWindow
$testProcess | Wait-Process $testProcess | Wait-Process | Out-Null
# Return the number of failed tests
$testProcess.ExitCode
} }
} }
#endregion #endregion
@ -107,12 +117,18 @@ dotnet publish -c Release -o $OutputDir $dotnetProjectPath
# 3. Cleanup Unnecessary Outputs # 3. Cleanup Unnecessary Outputs
Get-ChildItem "$dotnetProjectName*" -Path $OutputDir | Remove-Item -Confirm:$false Get-ChildItem "$dotnetProjectName*" -Path $OutputDir | Remove-Item -Confirm:$false
$failedTests = 0
# 4. Run Unit Tests # 4. Run Unit Tests
if ($TestsType -eq 'unit' -or $TestsType -eq 'all') { if ($TestsType -eq 'unit' -or $TestsType -eq 'all') {
Start-Tests -TestsType 'unit' $failedTests += (Start-Tests -TestsType 'unit')
} }
# 5. Run Integration Tests # 5. Run Integration Tests
if ($TestsType -eq 'integration' -or $TestsType -eq 'all') { 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
} }

View File

@ -27,6 +27,7 @@ if ($TestsType -eq 'unit' -or $TestsType -eq 'all') {
$pesterConfiguration.Run.Path = (Join-Path $PSScriptRoot 'unit') $pesterConfiguration.Run.Path = (Join-Path $PSScriptRoot 'unit')
$pesterConfiguration.Run.Container = $pesterContainer $pesterConfiguration.Run.Container = $pesterContainer
$pesterConfiguration.Run.Exit = $EnableProcessExit.IsPresent
Invoke-Pester -Configuration $pesterConfiguration 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.Path = (Join-Path $PSScriptRoot 'integration')
$pesterConfiguration.Run.Container = $pesterContainer $pesterConfiguration.Run.Container = $pesterContainer
$pesterConfiguration.Run.Exit = $EnableProcessExit.IsPresent
Invoke-Pester -Configuration $pesterConfiguration Invoke-Pester -Configuration $pesterConfiguration
} }