mirror of
https://github.com/actions/node-versions.git
synced 2025-09-10 22:11:13 +08:00
Implement script to prepare packages with Node.js
This commit is contained in:
33
helpers/packages-generation/pester-extensions.psm1
Normal file
33
helpers/packages-generation/pester-extensions.psm1
Normal file
@@ -0,0 +1,33 @@
|
||||
<#
|
||||
.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
|
Reference in New Issue
Block a user