forked from actions/runner-images
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Windows] Improve Pester tests coverage for MSYS2 (actions#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
- Loading branch information
1 parent
4143d0c
commit 1fb8c5d
Showing
5 changed files
with
106 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,78 @@ | ||
$toolsetContent = (Get-ToolsetContent).MsysPackages | ||
$archs = $toolsetContent.mingw.arch | ||
|
||
BeforeAll { | ||
$msys2BinDir = "C:\msys64\usr\bin" | ||
$msys2mingwDir = "C:\msys64\mingw64\bin" | ||
$msys2Dir = "C:\msys64\usr\bin" | ||
$originalPath = $env:PATH | ||
} | ||
|
||
Describe "MSYS2" { | ||
It "<ToolName>" -TestCases @( | ||
Describe "MSYS2 packages" { | ||
BeforeEach { | ||
$env:PATH = "$msys2Dir;$env:PATH" | ||
} | ||
|
||
It "msys2Dir exists" { | ||
$msys2Dir | Should -Exist | ||
} | ||
|
||
$TestCases = @( | ||
@{ ToolName = "bash.exe" } | ||
@{ ToolName = "tar.exe" } | ||
@{ ToolName = "make.exe" } | ||
) { | ||
Join-Path $msys2BinDir $ToolName | Should -Exist | ||
) | ||
|
||
It "<ToolName> is installed in <msys2Dir>" -TestCases $TestCases { | ||
(Get-Command "$ToolName").Source | Should -BeLike "$msys2Dir*" | ||
} | ||
|
||
It "<ToolName> is avaialable" -TestCases $TestCases { | ||
"$ToolName" | Should -ReturnZeroExitCodeWithParam | ||
} | ||
|
||
It "<ToolName>" -TestCases @( | ||
@{ ToolName = "gcc.exe" } | ||
@{ ToolName = "cmake.exe" } | ||
@{ ToolName = "g++.exe" } | ||
@{ ToolName = "clang-tidy.exe" } | ||
) { | ||
Join-Path $msys2mingwDir $ToolName | Should -Exist | ||
AfterEach { | ||
$env:PATH = $originalPath | ||
} | ||
} | ||
|
||
foreach ($arch in $archs) { | ||
Describe "$arch arch packages" { | ||
$archPackages = $toolsetContent.mingw | Where-Object { $_.arch -eq $arch } | ||
$tools = $archPackages.runtime_packages.name | ||
|
||
if ($arch -eq "mingw-w64-i686") | ||
{ | ||
$ExecDir = "C:\msys64\mingw32\bin" | ||
} | ||
else | ||
{ | ||
$ExecDir = "C:\msys64\mingw64\bin" | ||
} | ||
|
||
foreach ($tool in $tools) { | ||
Context "$tool package"{ | ||
$executables = ($archPackages.runtime_packages | Where-Object { $_.name -eq $tool }).executables | ForEach-Object { | ||
@{ | ||
ExecName = $_ | ||
ExecDir = $ExecDir | ||
} | ||
} | ||
|
||
BeforeEach { | ||
$env:PATH = "$ExecDir;$env:PATH" | ||
} | ||
|
||
It "<ExecName> is installed in <ExecDir>" -TestCases $executables { | ||
(Get-Command "$ExecName").Source | Should -BeLike "$ExecDir*" | ||
} | ||
|
||
It "<ExecName> is available" -TestCases $executables { | ||
"$ExecName" | Should -ReturnZeroExitCodeWithParam | ||
} | ||
|
||
AfterEach { | ||
$env:PATH = $originalPath | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters