1- {-# LANGUAGE OverloadedStrings #-}
2- {-# LANGUAGE RecordWildCards #-}
1+ {-# LANGUAGE ImpredicativeTypes #-}
2+ {-# LANGUAGE OverloadedStrings #-}
3+ {-# LANGUAGE RecordWildCards #-}
34
45module ActionSpec where
56
@@ -8,7 +9,11 @@ import qualified Control.Concurrent as C
89import Control.Concurrent.STM
910import Control.Monad.IO.Class (MonadIO (.. ))
1011import 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 )
1217import 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
2736itInThread :: String -> (DBQue -> IO () ) -> SpecWith ()
2837itInThread 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 ]
0 commit comments