Skip to content

Commit 11554bb

Browse files
committed
Use direct cradles for test-setup
1 parent 3ac6ee7 commit 11554bb

File tree

1 file changed

+3
-121
lines changed

1 file changed

+3
-121
lines changed

test/utils/TestUtils.hs

Lines changed: 3 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ module TestUtils
1212
-- , runIGM'
1313
, ghcVersion, GhcVersion(..)
1414
, logFilePath
15-
, readResolver
1615
, hieCommand
1716
, hieCommandVomit
1817
, hieCommandExamplePlugin
@@ -112,27 +111,9 @@ withFileLogging logFile f = do
112111

113112
-- ---------------------------------------------------------------------
114113

115-
-- If an executable @stack@ is present on the system then setup stack files,
116-
-- otherwise specify a direct cradle with -isrc
117114
setupBuildToolFiles :: IO ()
118115
setupBuildToolFiles = do
119-
stack <- findExecutable "stack"
120-
let s = case stack of
121-
Nothing -> setupDirectFilesIn
122-
Just _ -> setupStackFilesIn
123-
forM_ files $ \f -> do
124-
s f
125-
-- Cleanup stack directory in case the presence of stack has changed since
126-
-- the last run
127-
removePathForcibly (f ++ ".stack-work")
128-
129-
setupStackFilesIn :: FilePath -> IO ()
130-
setupStackFilesIn f = do
131-
resolver <- readResolver
132-
writeFile (f ++ "stack.yaml") $ stackFileContents resolver
133-
case f of
134-
"./test/testdata/" -> writeFile (f ++ "hie.yaml") testdataHieYamlCradleStackContents
135-
_ -> writeFile (f ++ "hie.yaml") hieYamlCradleStackContents
116+
forM_ files setupDirectFilesIn
136117

137118
setupDirectFilesIn :: FilePath -> IO ()
138119
setupDirectFilesIn f =
@@ -172,32 +153,8 @@ ghcVersion = GHC86
172153
ghcVersion = GHC84
173154
#endif
174155

175-
stackYaml :: FilePath
176-
stackYaml =
177-
#if (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,8,2,0)))
178-
"stack-8.8.2.yaml"
179-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,8,1,0)))
180-
"stack-8.8.1.yaml"
181-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,6,5,0)))
182-
"stack-8.6.5.yaml"
183-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,6,4,0)))
184-
"stack-8.6.4.yaml"
185-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,6,3,0)))
186-
"stack-8.6.3.yaml"
187-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,6,2,0)))
188-
"stack-8.6.2.yaml"
189-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,6,1,0)))
190-
"stack-8.6.1.yaml"
191-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,4,4,0)))
192-
"stack-8.4.4.yaml"
193-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,4,3,0)))
194-
"stack-8.4.3.yaml"
195-
#elif (defined(MIN_VERSION_GLASGOW_HASKELL) && (MIN_VERSION_GLASGOW_HASKELL(8,4,2,0)))
196-
"stack-8.4.2.yaml"
197-
#endif
198-
199156
logFilePath :: String
200-
logFilePath = "hie-" ++ stackYaml ++ ".log"
157+
logFilePath = "hie-" ++ show ghcVersion ++ ".log"
201158

202159
-- | The command to execute the version of hie for the current compiler.
203160
--
@@ -216,92 +173,17 @@ hieCommandVomit = hieCommand ++ " --vomit"
216173
hieCommandExamplePlugin :: String
217174
hieCommandExamplePlugin = hieCommand ++ " --example"
218175

219-
-- |Choose a resolver based on the current compiler, otherwise HaRe/ghc-mod will
220-
-- not be able to load the files
221-
readResolver :: IO String
222-
readResolver = readResolverFrom stackYaml
223-
224-
newtype StackResolver = StackResolver String
225-
226-
instance FromJSON StackResolver where
227-
parseJSON (Object x) = StackResolver <$> x .: pack "resolver"
228-
parseJSON invalid = typeMismatch "StackResolver" invalid
229-
230-
readResolverFrom :: FilePath -> IO String
231-
readResolverFrom yamlPath = do
232-
result <- decodeFileEither yamlPath
233-
case result of
234-
Left err -> error $ yamlPath ++ " parsing failed: " ++ show err
235-
Right (StackResolver res) -> return res
236-
237176
-- ---------------------------------------------------------------------
238177

