@@ -52,11 +52,9 @@ import Development.IDE.Test (Cursor,
5252 standardizeQuotes ,
5353 getInterfaceFilesDir
5454 waitForAction ,
55- garbageCollectDirtyKeys ,
5655 getStoredKeys ,
5756 waitForTypecheck ,
58- getFilesOfInterest ,
59- waitForBuildQueue )
57+ getFilesOfInterest , waitForGC )
6058import Development.IDE.Test.Runfiles
6159import qualified Development.IDE.Types.Diagnostics as Diagnostics
6260import Development.IDE.Types.Location
@@ -5841,83 +5839,75 @@ unitTests = do
58415839
58425840garbageCollectionTests :: TestTree
58435841garbageCollectionTests = testGroup " garbage collection"
5844- [ testGroup " dirty keys" (sharedGCtests $ garbageCollectDirtyKeys CheckOnSaveAndClose )
5845- ]
5846- where
5847- sharedGCtests gc =
5842+ [ testGroup " dirty keys"
58485843 [ testSession' " are collected" $ \ dir -> do
58495844 liftIO $ writeFile (dir </> " hie.yaml" ) " cradle: {direct: {arguments: [A]}}"
5850- void $ generateGarbage " A" dir
5851- garbage <- gc 0
5845+ doc <- generateGarbage " A" dir
5846+ closeDoc doc
5847+ garbage <- waitForGC
58525848 liftIO $ assertBool " no garbage was found" $ not $ null garbage
58535849
58545850 , testSession' " are deleted from the state" $ \ dir -> do
58555851 liftIO $ writeFile (dir </> " hie.yaml" ) " cradle: {direct: {arguments: [A]}}"
5856- void $ generateGarbage " A" dir
5852+ docA <- generateGarbage " A" dir
58575853 keys0 <- getStoredKeys
5858- garbage <- gc 0
5854+ closeDoc docA
5855+ garbage <- waitForGC
58595856 liftIO $ assertBool " something is wrong with this test - no garbage found" $ not $ null garbage
58605857 keys1 <- getStoredKeys
58615858 liftIO $ assertBool " keys were not deleted from the state" (length keys1 < length keys0)
58625859
58635860 , testSession' " are not regenerated unless needed" $ \ dir -> do
58645861 liftIO $ writeFile (dir </> " hie.yaml" ) " cradle: {direct: {arguments: [A.hs, B.hs]}}"
5865- void $ generateGarbage " A" dir
5862+ docA <- generateGarbage " A" dir
5863+ _docB <- generateGarbage " B" dir
58665864
5867- reopenB <- generateGarbage " B" dir
58685865 -- garbage collect A keys
58695866 keysBeforeGC <- getStoredKeys
5870- garbage <- gc 2
5867+ closeDoc docA
5868+ garbage <- waitForGC
58715869 liftIO $ assertBool " something is wrong with this test - no garbage found" $ not $ null garbage
58725870 keysAfterGC <- getStoredKeys
5873- liftIO $ assertBool " something is wrong with this test - keys were not deleted from the state" (length keysAfterGC < length keysBeforeGC)
5874- ff <- getFilesOfInterest
5875- liftIO $ assertBool (" something is wrong with this test - files of interest is " <> show ff) (null ff)
5876-
5877- -- typecheck B again
5878- doc <- reopenB
5879- void $ waitForTypecheck doc
5871+ liftIO $ assertBool " something is wrong with this test - keys were not deleted from the state"
5872+ (length keysAfterGC < length keysBeforeGC)
58805873
5881- -- review the keys in store now to validate that A keys have not been regenerated
5882- keysB' <- getStoredKeys
5874+ -- re-typecheck B and check that the keys for A have not materialized back
5875+ _docB <- generateGarbage " B" dir
5876+ keysB <- getStoredKeys
58835877 let regeneratedKeys = Set. filter (not . isExpected) $
5884- Set. intersection (Set. fromList garbage) (Set. fromList keysB' )
5878+ Set. intersection (Set. fromList garbage) (Set. fromList keysB)
58855879 liftIO $ regeneratedKeys @?= mempty
58865880
58875881 , testSession' " regenerate successfully" $ \ dir -> do
58885882 liftIO $ writeFile (dir </> " hie.yaml" ) " cradle: {direct: {arguments: [A]}}"
5889- reopenA <- generateGarbage " A" dir
5890- garbage <- gc 0
5883+ docA <- generateGarbage " A" dir
5884+ closeDoc docA
5885+ garbage <- waitForGC
58915886 liftIO $ assertBool " no garbage was found" $ not $ null garbage
58925887 let edit = T. unlines
58935888 [ " module A where"
58945889 , " a :: Bool"
58955890 , " a = ()"
58965891 ]
5897- doc <- reopenA
5892+ doc <- generateGarbage " A " dir
58985893 changeDoc doc [TextDocumentContentChangeEvent Nothing Nothing edit]
58995894 builds <- waitForTypecheck doc
59005895 liftIO $ assertBool " it still builds" builds
59015896 expectCurrentDiagnostics doc [(DsError , (2 ,4 ), " Couldn't match expected type" )]
59025897 ]
5898+ ]
5899+ where
5900+ isExpected k = any (`T.isPrefixOf` k) [" GhcSessionIO" ]
59035901
5904- isExpected k = any (`isPrefixOf` k) [" GhcSessionIO" ]
5905-
5906- generateGarbage :: String -> FilePath -> Session (Session TextDocumentIdentifier )
5902+ generateGarbage :: String -> FilePath -> Session TextDocumentIdentifier
59075903 generateGarbage modName dir = do
59085904 let fp = modName <> " .hs"
59095905 body = printf " module %s where" modName
59105906 doc <- createDoc fp " haskell" (T. pack body)
59115907 liftIO $ writeFile (dir </> fp) body
59125908 builds <- waitForTypecheck doc
59135909 liftIO $ assertBool " something is wrong with this test" builds
5914- closeDoc doc
5915- waitForBuildQueue
5916- -- dirty the garbage
5917- sendNotification SWorkspaceDidChangeWatchedFiles $ DidChangeWatchedFilesParams $
5918- List [FileEvent (filePathToUri $ dir </> modName <> " .hs" ) FcChanged ]
5919-
5920- return $ openDoc (modName <> " .hs" ) " haskell"
5910+ return doc
59215911
59225912findResolution_us :: Int -> IO Int
59235913findResolution_us delay_us | delay_us >= 1000000 = error " Unable to compute timestamp resolution"
0 commit comments