Skip to content

Commit 773ec86

Browse files
committed
Fix wrapper tests by copying to temporary directory
1 parent cf05aa9 commit 773ec86

File tree

6 files changed

+39
-8
lines changed

6 files changed

+39
-8
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ stack*.yaml.lock
2020
shake.yaml.lock
2121

2222
# ignore hie.yaml's for testdata
23-
test/**/*.yaml
23+
test/testdata/**/hie.yaml
2424

2525
# metadata files on macOS
2626
.DS_Store

haskell-language-server.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ common hls-test-utils
217217
, lsp-test
218218
, stm
219219
, tasty-hunit
220+
, temporary
220221
, text
221222
, transformers
222223
, unordered-containers

test/utils/Test/Hls/Util.hs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Test.Hls.Util
1515
, setupBuildToolFiles
1616
, withFileLogging
1717
, findExe
18+
, withCurrentDirectoryInTmp
1819
-- , makeRequest
1920
-- , runIGM
2021
-- , runIGM'
@@ -46,6 +47,7 @@ import System.Directory
4647
import System.Environment
4748
import System.FilePath
4849
import qualified System.Log.Logger as L
50+
import System.IO.Temp
4951
-- import Test.Hspec
5052
import Test.Hspec.Runner
5153
import Test.Hspec.Core.Formatters
@@ -332,6 +334,33 @@ findExeRecursive exe dir = do
332334
findExe :: String -> IO FilePath
333335
findExe name = do
334336
fp <- fmap fromJust $ runMaybeT $
335-
MaybeT (findExecutable name) <|>
337+
MaybeT (findExecutable name) <|>
336338
MaybeT (findExeRecursive name "dist-newstyle")
337339
makeAbsolute fp
340+
341+
-- | Like 'withCurrentDirectory', but will copy the directory over to the system
342+
-- temporary directory first to avoid haskell-language-server's source tree from
343+
-- interfering with the cradle
344+
withCurrentDirectoryInTmp :: FilePath -> IO a -> IO a
345+
withCurrentDirectoryInTmp dir f =
346+
withTempCopy dir $ \newDir ->
347+
withCurrentDirectory newDir f
348+
349+
withTempCopy :: FilePath -> (FilePath -> IO a) -> IO a
350+
withTempCopy srcDir f = do
351+
withSystemTempDirectory "hls-test" $ \newDir -> do
352+
copyDir srcDir newDir
353+
f newDir
354+
355+
copyDir :: FilePath -> FilePath -> IO ()
356+
copyDir src dst = do
357+
cnts <- listDirectory src
358+
forM_ cnts $ \file -> do
359+
unless (file `elem` ignored) $ do
360+
let srcFp = src </> file
361+
dstFp = dst </> file
362+
isDir <- doesDirectoryExist srcFp
363+
if isDir
364+
then createDirectory dstFp >> copyDir srcFp dstFp
365+
else copyFile srcFp dstFp
366+
where ignored = ["dist", "dist-newstyle", ".stack-work"]

test/wrapper/Main.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import Data.Char
33
import Test.Hls.Util
44
import Test.Tasty
55
import Test.Tasty.HUnit
6-
import System.Directory
76
import System.Process
87

98
main :: IO ()
10-
main = defaultMain $
11-
testGroup "haskell-language-server-wrapper" [projectGhcVersionTests]
9+
main = do
10+
flushStackEnvironment
11+
defaultMain $
12+
testGroup "haskell-language-server-wrapper" [projectGhcVersionTests]
1213

13-
--TODO: WAIT ON HIE-BIOS STOP FILES
1414
projectGhcVersionTests :: TestTree
1515
projectGhcVersionTests = testGroup "--project-ghc-version"
1616
[ testCase "stack with ghc 8.10.1" $
@@ -25,10 +25,9 @@ projectGhcVersionTests = testGroup "--project-ghc-version"
2525
testDir :: FilePath -> String -> Assertion
2626
testDir dir expectedVer = do
2727
wrapper <- findExe "haskell-language-server-wrapper"
28-
withCurrentDirectory dir $ do
28+
withCurrentDirectoryInTmp dir $ do
2929
actualVer <- trim <$> readProcess wrapper ["--project-ghc-version"] ""
3030
actualVer @?= expectedVer
3131

3232
trim :: String -> String
3333
trim = dropWhileEnd isSpace
34-
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
resolver: ghc-8.10.1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
resolver: ghc-8.8.3

0 commit comments

Comments
 (0)