239-
hieYamlCradleStackContents :: String
240-
hieYamlCradleStackContents = unlines
241-
[ "# WARNING: THIS FILE IS AUTOGENERATED IN test/utils/TestUtils.hs. IT WILL BE OVERWRITTEN ON EVERY TEST RUN"
242-
, "cradle:"
243-
, " stack:"
244-
]
245-
246-
testdataHieYamlCradleStackContents :: String
247-
testdataHieYamlCradleStackContents = unlines
248-
[ "# WARNING: THIS FILE IS AUTOGENERATED IN test/utils/TestUtils.hs. IT WILL BE OVERWRITTEN ON EVERY TEST RUN"
249-
, "cradle:"
250-
, " stack:"
251-
-- , " - path: \"ApplyRefact.hs\""
252-
-- , " component: \"testdata:exe:applyrefact\""
253-
-- , " - path: \"ApplyRefact2.hs\""
254-
-- , " component: \"testdata:exe:applyrefact2\""
255-
-- , " - path: \"CodeActionRename.hs\""
256-
-- , " component: \"testdata:exe:codeactionrename\""
257-
-- , " - path: \"Hover.hs\""
258-
-- , " component: \"testdata:exe:hover\""
259-
-- , " - path: \"Symbols.hs\""
260-
-- , " component: \"testdata:exe:symbols\""
261-
-- , " - path: \"ApplyRefact2.hs\""
262-
-- , " component: \"testdata:exe:applyrefact2\""
263-
-- , " - path: \"HlintPragma.hs\""
264-
-- , " component: \"testdata:exe:hlintpragma\""
265-
-- , " - path: \"HaReCase.hs\""
266-
-- , " component: \"testdata:exe:harecase\""
267-
-- , " - path: \"HaReDemote.hs\""
268-
-- , " component: \"testdata:exe:haredemote\""
269-
-- , " - path: \"HaReMoveDef.hs\""
270-
-- , " component: \"testdata:exe:haremovedef\""
271-
-- , " - path: \"HaReRename.hs\""
272-
-- , " component: \"testdata:exe:harerename\""
273-
-- , " - path: \"HaReGA1.hs\""
274-
-- , " component: \"testdata:exe:haregenapplicative\""
275-
-- , " - path: \"FuncTest.hs\""
276-
-- , " component: \"testdata:exe:functests\""
277-
-- , " - path: \"liquid/Evens.hs\""
278-
-- , " component: \"testdata:exe:evens\""
279-
-- , " - path: \"FileWithWarning.hs\""
280-
-- , " component: \"testdata:exe:filewithwarning\""
281-
-- , " - path: ."
282-
-- , " component: \"testdata:exe:filewithwarning\""
283-
]
284-
285-
286178
hieYamlCradleDirectContents :: String
287179
hieYamlCradleDirectContents = unlines
288180
[ "# WARNING: THIS FILE IS AUTOGENERATED IN test/utils/TestUtils.hs. IT WILL BE OVERWRITTEN ON EVERY TEST RUN"
289181
, "cradle:"
290182
, " direct:"
291183
, " arguments:"
292-
, " - -isrc"
184+
, " - -i."
293185
]
294186

295-
stackFileContents :: String -> String
296-
stackFileContents resolver = unlines
297-
[ "# WARNING: THIS FILE IS AUTOGENERATED IN test/utils/TestUtils. IT WILL BE OVERWRITTEN ON EVERY TEST RUN"
298-
, "resolver: " ++ resolver
299-
, "packages:"
300-
, "- '.'"
301-
, "extra-deps: []"
302-
, "flags: {}"
303-
, "extra-package-dbs: []"
304-
]
305187

306188
-- ---------------------------------------------------------------------
307189

0 commit comments

Comments
 (0)