diff --git a/common-helpers.psm1 b/common-helpers.psm1 index 4d3d3f1..fa54723 100644 --- a/common-helpers.psm1 +++ b/common-helpers.psm1 @@ -83,3 +83,26 @@ function IsNixPlatform { return ($Platform -match "macos") -or ($Platform -match "darwin") -or ($Platform -match "ubuntu") -or ($Platform -match "linux") } + +<# +.SYNOPSIS +Get root directory of selected tool +#> +function GetToolDirectory { + param( + [Parameter(Mandatory=$true)] + [String]$ToolName, + [Parameter(Mandatory=$true)] + [String]$Version, + [Parameter(Mandatory=$true)] + [String]$Architecture + ) + $targetPath = $env:AGENT_TOOLSDIRECTORY + if ([string]::IsNullOrEmpty($targetPath)) { + # GitHub Windows images don't have `AGENT_TOOLSDIRECTORY` variable + $targetPath = $env:RUNNER_TOOL_CACHE + } + $ToolcachePath = Join-Path -Path $targetPath -ChildPath $ToolName + $ToolcacheVersionPath = Join-Path -Path $ToolcachePath -ChildPath $Version + return Join-Path $ToolcacheVersionPath $Architecture +} diff --git a/pester-extensions.psm1 b/pester-extensions.psm1 index 6cec822..1284581 100644 --- a/pester-extensions.psm1 +++ b/pester-extensions.psm1 @@ -6,14 +6,19 @@ Pester extension that allows to run command and validate exit code #> function Get-CommandResult { - param ( + Param ( [Parameter(Mandatory=$true)] [string] $Command, [switch] $Multiline ) - # Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version") - $stdout = & bash -c "$Command 2>&1" + # CMD and bash trick to suppress and show error output because some commands write to stderr (for example, "python --version") + If ($IsWindows) { + $stdout = & $env:comspec /c "$Command 2>&1" + } else { + $stdout = & bash -c "$Command 2>&1" + } $exitCode = $LASTEXITCODE + return @{ Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout } ExitCode = $exitCode