Skip to content

Commit

Permalink
Merge pull request #10319 from haskell/mergify/bp/3.14/pr-10236
Browse files Browse the repository at this point in the history
Fix Windows tests depending on scripts (backport #10236)
  • Loading branch information
mergify[bot] authored Oct 2, 2024
2 parents 1eaa6af + 7d2a6b5 commit 57cbb08
Show file tree
Hide file tree
Showing 43 changed files with 228 additions and 36 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ github.sha }}
restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-

- name: Work around git problem https://bugs.launchpad.net/ubuntu/+source/git/+bug/1993586 (cabal PR #8546)
- name: "Work around git problem https://bugs.launchpad.net/ubuntu/+source/git/+bug/1993586 (cabal PR #8546)"
run: git config --global protocol.file.allow always

# The tool is not essential to the rest of the test suite. If
Expand All @@ -146,10 +146,15 @@ jobs:
run: cabal install --ignore-project hackage-repo-tool

# Needed by cabal-testsuite/PackageTests/Configure/setup.test.hs
- name: Install Autotools
- name: "MAC: Install Autotools"
if: runner.os == 'macOS'
run: brew install automake

# Needed by cabal-testsuite/PackageTests/Configure/setup.test.hs
- name: "WIN: Install Autotools"
if: runner.os == 'Windows'
run: /usr/bin/pacman --noconfirm -S autotools

- name: Set validate inputs
run: |
FLAGS="${{ env.COMMON_FLAGS }}"
Expand Down
25 changes: 21 additions & 4 deletions cabal-testsuite/PackageTests/Configure/cabal.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,26 @@ import Test.Cabal.Prelude
import Control.Monad.IO.Class
import Data.Maybe
import System.Directory
import System.Environment
import Data.List (isSuffixOf)

-- Test for 'build-type: Configure' example from the setup manual.
main = cabalTest $ do
hasAutoreconf <- liftIO $ fmap isJust $ findExecutable "autoreconf"
skipUnless "no autoreconf" hasAutoreconf
_ <- shell "autoreconf" ["-i"]
cabal "v2-build" []
if isWindows
then do
(mCI, mSh) <- liftIO $ (,) <$> lookupEnv "CI" <*> lookupEnv "SHELL"
case (mCI, mSh) of
(Nothing, Nothing) -> skip "Missing $SHELL"
(Nothing, Just sh) -> do
env <- getTestEnv
void $ shell sh [ "-l", "-c", "cd $(cygpath -m '" <> testTmpDir env <> "') && autoreconf -i"]
cabal "v2-build" []
(Just{}, _) -> do
env <- getTestEnv
void $ shell "C:\\msys64\\usr\\bin\\bash.exe" [ "-l", "-c", "cd $(cygpath -m '" <> testTmpDir env <> "') && autoreconf -i"]
cabal "v2-build" []
else do
hasAutoreconf <- liftIO $ fmap isJust $ findExecutable "autoreconf"
skipUnless "no autoreconf" hasAutoreconf
_ <- shell "autoreconf" ["-i"]
cabal "v2-build" []
26 changes: 21 additions & 5 deletions cabal-testsuite/PackageTests/Configure/setup.test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,25 @@ import Test.Cabal.Prelude
import Control.Monad.IO.Class
import Data.Maybe
import System.Directory
import System.Environment

