mirror of
https://github.com/actions/runner-images.git
synced 2025-12-14 22:05:17 +00:00
add assert MatchCommandOutput
This commit is contained in:
@@ -91,6 +91,39 @@ function ShouldReturnZeroExitCode {
|
||||
}
|
||||
}
|
||||
|
||||
# Pester Assert to match output of command
|
||||
function ShouldMatchCommandOutput {
|
||||
Param(
|
||||
[String] $ActualValue,
|
||||
[String] $RegularExpression,
|
||||
[switch] $Negate
|
||||
)
|
||||
|
||||
$output = (Get-CommandResult $ActualValue).Output | Out-String
|
||||
[bool] $succeeded = $output -cmatch $RegularExpression
|
||||
|
||||
if ($Negate) {
|
||||
$succeeded = -not $succeeded
|
||||
}
|
||||
|
||||
$failureMessage = ''
|
||||
|
||||
if (-not $succeeded) {
|
||||
if ($Negate) {
|
||||
$failureMessage = "Expected regular expression '$RegularExpression' for '$ActualValue' command to not match '$output',but it did match."
|
||||
}
|
||||
else {
|
||||
$failureMessage = "Expected regular expression '$RegularExpression' for '$ActualValue' command to match '$output',but it did not match."
|
||||
}
|
||||
}
|
||||
|
||||
return [PSCustomObject] @{
|
||||
Succeeded = $succeeded
|
||||
FailureMessage = $failureMessage
|
||||
}
|
||||
}
|
||||
|
||||
If (Get-Command -Name Add-AssertionOperator -ErrorAction SilentlyContinue) {
|
||||
Add-AssertionOperator -Name ReturnZeroExitCode -InternalName ShouldReturnZeroExitCode -Test ${function:ShouldReturnZeroExitCode}
|
||||
Add-AssertionOperator -Name MatchCommandOutput -InternalName ShouldMatchCommandOutput -Test ${function:ShouldMatchCommandOutput}
|
||||
}
|
||||
@@ -41,3 +41,4 @@ Choco-Install -PackageName hub
|
||||
Add-MachinePathItem "C:\Program Files\Git\bin"
|
||||
|
||||
Invoke-PesterTests -TestFile "Git" -TestName "Git"
|
||||
Invoke-PesterTests -TestFile "Git" -TestName "Hub"
|
||||
|
||||
@@ -17,11 +17,11 @@ Describe "Haskell" {
|
||||
}
|
||||
|
||||
It "GHC <ghcVersion> is installed" -TestCases $ghcTestCases {
|
||||
& $binGhcPath --version | Should -Match $ghcVersion
|
||||
"$binGhcPath --version" | Should -MatchCommandOutput $ghcVersion
|
||||
}
|
||||
|
||||
It "GHC <defaultGhcVersion> is the default version and should be the latest installed" -TestCases @{defaultGhcVersion = $defaultGhcVersion} {
|
||||
ghc --version | Should -Match $defaultGhcVersion
|
||||
"ghc --version" | Should -MatchCommandOutput $defaultGhcVersion
|
||||
}
|
||||
|
||||
It "Cabal is installed" {
|
||||
|
||||
Reference in New Issue
Block a user