mirror of
https://github.com/actions/runner-images.git
synced 2025-12-15 06:08:07 +00:00
[Windows] Improve Pester tests coverage for MSYS2 (#3595)
* Add ShouldReturnZeroExitCodeWithParam function and a new set of tests for MSYS2 tools * Change get-command -> Get-Command * Remove elevated user, return original path after msys installation and tests, resolve nitpicks * Add BeforeEach and AfterEach blocks These blocks change the path before each test and return the original path after each test * Change get-command -> Get-Command
This commit is contained in:
@@ -96,6 +96,42 @@ function ShouldReturnZeroExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
# Pester Assert to check exit code of command with given parameter, the assertion performed up to 3 checks (without '-', with 1 and 2 '-') until succeeded
|
||||
function ShouldReturnZeroExitCodeWithParam {
|
||||
param (
|
||||
[Parameter(Mandatory)] [string] $ActualValue,
|
||||
[switch] $Negate,
|
||||
[string] $CallParameter = "version",
|
||||
[string] $CallerSessionState
|
||||
)
|
||||
|
||||
$delimiterCharacter = ""
|
||||
|
||||
while ($delimiterCharacter.Length -le 2)
|
||||
{
|
||||
$callParameterWithDelimeter = $delimiterCharacter + $CallParameter
|
||||
$commandToCheck = "$ActualValue $callParameterWithDelimeter"
|
||||
[bool]$succeeded = (ShouldReturnZeroExitCode -ActualValue $commandToCheck).Succeeded
|
||||
|
||||
if ($succeeded)
|
||||
{
|
||||
break
|
||||
}
|
||||
$delimiterCharacter += '-'
|
||||
}
|
||||
if ($Negate) { $succeeded = -not $succeeded }
|
||||
|
||||
if (-not $succeeded)
|
||||
{
|
||||
$failureMessage = "Tool '$ActualValue' has not returned 0 exit code for any of these flags: '$CallParameter' or '-$CallParameter' or '--$CallParameter'"
|
||||
}
|
||||
|
||||
return [PSCustomObject] @{
|
||||
Succeeded = $succeeded
|
||||
FailureMessage = $failureMessage
|
||||
}
|
||||
}
|
||||
|
||||
# Pester Assert to match output of command
|
||||
function ShouldMatchCommandOutput {
|
||||
Param(
|
||||
@@ -130,5 +166,6 @@ function ShouldMatchCommandOutput {
|
||||
|
||||
If (Get-Command -Name Add-ShouldOperator -ErrorAction SilentlyContinue) {
|
||||
Add-ShouldOperator -Name ReturnZeroExitCode -InternalName ShouldReturnZeroExitCode -Test ${function:ShouldReturnZeroExitCode}
|
||||
Add-ShouldOperator -Name ReturnZeroExitCodeWithParam -InternalName ShouldReturnZeroExitCodeWithParam -Test ${function:ShouldReturnZeroExitCodeWithParam}
|
||||
Add-ShouldOperator -Name MatchCommandOutput -InternalName ShouldMatchCommandOutput -Test ${function:ShouldMatchCommandOutput}
|
||||
}
|
||||
Reference in New Issue
Block a user