-- Test for 'build-type: Configure' example from the setup manual.
main = setupTest $ do
hasAutoreconf <- liftIO $ fmap isJust $ findExecutable "autoreconf"
skipUnless "no autoreconf" hasAutoreconf
_ <- shell "autoreconf" ["-i"]
setup_build []
main = setupTest $
if isWindows
then do
(mCI, mSh) <- liftIO $ (,) <$> lookupEnv "CI" <*> lookupEnv "SHELL"
case (mCI, mSh) of
(Nothing, Nothing) -> skip "Missing $SHELL"
(Nothing, Just sh) -> do
env <- getTestEnv
void $ shell sh [ "-l", "-c", "cd $(cygpath -m '" <> testTmpDir env <> "') && autoreconf -i"]
setup_build []
(Just{}, _) -> do
env <- getTestEnv
void $ shell "C:\\msys64\\usr\\bin\\bash.exe" [ "-l", "-c", "cd $(cygpath -m '" <> testTmpDir env <> "') && autoreconf -i"]
setup_build []
else do
hasAutoreconf <- liftIO $ fmap isJust $ findExecutable "autoreconf"
skipUnless "no autoreconf" hasAutoreconf
_ <- shell "autoreconf" ["-i"]
setup_build []
6 changes: 4 additions & 2 deletions cabal-testsuite/PackageTests/GHCJS/BuildRunner/cabal.test.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Test.Cabal.Prelude

main = do
cabalTest . expectBrokenIfWindows 10179 . recordMode DoNotRecord $ do
cabalTest . recordMode DoNotRecord $ do
cwd <- fmap testCurrentDir getTestEnv
testInvokedWithBuildRunner cwd "test" []
testInvokedWithBuildRunner cwd "run" ["ghcjs-exe"]
Expand All @@ -14,6 +14,8 @@ testInvokedWithBuildRunner cwd cabalCmd extraArgs = do
[ "--ghcjs"
, "--with-compiler", cwd </> fakeGhcjsPath
]
-- On windows point cabal to the right cc
++ if isWindows then ["--with-gcc", "scripts/cc.bat"] else []
assertOutputContains magicString output
where
fakeGhcjsPath = "scripts/fake-ghcjs.sh"
fakeGhcjsPath = if isWindows then "scripts/fake-ghcjs.exe" else "scripts/fake-ghcjs.sh"
45 changes: 45 additions & 0 deletions cabal-testsuite/PackageTests/GHCJS/BuildRunner/scripts/cc.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@ECHO off

FOR /f "delims=" %%A in ('call ghc.exe --print-libdir') do set "libdir=%%A"
FOR /f "delims=" %%A in ('call ghc.exe --numeric-version') do set "numVersion=%%A"
setlocal EnableDelayedExpansion

call :compareVersions 9.4.1 %numVersion%
if %errorlevel% == 1 (set "cc=gcc.exe") else (set "cc=clang.exe")
CALL !libdir:lib=mingw\bin\!%cc% %*
EXIT /B %ERRORLEVEL%

REM taken from https://stackoverflow.com/questions/15807762/compare-version-numbers-in-batch-file

:compareVersions version1 version2
::
:: Compares two version numbers and returns the result in the ERRORLEVEL
::
:: Returns 1 if version1 > version2
:: 0 if version1 = version2
:: -1 if version1 < version2
::
:: The nodes must be delimited by . or , or -
::
:: Nodes are normally strictly numeric, without a 0 prefix. A letter suffix
:: is treated as a separate node
::
setlocal enableDelayedExpansion
set "v1=%~1"
set "v2=%~2"
:loop
call :parseNode "%v1%" n1 v1
call :parseNode "%v2%" n2 v2
if %n1% gtr %n2% exit /b 1
if %n1% lss %n2% exit /b -1
if not defined v1 if not defined v2 exit /b 0
if not defined v1 exit /b -1
if not defined v2 exit /b 1
goto :loop


:parseNode version nodeVar remainderVar
for /f "tokens=1* delims=." %%A in ("%~1") do (
set "%~2=%%A"
set "%~3=%%B"
)
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "sh.exe"
args = "scripts/fake-ghcjs.sh"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "sh.exe"
args = "scripts/ghcjs-pkg"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc-pkg"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc"
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import Test.Cabal.Prelude
import System.Directory

