Skip to content
Snippets Groups Projects
Commit d3e589d4 authored by Javier Sagredo's avatar Javier Sagredo
Browse files

Enable symlink creation on tests on Windows

parent 39b69247
No related branches found
No related tags found
No related merge requests found
......@@ -54,6 +54,7 @@ import Control.Concurrent.Async (withAsync)
import qualified Data.Aeson as JSON
import qualified Data.ByteString.Lazy as BSL
import Control.Monad (unless, when, void, forM_, liftM2, liftM4)
import Control.Monad.Catch ( bracket_ )
import Control.Monad.Trans.Reader (withReaderT, runReaderT)
import Control.Monad.IO.Class (MonadIO (..))
import qualified Crypto.Hash.SHA256 as SHA256
......@@ -70,10 +71,9 @@ import Control.Retry (exponentialBackoff, limitRetriesByCumulativeDelay)
import Network.Wait (waitTcpVerbose)
import System.Environment
import System.Process
import System.IO
#ifndef mingw32_HOST_OS
import Control.Monad.Catch ( bracket_ )
import System.Posix.Files ( createSymbolicLink )
import System.Posix.Resource
#endif
......@@ -1123,19 +1123,20 @@ withDelay m = do
Just _ -> m
-- | Create a symlink for the duration of the provided action. If the symlink
-- already exists, it is deleted.
withSymlink :: FilePath -> FilePath -> TestM a -> TestM a
withSymlink :: FilePath -> FilePath -> TestM a -> TestM a
#if defined(mingw32_HOST_OS) && !MIN_VERSION_directory(1,3,1)
withSymlink _oldpath _newpath _act =
withSymlink _oldpath _newpath _act =
error "Test.Cabal.Prelude.withSymlink: does not work on Windows with directory <1.3.1!"
#else
withSymlink oldpath newpath0 act = do
liftIO $ hPutStrLn stderr $ "Symlinking " <> oldpath <> " <== " <> newpath0
env <- getTestEnv
let newpath = testCurrentDir env </> newpath0
symlinkExists <- liftIO $ doesFileExist newpath
when symlinkExists $ liftIO $ removeFile newpath
when symlinkExists $ liftIO $ removeFile newpath
bracket_ (liftIO $ createSymbolicLink oldpath newpath)
bracket_ (liftIO $ createFileLink oldpath newpath)
(liftIO $ pure ()) act
#endif
writeSourceFile :: FilePath -> String -> TestM ()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment