Skip to content

Commit 54ec50a

Browse files
committed
fix hls-graph test
1 parent 36e4646 commit 54ec50a

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

hls-graph/src/Development/IDE/Graph/Internal/Database.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ newDatabase :: (String -> IO ()) -> DBQue -> Dynamic -> TheRules -> IO Database
5555
newDatabase dataBaseLogger databaseQueue databaseExtra databaseRules = do
5656
databaseStep <- newTVarIO $ Step 0
5757
databaseThreads <- newTVarIO []
58-
databaseValuesLock <- newTVarIO False
58+
databaseValuesLock <- newTVarIO True
5959
databaseValues <- atomically SMap.new
6060
databaseRuntimeRevDep <- atomically SMap.new
6161
pure Database{..}

hls-graph/test/ActionSpec.hs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
{-# LANGUAGE OverloadedStrings #-}
2-
{-# LANGUAGE RecordWildCards #-}
1+
{-# LANGUAGE ImpredicativeTypes #-}
2+
{-# LANGUAGE OverloadedStrings #-}
3+
{-# LANGUAGE RecordWildCards #-}
34

45
module ActionSpec where
56

@@ -8,7 +9,11 @@ import qualified Control.Concurrent as C
89
import Control.Concurrent.STM
910
import Control.Monad.IO.Class (MonadIO (..))
1011
import Control.Monad.Trans.Cont (evalContT)
11-
import Development.IDE.Graph (shakeOptions)
12+
import Data.Typeable (Typeable)
13+
import Development.IDE.Graph (RuleResult,
14+
ShakeOptions,
15+
shakeOptions)
16+
import Development.IDE.Graph.Classes (Hashable)
1217
import Development.IDE.Graph.Database (shakeNewDatabase,
1318
shakeRunDatabase,
1419
shakeRunDatabaseForKeys)
@@ -23,9 +28,14 @@ import Test.Hspec
2328

2429

2530

31+
buildWithRoot :: forall f key value . (Traversable f, RuleResult key ~ value, Typeable key, Show key, Hashable key, Typeable value) => Database -> Stack -> f key -> IO (f Key, f value)
32+
buildWithRoot = build (newKey ("root" :: [Char]))
33+
shakeNewDatabaseWithLogger :: DBQue -> ShakeOptions -> Rules () -> IO ShakeDatabase
34+
shakeNewDatabaseWithLogger = shakeNewDatabase (const $ return ())
2635

2736
itInThread :: String -> (DBQue -> IO ()) -> SpecWith ()
2837
itInThread name ex = it name $ evalContT $ do
38+
-- thread <- withWorkerQueueSimpleRight (appendFile "hlg-graph-test.txt" . (++"\n") . show) "hls-graph test"
2939
thread <- withWorkerQueueSimpleRight (const $ return ()) "hls-graph test"
3040
liftIO $ ex thread
3141

@@ -53,7 +63,7 @@ spec = do
5363
return $ RunResult ChangedNothing "" r (return ())
5464
count <- C.newMVar 0
5565
count1 <- C.newMVar 0
56-
db <- shakeNewDatabase q shakeOptions $ do
66+
db <- shakeNewDatabaseWithLogger q shakeOptions $ do
5767
ruleSubBranch count
5868
ruleStep1 count1
5969
-- bootstrapping the database
@@ -74,18 +84,18 @@ spec = do
7484
c1 `shouldBe` 2
7585
describe "apply1" $ do
7686
itInThread "computes a rule with no dependencies" $ \q -> do
77-
db <- shakeNewDatabase q shakeOptions ruleUnit
87+
db <- shakeNewDatabaseWithLogger q shakeOptions ruleUnit
7888
res <- shakeRunDatabaseFromRight db $
7989
pure $ apply1 (Rule @())
8090
res `shouldBe` [()]
8191
itInThread "computes a rule with one dependency" $ \q -> do
82-
db <- shakeNewDatabase q shakeOptions $ do
92+
db <- shakeNewDatabaseWithLogger q shakeOptions $ do
8393
ruleUnit
8494
ruleBool
8595
res <- shakeRunDatabaseFromRight db $ pure $ apply1 Rule
8696
res `shouldBe` [True]
8797
itInThread "tracks direct dependencies" $ \q -> do
88-
db@(ShakeDatabase _ _ theDb) <- shakeNewDatabase q shakeOptions $ do
98+
db@(ShakeDatabase _ _ theDb) <- shakeNewDatabaseWithLogger q shakeOptions $ do
8999
ruleUnit
90100
ruleBool
91101
let theKey = Rule @Bool
@@ -95,7 +105,7 @@ spec = do
95105
Just (Clean res) <- lookup (newKey theKey) <$> getDatabaseValues theDb
96106
resultDeps res `shouldBe` ResultDeps [singletonKeySet $ newKey (Rule @())]
97107
itInThread "tracks reverse dependencies" $ \q -> do
98-
db@(ShakeDatabase _ _ Database {..}) <- shakeNewDatabase q shakeOptions $ do
108+
db@(ShakeDatabase _ _ Database {..}) <- shakeNewDatabaseWithLogger q shakeOptions $ do
99109
ruleUnit
100110
ruleBool
101111
let theKey = Rule @Bool
@@ -105,33 +115,33 @@ spec = do
105115
Just KeyDetails {..} <- atomically $ STM.lookup (newKey (Rule @())) databaseValues
106116
keyReverseDeps `shouldBe` singletonKeySet (newKey theKey)
107117
itInThread "rethrows exceptions" $ \q -> do
108-
db <- shakeNewDatabase q shakeOptions $ addRule $ \(Rule :: Rule ()) _old _mode -> error "boom"
118+
db <- shakeNewDatabaseWithLogger q shakeOptions $ addRule $ \(Rule :: Rule ()) _old _mode -> error "boom"
109119
let res = shakeRunDatabaseFromRight db $ pure $ apply1 (Rule @())
110120
res `shouldThrow` anyErrorCall
111121
itInThread "computes a rule with branching dependencies does not invoke phantom dependencies #3423" $ \q -> do
112122
cond <- C.newMVar True
113123
count <- C.newMVar 0
114-
(ShakeDatabase _ _ theDb) <- shakeNewDatabase q shakeOptions $ do
124+
(ShakeDatabase _ _ theDb) <- shakeNewDatabaseWithLogger q shakeOptions $ do
115125
ruleUnit
116126
ruleCond cond
117127
ruleSubBranch count
118128
ruleWithCond
119129
-- build the one with the condition True
120130
-- This should call the SubBranchRule once
121131
-- cond rule would return different results each time
122-
res0 <- build theDb emptyStack [BranchedRule]
132+
res0 <- buildWithRoot theDb emptyStack [BranchedRule]
123133
snd res0 `shouldBe` [1 :: Int]
124134
incDatabase theDb Nothing
125135
-- build the one with the condition False
126136
-- This should not call the SubBranchRule
127-
res1 <- build theDb emptyStack [BranchedRule]
137+
res1 <- buildWithRoot theDb emptyStack [BranchedRule]
128138
snd res1 `shouldBe` [2 :: Int]
129139
-- SubBranchRule should be recomputed once before this (when the condition was True)
130-
countRes <- build theDb emptyStack [SubBranchRule]
140+
countRes <- buildWithRoot theDb emptyStack [SubBranchRule]
131141
snd countRes `shouldBe` [1 :: Int]
132142

133143
describe "applyWithoutDependency" $ itInThread "does not track dependencies" $ \q -> do
134-
db@(ShakeDatabase _ _ theDb) <- shakeNewDatabase q shakeOptions $ do
144+
db@(ShakeDatabase _ _ theDb) <- shakeNewDatabaseWithLogger q shakeOptions $ do
135145
ruleUnit
136146
addRule $ \Rule _old _mode -> do
137147
[()] <- applyWithoutDependency [Rule]

hls-graph/test/DatabaseSpec.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ module DatabaseSpec where
44

55
import ActionSpec (itInThread)
66
import Control.Exception (SomeException, throw)
7-
import Development.IDE.Graph (newKey, shakeOptions)
7+
import Development.IDE.Graph (ShakeOptions, newKey,
8+
shakeOptions)
89
import Development.IDE.Graph.Database (shakeNewDatabase,
910
shakeRunDatabase)
1011
import Development.IDE.Graph.Internal.Action (apply1)
@@ -21,12 +22,14 @@ exractException [] = Nothing
2122
exractException (Left e : _) | Just ne@StackException{} <- fromGraphException e = return ne
2223
exractException (_: xs) = exractException xs
2324

25+
shakeNewDatabaseWithLogger :: DBQue -> ShakeOptions -> Rules () -> IO ShakeDatabase
26+
shakeNewDatabaseWithLogger = shakeNewDatabase (const $ return ())
2427

2528
spec :: Spec
2629
spec = do
2730
describe "Evaluation" $ do
2831
itInThread "detects cycles" $ \q -> do
29-
db <- shakeNewDatabase q shakeOptions $ do
32+
db <- shakeNewDatabaseWithLogger q shakeOptions $ do
3033
ruleBool
3134
addRule $ \Rule _old _mode -> do
3235
True <- apply1 (Rule @Bool)
@@ -40,7 +43,7 @@ spec = do
4043

4144
describe "compute" $ do
4245
itInThread "build step and changed step updated correctly" $ \q -> do
43-
(ShakeDatabase _ _ theDb) <- shakeNewDatabase q shakeOptions $ do
46+
(ShakeDatabase _ _ theDb) <- shakeNewDatabaseWithLogger q shakeOptions $ do
4447
ruleStep
4548
let k = newKey $ Rule @()
4649
-- ChangedRecomputeSame

0 commit comments

Comments
 (0)