Fixed up weigh-pandoc and benchmark-pandoc so they build.

This commit is contained in:
John MacFarlane 2016-12-10 23:42:28 +01:00
parent b5d1567022
commit 35699ee533
3 changed files with 17 additions and 13 deletions

View file

@ -22,14 +22,15 @@ import Data.Maybe (mapMaybe)
import Debug.Trace (trace)
readerBench :: Pandoc
-> (String, ReaderOptions -> String -> IO (Either PandocError Pandoc))
-> (String, ReaderOptions -> String -> Pandoc)
-> Maybe Benchmark
readerBench doc (name, reader) =
case lookup name writers of
Just (PureStringWriter writer) ->
let inp = writer def{ writerWrapText = WrapAuto} doc
in return $ bench (name ++ " reader") $ nfIO $
(fmap handleError <$> reader def{ readerSmart = True }) inp
Just (StringWriter writer) ->
let inp = either (error . show) id $ runPure
$ writer def{ writerWrapText = WrapAuto} doc
in return $ bench (name ++ " reader") $ nf
(reader def{ readerSmart = True }) inp
_ -> trace ("\nCould not find writer for " ++ name ++ "\n") Nothing
writerBench :: Pandoc
@ -42,11 +43,13 @@ main :: IO ()
main = do
inp <- readFile "tests/testsuite.txt"
let opts = def{ readerSmart = True }
let doc = handleError $ readMarkdown opts inp
let readers' = [(n,r) | (n, StringReader r) <- readers]
let doc = either (error . show) id $ runPure $ readMarkdown opts inp
let readers' = [(n, \o -> either (error . show) id . runPure . r o)
| (n, StringReader r) <- readers]
let readerBs = mapMaybe (readerBench doc)
$ filter (\(n,_) -> n /="haddock") readers'
let writers' = [(n,w) | (n, PureStringWriter w) <- writers]
let writers' = [(n, \o -> either (error . show) id . runPure . w o)
| (n, StringWriter w) <- writers]
let writerBs = map (writerBench doc)
$ writers'
defaultMainWith defaultConfig{ timeLimit = 6.0 }

View file

@ -7,7 +7,7 @@ main = do
mainWith $ do
func "Pandoc document" id doc
mapM_
(\(n,r) -> weighReader doc n (handleError . r def{ readerSmart = True }))
(\(n,r) -> weighReader doc n (either (error . show) id . runPure . r def{ readerSmart = True }))
[("markdown", readMarkdown)
,("html", readHtml)
,("docbook", readDocBook)
@ -15,7 +15,7 @@ main = do
,("commonmark", readCommonMark)
]
mapM_
(\(n,w) -> weighWriter doc n (w def))
(\(n,w) -> weighWriter doc n (either (error . show) id . runPure . w def))
[("markdown", writeMarkdown)
,("html", writeHtmlString)
,("docbook", writeDocbook)
@ -29,8 +29,8 @@ weighWriter doc name writer = func (name ++ " writer") writer doc
weighReader :: Pandoc -> String -> (String -> Pandoc) -> Weigh ()
weighReader doc name reader = do
case lookup name writers of
Just (PureStringWriter writer) ->
let inp = writer def{ writerWrapText = WrapAuto} doc
Just (StringWriter writer) ->
let inp = either (error . show) id $ runPure $ writer def{ writerWrapText = WrapAuto} doc
in func (name ++ " reader") reader inp
_ -> return () -- no writer for reader

View file

@ -485,7 +485,8 @@ Executable weigh-pandoc
if flag(weigh-pandoc)
Build-Depends: pandoc,
base >= 4.2 && < 5,
weigh >= 0.0 && < 0.1
weigh >= 0.0 && < 0.1,
mtl >= 2.2 && < 2.3
Buildable: True
else
Buildable: False