main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do
main = setupAndCabalTest $ do
when isWindows $ do
sh <- fmap takeDirectory <$> liftIO (findExecutable "sh")
case sh of
Nothing -> skip "no sh"
Just sh' -> do
let sh'' = concatMap (\c -> case c of
'\\' -> "\\\\\\\\"
x -> [x]) sh'
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "ghc.shim", "ghc-pkg.shim"]
env <- getTestEnv
let cwd = testCurrentDir env
ghc_path <- programPathM ghcProgram
r <- withEnv [("WITH_GHC", Just ghc_path)]
. fails $ setup' "configure" ["-w", cwd </> "ghc"]
. fails $ setup' "configure" ["-w", cwd </> if isWindows then "ghc.exe" else "ghc" ]
assertOutputContains "is version 9999999" r
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc-7.10"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc-pkg-ghc-7.10"
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import Test.Cabal.Prelude
import System.Directory

main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do
main = setupAndCabalTest $ do
when isWindows $ do
sh <- fmap takeDirectory <$> liftIO (findExecutable "sh")
case sh of
Nothing -> skip "no sh"
Just sh' -> do
let sh'' = concatMap (\c -> case c of
'\\' -> "\\\\\\\\"
x -> [x]) sh'
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "ghc-7.10.shim", "ghc-pkg-ghc-7.10.shim"]
env <- getTestEnv
let cwd = testCurrentDir env
ghc_path <- programPathM ghcProgram
r <- withEnv [("WITH_GHC", Just ghc_path)]
. fails $ setup' "configure" ["-w", cwd </> "ghc-7.10"]
. fails $ setup' "configure" ["-w", cwd </> if isWindows then "ghc-7.10.exe" else "ghc-7.10"]
assertOutputContains "is version 9999999" r
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc-7.10"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc-pkg-7.10"
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import Test.Cabal.Prelude
import System.Directory

main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do
main = setupAndCabalTest $ do
when isWindows $ do
sh <- fmap takeDirectory <$> liftIO (findExecutable "sh")
case sh of
Nothing -> skip "no sh"
Just sh' -> do
let sh'' = concatMap (\c -> case c of
'\\' -> "\\\\\\\\"
x -> [x]) sh'
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "ghc-7.10.shim", "ghc-pkg-7.10.shim"]
env <- getTestEnv
let cwd = testCurrentDir env
ghc_path <- programPathM ghcProgram
r <- withEnv [("WITH_GHC", Just ghc_path)]
. fails $ setup' "configure" ["-w", cwd </> "ghc-7.10"]
. fails $ setup' "configure" ["-w", cwd </> if isWindows then "ghc-7.10.exe" else "ghc-7.10"]
assertOutputContains "is version 9999999" r
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "bin\ghc-pkg"
Binary file not shown.
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/bin/ghc.shim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc"
18 changes: 15 additions & 3 deletions cabal-testsuite/PackageTests/GhcPkgGuess/Symlink/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import Test.Cabal.Prelude
import System.Directory

main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do
withSymlink "bin/ghc" "ghc" $ do
main = setupAndCabalTest $ do
when isWindows $ do
sh <- fmap takeDirectory <$> liftIO (findExecutable "sh")
case sh of
Nothing -> skip "no sh"
Just sh' -> do
let sh'' = concatMap (\c -> case c of
'\\' -> "\\\\\\\\"
x -> [x]) sh'
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "bin/ghc.shim", "bin/ghc-pkg.shim"]
(if isWindows
then withSymlink "bin/ghc.exe" "ghc.exe" . withSymlink "bin/ghc.shim" "ghc.shim" . withSymlink "bin/ghc" "ghc"
else withSymlink "bin/ghc" "ghc") $ do
env <- getTestEnv
let cwd = testCurrentDir env
ghc_path <- programPathM ghcProgram
r <- withEnv [("WITH_GHC", Just ghc_path)]
. fails $ setup' "configure" ["-w", cwd </> "ghc"]
. fails $ setup' "configure" ["-w", cwd </> if isWindows then "ghc.exe" else "ghc"]
assertOutputContains "is version 9999999" r
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "bin\ghc-pkg-7.10"
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import Test.Cabal.Prelude
import System.Directory

