git.iko.soy/typeable/pandoc
on master help sign in
Update all tests to use new readers and error structure.
commit5ede57122ce61d1504e81c6429ff26c38490aee6 authorJesse Rosenthal <jrosenthal@jhu.edu> dateThu 1 Dec 2016, 12:47 (10 years ago) parent3574b98
11 files changed+32−31
tests/Tests/Old.hs+1−2 tests/Tests/Readers/Docx.hs+5−5 tests/Tests/Readers/EPUB.hs+4−2 tests/Tests/Readers/HTML.hs+1−1 tests/Tests/Readers/LaTeX.hs+1−1 tests/Tests/Readers/Markdown.hs+6−6 tests/Tests/Readers/Odt.hs+5−6 tests/Tests/Readers/Org.hs+2−2 tests/Tests/Readers/RST.hs+1−1 tests/Tests/Readers/Txt2Tags.hs+3−1 tests/Tests/Writers/Docx.hs+3−4
tests/Tests/Old.hs+1−2
@@ -19,7 +19,6 @@ import Prelude hiding ( readFile )
1919import qualified Data.ByteString.Lazy as B
2020import Text.Pandoc.UTF8 (toStringLazy)
2121import Text.Printf
22−import Text.Pandoc.Error
2322import Tests.Helpers (purely)
2423
2524readFileUTF8 :: FilePath -> IO String
@@ -197,7 +196,7 @@ lhsReaderTest format =
197196 testWithNormalize normalizer "lhs" ["-r", format, "-w", "native"]
198197 ("lhs-test" <.> format) norm
199198 where normalizer = purely $ \nat -> do
200− d <- handleError <$> readNative nat
199+ d <- readNative nat
201200 writeNative def $ normalize d
202201 norm = if format == "markdown+lhs"
203202 then "lhs-test-markdown.native"
tests/Tests/Readers/Docx.hs+5−5
@@ -13,8 +13,8 @@ import Text.Pandoc.Writers.Native (writeNative)
1313import qualified Data.Map as M
1414import Text.Pandoc.MediaBag (MediaBag, lookupMedia, mediaDirectory)
1515import Codec.Archive.Zip
16−import Text.Pandoc.Error
1716import Text.Pandoc.Class (runIOorExplode)
17+import qualified Text.Pandoc.Class as P
1818
1919-- We define a wrapper around pandoc that doesn't normalize in the
2020-- tests. Since we do our own normalization, we want to make sure
@@ -43,9 +43,9 @@ compareOutput :: ReaderOptions
4343compareOutput opts docxFile nativeFile = do
4444 df <- B.readFile docxFile
4545 nf <- Prelude.readFile nativeFile
46− let (p, _) = handleError $ readDocx opts df
46+ p <- runIOorExplode $ readDocx opts df
4747 df' <- runIOorExplode $ readNative nf
48− return $ (noNorm p, noNorm $ handleError df')
48+ return $ (noNorm p, noNorm df')
4949
5050testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO Test
5151testCompareWithOptsIO opts name docxFile nativeFile = do
@@ -62,7 +62,7 @@ testCompare = testCompareWithOpts def
6262testForWarningsWithOptsIO :: ReaderOptions -> String -> FilePath -> [String] -> IO Test
6363testForWarningsWithOptsIO opts name docxFile expected = do
6464 df <- B.readFile docxFile
65− let (_, _, warns) = handleError $ readDocxWithWarnings opts df
65+ warns <- runIOorExplode (readDocx opts df >> P.getWarnings)
6666 return $ test id name (unlines warns, unlines expected)
6767
6868testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> Test
@@ -95,7 +95,7 @@ compareMediaPathIO mediaPath mediaBag docxPath = do
9595compareMediaBagIO :: FilePath -> IO Bool
9696compareMediaBagIO docxFile = do
9797 df <- B.readFile docxFile
98− let (_, mb) = handleError $ readDocx def df
98+ mb <- runIOorExplode (readDocx def df >> P.getMediaBag)
9999 bools <- mapM
100100 (\(fp, _, _) -> compareMediaPathIO fp mb docxFile)
101101 (mediaDirectory mb)
tests/Tests/Readers/EPUB.hs+4−2
@@ -7,10 +7,12 @@ import Test.Framework.Providers.HUnit
77import qualified Data.ByteString.Lazy as BL
88import Text.Pandoc.Readers.EPUB
99import Text.Pandoc.MediaBag (MediaBag, mediaDirectory)
10−import Text.Pandoc.Error
10+import qualified Text.Pandoc.Class as P
1111
1212getMediaBag :: FilePath -> IO MediaBag
13−getMediaBag fp = snd . handleError . readEPUB def <$> BL.readFile fp
13+getMediaBag fp = do
14+ bs <- BL.readFile fp
15+ snd <$> (P.runIOorExplode $ P.withMediaBag $ readEPUB def bs)
1416
1517testMediaBag :: FilePath -> [(String, String, Int)] -> IO ()
1618testMediaBag fp bag = do
tests/Tests/Readers/HTML.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
99import Text.Pandoc
1010
1111html :: String -> Pandoc
12−html = handleError . readHtml def
12+html = purely $ readHtml def
1313
1414tests :: [Test]
1515tests = [ testGroup "base tag"
tests/Tests/Readers/LaTeX.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
99import Text.Pandoc
1010
1111latex :: String -> Pandoc
12−latex = handleError . readLaTeX def
12+latex = purely $ readLaTeX def
1313
1414infix 4 =:
1515(=:) :: ToString c
tests/Tests/Readers/Markdown.hs+6−6
@@ -10,17 +10,17 @@ import qualified Data.Set as Set
1010import Text.Pandoc
1111
1212markdown :: String -> Pandoc
13−markdown = handleError . readMarkdown def
13+markdown = purely $ readMarkdown def
1414
1515markdownSmart :: String -> Pandoc
16−markdownSmart = handleError . readMarkdown def { readerSmart = True }
16+markdownSmart = purely $ readMarkdown def { readerSmart = True }
1717
1818markdownCDL :: String -> Pandoc
19−markdownCDL = handleError . readMarkdown def { readerExtensions = Set.insert
19+markdownCDL = purely $ readMarkdown def { readerExtensions = Set.insert
2020 Ext_compact_definition_lists $ readerExtensions def }
2121
2222markdownGH :: String -> Pandoc
23−markdownGH = handleError . readMarkdown def { readerExtensions = githubMarkdownExtensions }
23+markdownGH = purely $ readMarkdown def { readerExtensions = githubMarkdownExtensions }
2424
2525infix 4 =:
2626(=:) :: ToString c
@@ -29,7 +29,7 @@ infix 4 =:
2929
3030testBareLink :: (String, Inlines) -> Test
3131testBareLink (inp, ils) =
32− test (handleError . readMarkdown def{ readerExtensions =
32+ test (purely $ readMarkdown def{ readerExtensions =
3333 Set.fromList [Ext_autolink_bare_uris, Ext_raw_html] })
3434 inp (inp, doc $ para ils)
3535
@@ -303,7 +303,7 @@ tests = [ testGroup "inline code"
303303 =?> para (note (para "See [^1]"))
304304 ]
305305 , testGroup "lhs"
306− [ test (handleError . readMarkdown def{ readerExtensions = Set.insert
306+ [ test (purely $ readMarkdown def{ readerExtensions = Set.insert
307307 Ext_literate_haskell $ readerExtensions def })
308308 "inverse bird tracks and html" $
309309 "> a\n\n< b\n\n<div>\n"
tests/Tests/Readers/Odt.hs+5−6
@@ -5,7 +5,7 @@ import Text.Pandoc.Options
55import Text.Pandoc.Readers.Native
66import Text.Pandoc.Readers.Markdown
77import Text.Pandoc.Definition
8−import Text.Pandoc.Class (runIOorExplode)
8+import Text.Pandoc.Class (runIOorExplode, runIO, withMediaBag)
99import Tests.Helpers
1010import Test.Framework
1111import qualified Data.ByteString.Lazy as B
@@ -63,17 +63,16 @@ compareOdtToNative :: TestCreator
6363compareOdtToNative opts odtPath nativePath = do
6464 nativeFile <- Prelude.readFile nativePath
6565 odtFile <- B.readFile odtPath
66− native <- getNoNormVia id "native" <$>
67− runIOorExplode (readNative nativeFile)
68− let odt = getNoNormVia fst "odt" $ readOdt opts odtFile
66+ native <- getNoNormVia id "native" <$> runIO (readNative nativeFile)
67+ odt <- getNoNormVia id "odt" <$> runIO (readOdt opts odtFile)
6968 return (odt,native)
7069
7170compareOdtToMarkdown :: TestCreator
7271compareOdtToMarkdown opts odtPath markdownPath = do
7372 markdownFile <- Prelude.readFile markdownPath
7473 odtFile <- B.readFile odtPath
75− let markdown = getNoNormVia id "markdown" $ readMarkdown opts markdownFile
76− let odt = getNoNormVia fst "odt" $ readOdt opts odtFile
74+ markdown <- getNoNormVia id "markdown" <$> runIO (readMarkdown opts markdownFile)
75+ odt <- getNoNormVia id "odt" <$> runIO (readOdt opts odtFile)
7776 return (odt,markdown)
7877
7978
tests/Tests/Readers/Org.hs+2−2
@@ -9,10 +9,10 @@ import Text.Pandoc
99import Data.List (intersperse)
1010
1111org :: String -> Pandoc
12−org = handleError . readOrg def
12+org = purely $ readOrg def
1313
1414orgSmart :: String -> Pandoc
15−orgSmart = handleError . readOrg def { readerSmart = True }
15+orgSmart = purely $ readOrg def { readerSmart = True }
1616
1717infix 4 =:
1818(=:) :: ToString c
tests/Tests/Readers/RST.hs+1−1
@@ -9,7 +9,7 @@ import Text.Pandoc.Builder
99import Text.Pandoc
1010
1111rst :: String -> Pandoc
12−rst = handleError . readRST def{ readerStandalone = True }
12+rst = purely $ readRST def{ readerStandalone = True }
1313
1414infix 4 =:
1515(=:) :: ToString c
tests/Tests/Readers/Txt2Tags.hs+3−1
@@ -10,8 +10,10 @@ import Text.Pandoc
1010import Data.List (intersperse)
1111import Text.Pandoc.Readers.Txt2Tags
1212
13+
1314t2t :: String -> Pandoc
14−t2t = handleError . readTxt2Tags (T2TMeta "date" "mtime" "in" "out") def
15+-- t2t = handleError . readTxt2Tags (T2TMeta "date" "mtime" "in" "out") def
16+t2t = purely $ readTxt2Tags def
1517
1618infix 4 =:
1719(=:) :: ToString c
tests/Tests/Writers/Docx.hs+3−4
@@ -7,7 +7,6 @@ import Tests.Helpers
77import Test.Framework
88import Text.Pandoc.Readers.Docx
99import Text.Pandoc.Writers.Docx
10−import Text.Pandoc.Error
1110import System.FilePath ((</>))
1211import Text.Pandoc.Class (runIOorExplode)
1312
@@ -22,10 +21,10 @@ compareOutput opts nativeFileIn nativeFileOut = do
2221 nf' <- Prelude.readFile nativeFileOut
2322 let wopts = fst opts
2423 df <- runIOorExplode $ do
25− d <- handleError <$> readNative nf
24+ d <- readNative nf
2625 writeDocx wopts{writerUserDataDir = Just (".." </> "data")} d
27− df' <- handleError <$> runIOorExplode (readNative nf')
28− let (p, _) = handleError $ readDocx (snd opts) df
26+ df' <- runIOorExplode (readNative nf')
27+ p <- runIOorExplode $ readDocx (snd opts) df
2928 return (p, df')
3029
3130testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO Test