diff --git a/app/Main.hs b/app/Main.hs index 5bb2eb7..54f0c48 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -7,6 +7,7 @@ import Data.List (find, isPrefixOf) import Streamly.Data.Fold (Fold) import Streamly.Data.Parser (Parser) import System.Environment (getArgs) +import System.IO.Temp (withSystemTempFile) import qualified Language.Haskell.Ghcid as G import qualified Streamly.Data.Fold as Fold @@ -225,17 +226,18 @@ loopCmdREPL sess (ln:lns) = do loopCmdFile :: G.Ghci -> [(Int, String)] -> IO Bool loopCmdFile _ [] = putStrLn "All good" >> return True -loopCmdFile sess (ln:lns) = do - let padding = replicate (fst ln - 1) '\n' - writeFile ("interpreted.hs") (padding ++ snd ln) - putStrLn (snd ln) - res <- G.exec sess ":load interpreted.hs" - if or (map hasErrorFile res) - then do - mapM_ putStrLn res - putStrLn ("Error at: " ++ show (fst ln)) - return False - else loopCmdFile sess lns +loopCmdFile sess (ln:lns) = + withSystemTempFile "docTest" $ \fp _fh -> do + let padding = replicate (fst ln - 1) '\n' + writeFile fp (padding ++ snd ln) + putStrLn (snd ln) + res <- G.exec sess (":load " ++ fp) + if or (map hasErrorFile res) + then do + mapM_ putStrLn res + putStrLn ("Error at: " ++ show (fst ln)) + return False + else loopCmdFile sess lns ghciSetup :: [String] ghciSetup = [":set -fobject-code"] diff --git a/markdown-doctest.cabal b/markdown-doctest.cabal index 71b07e8..639783a 100644 --- a/markdown-doctest.cabal +++ b/markdown-doctest.cabal @@ -47,5 +47,7 @@ executable markdown-doctest build-depends: base , streamly-core , ghcid + , temporary >= 1.3 && < 1.4 + , filepath >= 1.4 && < 1.5 hs-source-dirs: app default-language: Haskell2010