Files
runner-images/images/win/scripts/Tests/Haskell.Tests.ps1
Julian Ospald 1fb7d122d1 Expose ghcup binary to PATH on windows (#4264)
* Expose ghcup binary to PATH on windows

The bootstrap-haskell.ps1 script uses
'[System.EnvironmentVariableTarget]::User' instead of
'[System.EnvironmentVariableTarget]::Machine', so it appears
ghcup env vars and PATH update never make it. Do these manually
for now.

* Set CABAL_DIR and make sure config is adjusted

The config adjustment usually includes adding msys2 directories,
so cabal can find `pkg-config` and libraries, e.g.:

+ C: \ghcup\msys64\mingw64\bin
+ extra-include-dirs: C:\ghcup\msys64\mingw64\include
+ extra-lib-dirs: C:\ghcup\msys64\mingw64\lib
- extra-prog-path: C:\cabal\bin
+ extra-prog-path: C:\ghcup\bin,

* Expose cabal dir to PATH as well

* Use Set-SystemVariable

* Fix tests

* Use hardcoded cabal dir

* Fix bootstrap-haskell

* Move test after installation

* Print ghcup installation message

* Don't adjust cabal.config (to include mingw paths)

This may break setups.
2021-12-10 11:23:44 +03:00

61 lines
2.3 KiB
PowerShell

Describe "Haskell" {
$chocoPackagesPath = Join-Path $env:ChocolateyInstall "lib"
[array]$ghcVersionList = Get-ChildItem -Path $chocoPackagesPath -Filter "ghc.*" | ForEach-Object { $_.Name.TrimStart("ghc.") }
$ghcCount = $ghcVersionList.Count
$defaultGhcVersion = $ghcVersionList | Sort-Object {[Version]$_} | Select-Object -Last 1
$ghcDefaultCases = @{
defaultGhcVersion = $defaultGhcVersion
defaultGhcShortVersion = ([version]$defaultGhcVersion).ToString(3)
}
$ghcTestCases = $ghcVersionList | ForEach-Object {
$ghcVersion = $_
$ghcShortVersion = ([version]$ghcVersion).ToString(3)
$binGhcPath = Join-Path $chocoPackagesPath "ghc.$ghcVersion\tools\ghc-$ghcShortVersion\bin\ghc.exe"
# The most recent GHC versions installation directory is $env:ChocolateyToolsLocation instead of $env:ChocolateyInstall\lib
if (-not (Test-Path $binGhcPath))
{
$binGhcPath = Join-Path $env:ChocolateyToolsLocation "ghc-$ghcShortVersion\bin\ghc.exe"
}
@{
ghcVersion = $ghcVersion
ghcShortVersion = $ghcShortVersion
binGhcPath = $binGhcPath
}
}
$ghcupEnvExists = @(
@{envVar = "GHCUP_INSTALL_BASE_PREFIX"}
@{envVar = "GHCUP_MSYS2"}
)
It "<envVar> environment variable exists" -TestCases $ghcupEnvExists {
Test-Path env:\$envVar
}
It "Accurate 3 versions of GHC are installed" -TestCases @{ghcCount = $ghcCount} {
$ghcCount | Should -BeExactly 3
}
It "GHC <ghcVersion> is installed" -TestCases $ghcTestCases {
"$binGhcPath --version" | Should -MatchCommandOutput $ghcShortVersion
}
It "GHC <defaultGhcVersion> is the default version and should be the latest installed" -TestCases $ghcDefaultCases {
"ghc --version" | Should -MatchCommandOutput $defaultGhcShortVersion
}
It "Cabal is installed" {
"cabal --version" | Should -ReturnZeroExitCode
}
It "cabal config was modified and exists" {
$env:CABAL_DIR | Should -Exist
"cabal user-config diff" | Should -ReturnZeroExitCode
}
It "ghcup is installed" {
"ghcup --version" | Should -ReturnZeroExitCode
}
}