Reinstate cwd setup, this time with locking
This commit is contained in:
@@ -3,6 +3,8 @@ module MonadSpec where
|
||||
import Test.Hspec
|
||||
import TestUtils
|
||||
import Control.Monad.Error.Class
|
||||
import Control.Concurrent
|
||||
import Control.Exception
|
||||
|
||||
spec :: Spec
|
||||
spec = do
|
||||
@@ -15,3 +17,21 @@ spec = do
|
||||
return "hello"
|
||||
`catchError` (const $ fail "oh noes")
|
||||
a `shouldBe` (Left $ GMEString "oh noes")
|
||||
|
||||
describe "runGhcModT" $
|
||||
it "throws an exception when run in multiple threads" $ do
|
||||
mv1 :: MVar (Either SomeException ())
|
||||
<- newEmptyMVar
|
||||
mv2 :: MVar (Either SomeException ())
|
||||
<- newEmptyMVar
|
||||
|
||||
_ <- forkOS $ putMVar mv1 =<< (try $ evaluate =<< (runD $ liftIO $ readMVar mv2 >> return ()))
|
||||
_ <- forkOS $ putMVar mv2 =<< (try $ evaluate =<< (runD $ return ()))
|
||||
e1 <- takeMVar mv1
|
||||
e2 <- takeMVar mv2
|
||||
|
||||
(isLeft e1 || isLeft e2) `shouldBe` True
|
||||
|
||||
isLeft :: Either a b -> Bool
|
||||
isLeft (Right _) = False
|
||||
isLeft (Left _) = True
|
||||
|
||||
@@ -45,20 +45,7 @@ extract action = do
|
||||
|
||||
withSpecCradle :: (IOish m, GmOut m) => FilePath -> ((Cradle, GhcModLog) -> m a) -> m a
|
||||
withSpecCradle cradledir f = do
|
||||
gbracket (runJournalT $ findSpecCradle cradledir) (liftIO . cleanupCradle . fst) $ \arg@(crdl,_) ->
|
||||
bracketWorkingDirectory (cradleRootDir crdl) $
|
||||
f arg
|
||||
|
||||
bracketWorkingDirectory ::
|
||||
(ExceptionMonad m, MonadIO m) => FilePath -> m c -> m c
|
||||
bracketWorkingDirectory dir a =
|
||||
gbracket (swapWorkingDirectory dir) (liftIO . setCurrentDirectory) (const a)
|
||||
|
||||
swapWorkingDirectory :: MonadIO m => FilePath -> m FilePath
|
||||
swapWorkingDirectory ndir = liftIO $ do
|
||||
odir <- getCurrentDirectory >>= canonicalizePath
|
||||
setCurrentDirectory $ ndir
|
||||
return odir
|
||||
gbracket (runJournalT $ findSpecCradle cradledir) (liftIO . cleanupCradle . fst) f
|
||||
|
||||
runGhcModTSpec :: Options -> GhcModT IO a -> IO (Either GhcModError a, GhcModLog)
|
||||
runGhcModTSpec opt action = do
|
||||
|
||||
Reference in New Issue
Block a user