diff --git a/images/win/scripts/ImageHelpers/TestsHelpers.ps1 b/images/win/scripts/ImageHelpers/TestsHelpers.ps1 index 7a0229ac5..ae3e10746 100644 --- a/images/win/scripts/ImageHelpers/TestsHelpers.ps1 +++ b/images/win/scripts/ImageHelpers/TestsHelpers.ps1 @@ -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} } \ No newline at end of file diff --git a/images/win/scripts/Installers/Install-Git.ps1 b/images/win/scripts/Installers/Install-Git.ps1 index 1537be801..25ce857db 100644 --- a/images/win/scripts/Installers/Install-Git.ps1 +++ b/images/win/scripts/Installers/Install-Git.ps1 @@ -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" diff --git a/images/win/scripts/Tests/Haskell.Tests.ps1 b/images/win/scripts/Tests/Haskell.Tests.ps1 index 99780a55f..b6ebb7630 100644 --- a/images/win/scripts/Tests/Haskell.Tests.ps1 +++ b/images/win/scripts/Tests/Haskell.Tests.ps1 @@ -17,11 +17,11 @@ Describe "Haskell" { } It "GHC is installed" -TestCases $ghcTestCases { - & $binGhcPath --version | Should -Match $ghcVersion + "$binGhcPath --version" | Should -MatchCommandOutput $ghcVersion } It "GHC 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" {