Skip to content

Commit

Permalink
Enable process exit in build.ps1
Browse files Browse the repository at this point in the history
Signed-off-by: Dimitar Milov <[email protected]>
  • Loading branch information
dmilov committed Apr 22, 2021
1 parent 84606b0 commit aac584a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 21 additions & 5 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,7 +31,11 @@ param(
[Parameter()]
[ValidateSet('none','unit', 'integration', 'all')]
[string]
$TestsType = 'all'
$TestsType = 'all',

[Parameter()]
[switch]
$ExitProcess
)

$moduleName = 'CloudEvents.Sdk'
Expand Down Expand Up @@ -89,7 +96,10 @@ param(
-PassThru `
-NoNewWindow

$testProcess | Wait-Process
$testProcess | Wait-Process | Out-Null

# Return the number of failed tests
$testProcess.ExitCode
}
}
#endregion
Expand All @@ -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
}
2 changes: 2 additions & 0 deletions test/RunTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

0 comments on commit aac584a

Please sign in to comment.