diff --git a/test/dispatcher/Main.hs b/test/dispatcher/Main.hs index 1fe3d13b3..348b19e78 100644 --- a/test/dispatcher/Main.hs +++ b/test/dispatcher/Main.hs @@ -43,7 +43,7 @@ import Haskell.Ide.Engine.Plugin.Generic main :: IO () main = do hSetBuffering stderr LineBuffering - setupStackFiles + setupBuildToolFiles config <- getHspecFormattedConfig "dispatcher" withFileLogging "main-dispatcher.log" $ do hspecWith config funcSpec diff --git a/test/functional/Main.hs b/test/functional/Main.hs index 603679786..cfc8a96bc 100644 --- a/test/functional/Main.hs +++ b/test/functional/Main.hs @@ -8,7 +8,7 @@ import TestUtils main :: IO () main = do - setupStackFiles + setupBuildToolFiles -- run a test session to warm up the cache to prevent timeouts in other tests putStrLn "Warming up HIE cache..." runSessionWithConfig (defaultConfig { messageTimeout = 120 }) hieCommand fullCaps "test/testdata" $ diff --git a/test/plugin-dispatcher/Main.hs b/test/plugin-dispatcher/Main.hs index 6c8fc88b0..d6a125ee0 100644 --- a/test/plugin-dispatcher/Main.hs +++ b/test/plugin-dispatcher/Main.hs @@ -19,7 +19,7 @@ import Test.Hspec.Runner main :: IO () main = do - setupStackFiles + setupBuildToolFiles config <- getHspecFormattedConfig "plugin-dispatcher" withFileLogging "plugin-dispatcher.log" $ hspecWith config newPluginSpec diff --git a/test/unit/Main.hs b/test/unit/Main.hs index d6f9c3880..a6e96715e 100644 --- a/test/unit/Main.hs +++ b/test/unit/Main.hs @@ -8,7 +8,7 @@ import qualified Spec main :: IO () main = do - setupStackFiles + setupBuildToolFiles config <- getHspecFormattedConfig "unit" withFileLogging "main.log" $ hspecWith config $ Spec.spec diff --git a/test/utils/TestUtils.hs b/test/utils/TestUtils.hs index 75b7cf67a..e0ed044d9 100644 --- a/test/utils/TestUtils.hs +++ b/test/utils/TestUtils.hs @@ -2,7 +2,7 @@ module TestUtils ( withFileLogging - , setupStackFiles + , setupBuildToolFiles , testCommand , runSingle , runSingleReq @@ -91,14 +91,30 @@ withFileLogging logFile f = do -- --------------------------------------------------------------------- -setupStackFiles :: IO () -setupStackFiles = +-- If an executable @stack@ is present on the system then setup stack files, +-- otherwise specify a direct cradle with -isrc +setupBuildToolFiles :: IO () +setupBuildToolFiles = do + stack <- findExecutable "stack" + let s = case stack of + Nothing -> setupDirectFilesIn + Just _ -> setupStackFilesIn forM_ files $ \f -> do - resolver <- readResolver - writeFile (f ++ "stack.yaml") $ stackFileContents resolver - writeFile (f ++ "hie.yaml") hieYamlCradleStackContents + s f + -- Cleanup stack directory in case the presence of stack has changed since + -- the last run removePathForcibly (f ++ ".stack-work") +setupStackFilesIn :: FilePath -> IO () +setupStackFilesIn f = do + resolver <- readResolver + writeFile (f ++ "stack.yaml") $ stackFileContents resolver + writeFile (f ++ "hie.yaml") hieYamlCradleStackContents + +setupDirectFilesIn :: FilePath -> IO () +setupDirectFilesIn f = + writeFile (f ++ "hie.yaml") hieYamlCradleDirectContents + -- --------------------------------------------------------------------- files :: [FilePath] @@ -197,14 +213,23 @@ readResolverFrom yamlPath = do hieYamlCradleStackContents :: String hieYamlCradleStackContents = unlines - [ "# WARNING: THIS FILE IS AUTOGENERATED IN test/Main.hs. IT WILL BE OVERWRITTEN ON EVERY TEST RUN" + [ "# WARNING: THIS FILE IS AUTOGENERATED IN test/utils/TestUtils.hs. IT WILL BE OVERWRITTEN ON EVERY TEST RUN" , "cradle:" , " stack:" ] +hieYamlCradleDirectContents :: String +hieYamlCradleDirectContents = unlines + [ "# WARNING: THIS FILE IS AUTOGENERATED IN test/utils/TestUtils.hs. IT WILL BE OVERWRITTEN ON EVERY TEST RUN" + , "cradle:" + , " direct:" + , " arguments:" + , " - -isrc" + ] + stackFileContents :: String -> String stackFileContents resolver = unlines - [ "# WARNING: THIS FILE IS AUTOGENERATED IN test/Main.hs. IT WILL BE OVERWRITTEN ON EVERY TEST RUN" + [ "# WARNING: THIS FILE IS AUTOGENERATED IN test/utils/TestUtils. IT WILL BE OVERWRITTEN ON EVERY TEST RUN" , "resolver: " ++ resolver , "packages:" , "- '.'"