Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
Expand Down
2 changes: 2 additions & 0 deletions markdown-doctest.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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