Skip to content

Commit 37a8353

Browse files
author
Michael Gasch
authored
Merge pull request #20 from dmilov/topic/dmilov/tests-exit-code
2 parents 3629c77 + aac584a commit 37a8353

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

build.ps1

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@
1515
Target directory where the CloudEvents.Sdk will be created by the script. The default is the PS Script Root
1616
1717
.PARAMETER TestsType
18-
Specifies the type of the test to be run post build. Possible values are 'none','unit', 'integration', 'all'.
18+
Specifies the type of the test to be run post build. Possible values are 'none','unit', 'integration', 'all'.
1919
The default is 'all'
2020
21+
.PARAMETER ExitProcess
22+
Specifies whther to exit the running process. Exits with exit code equal to the number of failing tests.
23+
2124
#>
2225

2326
param(
@@ -28,7 +31,11 @@ param(
2831
[Parameter()]
2932
[ValidateSet('none','unit', 'integration', 'all')]
3033
[string]
31-
$TestsType = 'all'
34+
$TestsType = 'all',
35+
36+
[Parameter()]
37+
[switch]
38+
$ExitProcess
3239
)
3340

3441
$moduleName = 'CloudEvents.Sdk'
@@ -89,7 +96,10 @@ param(
8996
-PassThru `
9097
-NoNewWindow
9198

92-
$testProcess | Wait-Process
99+
$testProcess | Wait-Process | Out-Null
100+
101+
# Return the number of failed tests
102+
$testProcess.ExitCode
93103
}
94104
}
95105
#endregion
@@ -107,12 +117,18 @@ dotnet publish -c Release -o $OutputDir $dotnetProjectPath
107117
# 3. Cleanup Unnecessary Outputs
108118
Get-ChildItem "$dotnetProjectName*" -Path $OutputDir | Remove-Item -Confirm:$false
109119

120+
$failedTests = 0
110121
# 4. Run Unit Tests
111122
if ($TestsType -eq 'unit' -or $TestsType -eq 'all') {
112-
Start-Tests -TestsType 'unit'
123+
$failedTests += (Start-Tests -TestsType 'unit')
113124
}
114125

115126
# 5. Run Integration Tests
116127
if ($TestsType -eq 'integration' -or $TestsType -eq 'all') {
117-
Start-Tests -TestsType 'integration'
128+
$failedTests += (Start-Tests -TestsType 'integration')
118129
}
130+
131+
# 6. Set exit code
132+
if ($ExitProcess.IsPresent) {
133+
exit $failedTests
134+
}

test/RunTests.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ if ($TestsType -eq 'unit' -or $TestsType -eq 'all') {
2727

2828
$pesterConfiguration.Run.Path = (Join-Path $PSScriptRoot 'unit')
2929
$pesterConfiguration.Run.Container = $pesterContainer
30+
$pesterConfiguration.Run.Exit = $EnableProcessExit.IsPresent
3031

3132
Invoke-Pester -Configuration $pesterConfiguration
3233
}
@@ -42,6 +43,7 @@ if ($TestsType -eq 'integration' -or $TestsType -eq 'all') {
4243

4344
$pesterConfiguration.Run.Path = (Join-Path $PSScriptRoot 'integration')
4445
$pesterConfiguration.Run.Container = $pesterContainer
46+
$pesterConfiguration.Run.Exit = $EnableProcessExit.IsPresent
4547

4648
Invoke-Pester -Configuration $pesterConfiguration
4749
}

0 commit comments

Comments
 (0)