1
- {-# LANGUAGE OverloadedStrings #-}
2
- {-# LANGUAGE RecordWildCards #-}
1
+ {-# LANGUAGE ImpredicativeTypes #-}
2
+ {-# LANGUAGE OverloadedStrings #-}
3
+ {-# LANGUAGE RecordWildCards #-}
3
4
4
5
module ActionSpec where
5
6
@@ -8,7 +9,11 @@ import qualified Control.Concurrent as C
8
9
import Control.Concurrent.STM
9
10
import Control.Monad.IO.Class (MonadIO (.. ))
10
11
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 )
12
17
import Development.IDE.Graph.Database (shakeNewDatabase ,
13
18
shakeRunDatabase ,
14
19
shakeRunDatabaseForKeys )
@@ -23,9 +28,14 @@ import Test.Hspec
23
28
24
29
25
30
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 () )
26
35
27
36
itInThread :: String -> (DBQue -> IO () ) -> SpecWith ()
28
37
itInThread name ex = it name $ evalContT $ do
38
+ -- thread <- withWorkerQueueSimpleRight (appendFile "hlg-graph-test.txt" . (++"\n") . show) "hls-graph test"
29
39
thread <- withWorkerQueueSimpleRight (const $ return () ) " hls-graph test"
30
40
liftIO $ ex thread
31
41
@@ -53,7 +63,7 @@ spec = do
53
63
return $ RunResult ChangedNothing " " r (return () )
54
64
count <- C. newMVar 0
55
65
count1 <- C. newMVar 0
56
- db <- shakeNewDatabase q shakeOptions $ do
66
+ db <- shakeNewDatabaseWithLogger q shakeOptions $ do
57
67
ruleSubBranch count
58
68
ruleStep1 count1
59
69
-- bootstrapping the database
@@ -74,18 +84,18 @@ spec = do
74
84
c1 `shouldBe` 2
75
85
describe " apply1" $ do
76
86
itInThread " computes a rule with no dependencies" $ \ q -> do
77
- db <- shakeNewDatabase q shakeOptions ruleUnit
87
+ db <- shakeNewDatabaseWithLogger q shakeOptions ruleUnit
78
88
res <- shakeRunDatabaseFromRight db $
79
89
pure $ apply1 (Rule @ () )
80
90
res `shouldBe` [() ]
81
91
itInThread " computes a rule with one dependency" $ \ q -> do
82
- db <- shakeNewDatabase q shakeOptions $ do
92
+ db <- shakeNewDatabaseWithLogger q shakeOptions $ do
83
93
ruleUnit
84
94
ruleBool
85
95
res <- shakeRunDatabaseFromRight db $ pure $ apply1 Rule
86
96
res `shouldBe` [True ]
87
97
itInThread " tracks direct dependencies" $ \ q -> do
88
- db@ (ShakeDatabase _ _ theDb) <- shakeNewDatabase q shakeOptions $ do
98
+ db@ (ShakeDatabase _ _ theDb) <- shakeNewDatabaseWithLogger q shakeOptions $ do
89
99
ruleUnit
90
100
ruleBool
91
101
let theKey = Rule @ Bool
@@ -95,7 +105,7 @@ spec = do
95
105
Just (Clean res) <- lookup (newKey theKey) <$> getDatabaseValues theDb
96
106
resultDeps res `shouldBe` ResultDeps [singletonKeySet $ newKey (Rule @ () )]
97
107
itInThread " tracks reverse dependencies" $ \ q -> do
98
- db@ (ShakeDatabase _ _ Database {.. }) <- shakeNewDatabase q shakeOptions $ do
108
+ db@ (ShakeDatabase _ _ Database {.. }) <- shakeNewDatabaseWithLogger q shakeOptions $ do
99
109
ruleUnit
100
110
ruleBool
101
111
let theKey = Rule @ Bool
@@ -105,33 +115,33 @@ spec = do
105
115
Just KeyDetails {.. } <- atomically $ STM. lookup (newKey (Rule @ () )) databaseValues
106
116
keyReverseDeps `shouldBe` singletonKeySet (newKey theKey)
107
117
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"
109
119
let res = shakeRunDatabaseFromRight db $ pure $ apply1 (Rule @ () )
110
120
res `shouldThrow` anyErrorCall
111
121
itInThread " computes a rule with branching dependencies does not invoke phantom dependencies #3423" $ \ q -> do
112
122
cond <- C. newMVar True
113
123
count <- C. newMVar 0
114
- (ShakeDatabase _ _ theDb) <- shakeNewDatabase q shakeOptions $ do
124
+ (ShakeDatabase _ _ theDb) <- shakeNewDatabaseWithLogger q shakeOptions $ do
115
125
ruleUnit
116
126
ruleCond cond
117
127
ruleSubBranch count
118
128
ruleWithCond
119
129
-- build the one with the condition True
120
130
-- This should call the SubBranchRule once
121
131
-- cond rule would return different results each time
122
- res0 <- build theDb emptyStack [BranchedRule ]
132
+ res0 <- buildWithRoot theDb emptyStack [BranchedRule ]
123
133
snd res0 `shouldBe` [1 :: Int ]
124
134
incDatabase theDb Nothing
125
135
-- build the one with the condition False
126
136
-- This should not call the SubBranchRule
127
- res1 <- build theDb emptyStack [BranchedRule ]
137
+ res1 <- buildWithRoot theDb emptyStack [BranchedRule ]
128
138
snd res1 `shouldBe` [2 :: Int ]
129
139
-- SubBranchRule should be recomputed once before this (when the condition was True)
130
- countRes <- build theDb emptyStack [SubBranchRule ]
140
+ countRes <- buildWithRoot theDb emptyStack [SubBranchRule ]
131
141
snd countRes `shouldBe` [1 :: Int ]
132
142
133
143
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
135
145
ruleUnit
136
146
addRule $ \ Rule _old _mode -> do
137
147
[() ] <- applyWithoutDependency [Rule ]
0 commit comments