pull/15/head
Nikita Bykov 5 years ago
parent 4e226c0233
commit 0fa94677df

@ -6,27 +6,22 @@ Pester extension that allows to run command and validate exit code
#> #>
function Get-CommandResult { function Get-CommandResult {
param ( Param (
[Parameter(Mandatory=$true)] [Parameter(Mandatory)][string] $Command
[string] $Command,
[switch] $Multiline
) )
# Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version") # CMD trick to suppress and show error output because some commands write to stderr (for example, "python --version")
if ($IsWindows) { [string[]]$output = & $env:comspec /c "$Command 2>&1"
[string[]]$stdout = & $env:comspec /c "$Command 2>&1"
} else {
$stdout = & bash -c "$Command 2>&1"
}
$exitCode = $LASTEXITCODE $exitCode = $LASTEXITCODE
return @{ return @{
Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout } Output = $output
ExitCode = $exitCode ExitCode = $exitCode
} }
} }
function ShouldReturnZeroExitCode { function ShouldReturnZeroExitCode {
Param( Param(
[String] $ActualValue, [string] $ActualValue,
[switch] $Negate, [switch] $Negate,
[string] $Because # This parameter is unused by we need it to match Pester asserts signature [string] $Because # This parameter is unused by we need it to match Pester asserts signature
) )

Loading…
Cancel
Save