Files
versions-package-tools/pester-extensions.psm1
Dmitry Shibanov d8c3ce72ee Merge helpers function from node, boost, python. (#2)
* setup boost helpers

* add ci for pull requests

* pester for ci

* resolving issue with pester 5

* remove Output flag

* check tests with 4 version

* try common tests variant

* added requires

* move to 5 version

* try to add assert module

* fix scope

* use new regex for python

* fix regex in tests

* Pester 4.10.1

* EnableExit

* fix synopsys

* fix creating tar archive

Co-authored-by: Dmitry Shibanov <v-dmshib@microsoft.com>
Co-authored-by: Maxim Lobanov <v-malob@microsoft.com>
2020-06-01 17:46:35 +03:00

34 lines
949 B
PowerShell

<#
.SYNOPSIS
Pester extension that allows to run command and validate exit code
.EXAMPLE
"python file.py" | Should -ReturnZeroExitCode
#>
function ShouldReturnZeroExitCode {
Param(
[Parameter (Mandatory = $true)] [ValidateNotNullOrEmpty()]
[String]$ActualValue,
[switch]$Negate
)
Write-Host "Run command '${ActualValue}'"
Invoke-Expression -Command $ActualValue | ForEach-Object { Write-Host $_ }
$actualExitCode = $LASTEXITCODE
[bool]$succeeded = $actualExitCode -eq 0
if ($Negate) { $succeeded = -not $succeeded }
if (-not $succeeded)
{
$failureMessage = "Command '${ActualValue}' has finished with exit code ${actualExitCode}"
}
return New-Object PSObject -Property @{
Succeeded = $succeeded
FailureMessage = $failureMessage
}
}
Add-AssertionOperator -Name ReturnZeroExitCode `
-Test $function:ShouldReturnZeroExitCode