@@ -25,7 +25,7 @@ module Hedgehog.Extras.Test.Process
25
25
, defaultExecConfig
26
26
) where
27
27
28
- import Control.Monad (Monad (.. ), MonadFail (fail ), void )
28
+ import Control.Monad (Monad (.. ), MonadFail (fail ), void , unless )
29
29
import Control.Monad.Catch (MonadCatch )
30
30
import Control.Monad.IO.Class (MonadIO , liftIO )
31
31
import Control.Monad.Trans.Resource (MonadResource , ReleaseKey , register )
@@ -84,14 +84,15 @@ findDefaultPlanJsonFile :: IO FilePath
84
84
findDefaultPlanJsonFile = IO. getCurrentDirectory >>= go
85
85
where go :: FilePath -> IO FilePath
86
86
go d = do
87
- let file = d </> " dist-newstyle/cache/plan.json"
87
+ let planRelPath = " dist-newstyle/cache/plan.json"
88
+ file = d </> planRelPath
88
89
exists <- IO. doesFileExist file
89
90
if exists
90
91
then return file
91
92
else do
92
93
let parent = takeDirectory d
93
94
if parent == d
94
- then return " dist-newstyle/cache/plan.json "
95
+ then return planRelPath
95
96
else go parent
96
97
97
98
-- | Discover the location of the plan.json file.
@@ -272,7 +273,7 @@ waitSecondsForProcess seconds hProcess = GHC.withFrozenCallStack $ do
272
273
273
274
-- | Compute the path to the binary given a package name or an environment variable override.
274
275
binFlex
275
- :: (MonadTest m , MonadIO m )
276
+ :: (HasCallStack , MonadTest m , MonadIO m )
276
277
=> String
277
278
-- ^ Package name
278
279
-> String
@@ -288,22 +289,26 @@ binFlex pkg binaryEnv = do
288
289
-- | Consult the "plan.json" generated by cabal to get the path to the executable corresponding.
289
290
-- to a haskell package. It is assumed that the project has already been configured and the
290
291
-- executable has been built.
292
+ -- Throws an exception on failure.
291
293
binDist
292
- :: (MonadTest m , MonadIO m )
294
+ :: (HasCallStack , MonadTest m , MonadIO m )
293
295
=> String
294
296
-- ^ Package name
295
297
-> m FilePath
296
298
-- ^ Path to executable
297
299
binDist pkg = do
300
+ doesPlanExist <- liftIO $ IO. doesFileExist planJsonFile
301
+ unless doesPlanExist $
302
+ error $ " Could not find plan.json in the path: " <> planJsonFile
298
303
contents <- H. evalIO . LBS. readFile $ planJsonFile
299
304
300
305
case eitherDecode contents of
301
306
Right plan -> case L. filter matching (plan & installPlan) of
302
307
(component: _) -> case component & binFile of
303
308
Just bin -> return $ addExeSuffix (T. unpack bin)
304
- Nothing -> error $ " missing bin-file in : " <> show component
305
- [] -> error $ " Cannot find exe:" <> pkg <> " in plan"
306
- Left message -> error $ " Cannot decode plan: " <> message
309
+ Nothing -> error $ " missing \" bin-file\" key in plan component : " <> show component <> " in the plan in: " <> planJsonFile
310
+ [] -> error $ " Cannot find \" component-name \" key with the value \" exe:" <> pkg <> " \" in the plan in: " <> planJsonFile
311
+ Left message -> error $ " Cannot decode plan in " <> planJsonFile <> " : " <> message
307
312
where matching :: Component -> Bool
308
313
matching component = case componentName component of
309
314
Just name -> name == " exe:" <> T. pack pkg
0 commit comments