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

@ -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
}

View File

@ -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
}