main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do
withSymlink "bin/ghc-7.10" "ghc" $ do
main = setupAndCabalTest $ do
when isWindows $ do
sh <- fmap takeDirectory <$> liftIO (findExecutable "sh")
case sh of
Nothing -> skip "no sh"
Just sh' -> do
let sh'' = concatMap (\c -> case c of
'\\' -> "\\\\\\\\"
x -> [x]) sh'
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "bin/ghc-7.10.shim", "bin/ghc-pkg-7.10.shim"]
(if isWindows
then withSymlink "bin/ghc-7.10.exe" "ghc.exe" . withSymlink "bin/ghc-7.10.shim" "ghc.shim" . withSymlink "bin/ghc-7.10" "ghc"
else withSymlink "bin/ghc-7.10" "ghc") $ do
env <- getTestEnv
let cwd = testCurrentDir env
ghc_path <- programPathM ghcProgram
r <- withEnv [("WITH_GHC", Just ghc_path)]
. fails $ setup' "configure" ["-w", cwd </> "ghc"]
. fails $ setup' "configure" ["-w", cwd </> if isWindows then "ghc.exe" else "ghc"]
assertOutputContains "is version 9999999" r
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "ghc"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "bin\ghc-pkg-ghc-7.10"
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import Test.Cabal.Prelude
import System.Directory

main = setupAndCabalTest $ expectBrokenIfWindows 10179 $ do
withSymlink "bin/ghc-7.10" "ghc" $ do
main = setupAndCabalTest $ do
when isWindows $ do
sh <- fmap takeDirectory <$> liftIO (findExecutable "sh")
case sh of
Nothing -> skip "no sh"
Just sh' -> do
let sh'' = concatMap (\c -> case c of
'\\' -> "\\\\\\\\"
x -> [x]) sh'
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "bin/ghc-7.10.shim", "bin/ghc-pkg-ghc-7.10.shim"]
(if isWindows
then withSymlink "bin/ghc-7.10.exe" "ghc.exe" . withSymlink "bin/ghc-7.10.shim" "ghc.shim" . withSymlink "bin/ghc-7.10" "ghc"
else withSymlink "bin/ghc-7.10" "ghc") $ do
env <- getTestEnv
let cwd = testCurrentDir env
ghc_path <- programPathM ghcProgram
r <- withEnv [("WITH_GHC", Just ghc_path)]
. fails $ setup' "configure" ["-w", cwd </> "ghc"]
. fails $ setup' "configure" ["-w", cwd </> if isWindows then "ghc.exe" else "ghc"]
assertOutputContains "is version 9999999" r
Binary file not shown.
2 changes: 2 additions & 0 deletions cabal-testsuite/PackageTests/PkgConfigParse/pkg-config.shim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
path = "FINDSH\sh.exe"
args = "pkg-config"
12 changes: 11 additions & 1 deletion cabal-testsuite/PackageTests/PkgConfigParse/setup.test.hs
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import System.Directory
import Test.Cabal.Prelude

-- Test that invalid unicode in pkg-config output doesn't trip up cabal very much
main = cabalTest $ expectBrokenIfWindows 10179 $ do
main = cabalTest $ do
when isWindows $ do
sh <- fmap takeDirectory <$> liftIO (findExecutable "sh")
case sh of
Nothing -> skip "no sh"
Just sh' -> do
let sh'' = concatMap (\c -> case c of
'\\' -> "\\\\\\\\"
x -> [x]) sh'
void $ shell "sed" [ "-i", "-e", "s/FINDSH/" <> sh'' <> "/g", "pkg-config.shim"]
cdir <- testCurrentDir `fmap` getTestEnv
res <- cabal' "v2-build" ["--extra-prog-path="++cdir, "-v2"]
assertOutputContains "Some pkg-config packages have names containing invalid unicode: or" res
Loading

0 comments on commit 57cbb08

Please sign in to comment.