Skip to content

Commit 6ec5617

Browse files
committed
Fix flaky test
1 parent db3dd7d commit 6ec5617

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

ghcide/src/Development/IDE/Core/FileExists.hs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,6 @@ fromChange FcChanged = Nothing
131131
-------------------------------------------------------------------------------------
132132

133133
-- | Returns True if the file exists
134-
-- Note that a file is not considered to exist unless it is saved to disk.
135-
-- In particular, VFS existence is not enough.
136-
-- Consider the following example:
137-
-- 1. The file @A.hs@ containing the line @import B@ is added to the files of interest
138-
-- Since @B.hs@ is neither open nor exists, GetLocatedImports finds Nothing
139-
-- 2. The editor creates a new buffer @B.hs@
140-
-- Unless the editor also sends a @DidChangeWatchedFile@ event, ghcide will not pick it up
141-
-- Most editors, e.g. VSCode, only send the event when the file is saved to disk.
142134
getFileExists :: NormalizedFilePath -> Action Bool
143135
getFileExists fp = use_ GetFileExists fp
144136

ghcide/test/exe/Main.hs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ import System.Process.Extra (CreateProcess (cwd),
9595
import Test.QuickCheck
9696
-- import Test.QuickCheck.Instances ()
9797
import Control.Concurrent.Async
98-
import Control.Lens (to, (^.))
98+
import Control.Lens (to, (^.), (.~))
9999
import Control.Monad.Extra (whenJust)
100100
import Data.Function ((&))
101101
import Data.IORef
@@ -133,6 +133,7 @@ import Test.Tasty.Ingredients.Rerun
133133
import Test.Tasty.QuickCheck
134134
import Text.Printf (printf)
135135
import Text.Regex.TDFA ((=~))
136+
import Language.LSP.Types.Lens (workspace, didChangeWatchedFiles)
136137

137138
data Log
138139
= LogGhcIde Ghcide.Log
@@ -421,9 +422,8 @@ diagnosticTests = testGroup "diagnostics"
421422
let contentA = T.unlines [ "module ModuleA where" ]
422423
_ <- createDoc "ModuleA.hs" "haskell" contentA
423424
expectDiagnostics [("ModuleB.hs", [])]
424-
, ignoreTestBecause "Flaky #2831" $ testSessionWait "add missing module (non workspace)" $ do
425-
-- need to canonicalize in Mac Os
426-
tmpDir <- liftIO $ canonicalizePath =<< getTemporaryDirectory
425+
, testCase "add missing module (non workspace)" $
426+
withTempDir $ \tmpDir -> runInDir'' lspTestCapsNoFileWatches tmpDir "." "." [] $ do
427427
let contentB = T.unlines
428428
[ "module ModuleB where"
429429
, "import ModuleA ()"
@@ -6306,7 +6306,18 @@ withLongTimeout = bracket_ (setEnv "LSP_TIMEOUT" "120" True) (unsetEnv "LSP_TIME
63066306

63076307
-- | Takes a directory as well as relative paths to where we should launch the executable as well as the session root.
63086308
runInDir' :: FilePath -> FilePath -> FilePath -> [String] -> Session a -> IO a
6309-
runInDir' dir startExeIn startSessionIn extraOptions s = do
6309+
runInDir' = runInDir'' lspTestCaps
6310+
6311+
runInDir''
6312+
:: ClientCapabilities
6313+
-> FilePath
6314+
-> FilePath
6315+
-> FilePath
6316+
-> [String]
6317+
-> Session b
6318+
-> IO b
6319+
runInDir'' lspCaps dir startExeIn startSessionIn extraOptions s = do
6320+
63106321
ghcideExe <- locateGhcideExecutable
63116322
let startDir = dir </> startExeIn
63126323
let projDir = dir </> startSessionIn
@@ -6326,10 +6337,11 @@ runInDir' dir startExeIn startSessionIn extraOptions s = do
63266337
-- Only sets HOME if it wasn't already set.
63276338
setEnv "HOME" "/homeless-shelter" False
63286339
conf <- getConfigFromEnv
6329-
runSessionWithConfig conf cmd lspTestCaps projDir $ do
6340+
runSessionWithConfig conf cmd lspCaps projDir $ do
63306341
configureCheckProject False
63316342
s
63326343

6344+
63336345
getConfigFromEnv :: IO SessionConfig
63346346
getConfigFromEnv = do
63356347
logColor <- fromMaybe True <$> checkEnv "LSP_TEST_LOG_COLOR"
@@ -6347,6 +6359,9 @@ getConfigFromEnv = do
63476359
lspTestCaps :: ClientCapabilities
63486360
lspTestCaps = fullCaps { _window = Just $ WindowClientCapabilities (Just True) Nothing Nothing }
63496361

6362+
lspTestCapsNoFileWatches :: ClientCapabilities
6363+
lspTestCapsNoFileWatches = lspTestCaps & workspace . Lens._Just . didChangeWatchedFiles .~ Nothing
6364+
63506365
openTestDataDoc :: FilePath -> Session TextDocumentIdentifier
63516366
openTestDataDoc path = do
63526367
source <- liftIO $ readFileUtf8 $ "test/data" </> path

0 commit comments

Comments
 (0)