From 8769d5ef623ca6261c225eebbbfc19f4ef070e2d Mon Sep 17 00:00:00 2001 From: Akshit Kumar Date: Mon, 3 Jun 2024 01:46:42 +0530 Subject: [PATCH 1/4] Refactor test env setup to use separate dirs for every test. --- hls-test-utils/src/Test/Hls.hs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 15f41e3b2b..8ad2fa56e0 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -121,7 +121,6 @@ import qualified Language.LSP.Server as LSP import Language.LSP.Test import Prelude hiding (log) import System.Directory (canonicalizePath, - createDirectoryIfMissing, getCurrentDirectory, getTemporaryDirectory, makeAbsolute, @@ -130,6 +129,7 @@ import System.Environment (lookupEnv, setEnv) import System.FilePath import System.IO.Extra (newTempDirWithin) import System.IO.Unsafe (unsafePerformIO) +import System.IO.Temp (createTempDirectory) import System.Process.Extra (createPipe) import System.Time.Extra import qualified Test.Hls.FileSystem as FS @@ -556,9 +556,8 @@ setupTestEnvironment :: IO FilePath setupTestEnvironment = do tmpDirRoot <- getTemporaryDirectory let testRoot = tmpDirRoot "hls-test-root" - testCacheDir = testRoot ".cache" - createDirectoryIfMissing True testCacheDir - setEnv "XDG_CACHE_HOME" testCacheDir + tempCacheDir <- createTempDirectory testRoot ".cache" + setEnv "XDG_CACHE_HOME" tempCacheDir pure testRoot goldenWithHaskellDocFormatter From acae9d97f749fdaaefe5db3561c17bd8edf12bfd Mon Sep 17 00:00:00 2001 From: Akshit Kumar Date: Mon, 3 Jun 2024 20:47:42 +0530 Subject: [PATCH 2/4] ran stylish-haskell on Hls.hs --- hls-test-utils/src/Test/Hls.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 8ad2fa56e0..48959a3813 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -128,8 +128,8 @@ import System.Directory (canonicalizePath, import System.Environment (lookupEnv, setEnv) import System.FilePath import System.IO.Extra (newTempDirWithin) -import System.IO.Unsafe (unsafePerformIO) import System.IO.Temp (createTempDirectory) +import System.IO.Unsafe (unsafePerformIO) import System.Process.Extra (createPipe) import System.Time.Extra import qualified Test.Hls.FileSystem as FS From 571261059c1b3ec22d57dec65ec8d3bf81ae5b15 Mon Sep 17 00:00:00 2001 From: Akshit Kumar Date: Tue, 4 Jun 2024 01:36:17 +0530 Subject: [PATCH 3/4] create hls-test-root directory if missing --- hls-test-utils/src/Test/Hls.hs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hls-test-utils/src/Test/Hls.hs b/hls-test-utils/src/Test/Hls.hs index 48959a3813..5bc8b98ef2 100644 --- a/hls-test-utils/src/Test/Hls.hs +++ b/hls-test-utils/src/Test/Hls.hs @@ -121,6 +121,7 @@ import qualified Language.LSP.Server as LSP import Language.LSP.Test import Prelude hiding (log) import System.Directory (canonicalizePath, + createDirectoryIfMissing, getCurrentDirectory, getTemporaryDirectory, makeAbsolute, @@ -556,6 +557,7 @@ setupTestEnvironment :: IO FilePath setupTestEnvironment = do tmpDirRoot <- getTemporaryDirectory let testRoot = tmpDirRoot "hls-test-root" + createDirectoryIfMissing True testRoot tempCacheDir <- createTempDirectory testRoot ".cache" setEnv "XDG_CACHE_HOME" tempCacheDir pure testRoot From 6594a287f06fc802e50e6c02228bb08cda203295 Mon Sep 17 00:00:00 2001 From: komikat Date: Fri, 5 Jul 2024 18:34:39 +0530 Subject: [PATCH 4/4] temporary fix to breaking testcase after $TEMPDIR cleanup update --- ghcide/test/exe/FindDefinitionAndHoverTests.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ghcide/test/exe/FindDefinitionAndHoverTests.hs b/ghcide/test/exe/FindDefinitionAndHoverTests.hs index 63d8dd7ab7..e60d6e8cfc 100644 --- a/ghcide/test/exe/FindDefinitionAndHoverTests.hs +++ b/ghcide/test/exe/FindDefinitionAndHoverTests.hs @@ -159,7 +159,7 @@ tests = let holeL65 = Position 65 8 ; hleInfo2 = [ExpectHoverText ["_ :: a -> Maybe a"]] cccL17 = Position 17 16 ; docLink = [ExpectHoverTextRegex "\\*Defined in 'GHC.Types'\\* \\*\\(ghc-prim-[0-9.]+\\)\\*\n\n"] imported = Position 56 13 ; importedSig = getDocUri "Foo.hs" >>= \foo -> return [ExpectHoverText ["foo", "Foo", "Haddock"], mkL foo 5 0 5 3] - reexported = Position 55 14 ; reexportedSig = getDocUri "Bar.hs" >>= \bar -> return [ExpectHoverText ["Bar", "Bar", "Haddock"], if ghcVersion >= GHC94 && ghcVersion < GHC910 then mkL bar 3 5 3 8 else mkL bar 3 0 3 14] + reexported = Position 55 14 ; reexportedSig = getDocUri "Bar.hs" >>= \bar -> return [ExpectHoverText ["Bar", "Bar", "Haddock"], mkL bar 3 0 3 14] -- thLocL57 = Position 59 10 ; thLoc = [ExpectHoverText ["Identity"]] cmtL68 = Position 67 0 ; lackOfdEq = [ExpectHoverExcludeText ["$dEq"]] import310 = Position 3 10; pkgTxt = [ExpectHoverText ["Data.Text\n\ntext-"]] @@ -211,6 +211,7 @@ tests = let -- Flaky on Windows: https://github.com/haskell/haskell-language-server/issues/2997 testM no yes reexported reexportedSig "Imported symbol (reexported)" else + -- Flaky after $TEMPDIR cleanup: https://github.com/haskell/haskell-language-server/issues/4348 testM yes yes reexported reexportedSig "Imported symbol (reexported)" , test no yes thLocL57 thLoc "TH Splice Hover" , test yes yes import310 pkgTxt "show package name and its version"