From 5ede57122ce61d1504e81c6429ff26c38490aee6 Mon Sep 17 00:00:00 2001 From: Jesse Rosenthal Date: Thu, 1 Dec 2016 12:47:05 -0500 Subject: Update all tests to use new readers and error structure. --- tests/Tests/Old.hs | 3 +-- tests/Tests/Readers/Docx.hs | 10 +++++----- tests/Tests/Readers/EPUB.hs | 6 ++++-- tests/Tests/Readers/HTML.hs | 2 +- tests/Tests/Readers/LaTeX.hs | 2 +- tests/Tests/Readers/Markdown.hs | 12 ++++++------ tests/Tests/Readers/Odt.hs | 11 +++++------ tests/Tests/Readers/Org.hs | 4 ++-- tests/Tests/Readers/RST.hs | 2 +- tests/Tests/Readers/Txt2Tags.hs | 4 +++- tests/Tests/Writers/Docx.hs | 7 +++---- 11 files changed, 32 insertions(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/Tests/Old.hs b/tests/Tests/Old.hs index b76043887..a8ac717e4 100644 --- a/tests/Tests/Old.hs +++ b/tests/Tests/Old.hs @@ -19,7 +19,6 @@ import Prelude hiding ( readFile ) import qualified Data.ByteString.Lazy as B import Text.Pandoc.UTF8 (toStringLazy) import Text.Printf -import Text.Pandoc.Error import Tests.Helpers (purely) readFileUTF8 :: FilePath -> IO String @@ -197,7 +196,7 @@ lhsReaderTest format = testWithNormalize normalizer "lhs" ["-r", format, "-w", "native"] ("lhs-test" <.> format) norm where normalizer = purely $ \nat -> do - d <- handleError <$> readNative nat + d <- readNative nat writeNative def $ normalize d norm = if format == "markdown+lhs" then "lhs-test-markdown.native" diff --git a/tests/Tests/Readers/Docx.hs b/tests/Tests/Readers/Docx.hs index 59147b664..22fdf575a 100644 --- a/tests/Tests/Readers/Docx.hs +++ b/tests/Tests/Readers/Docx.hs @@ -13,8 +13,8 @@ import Text.Pandoc.Writers.Native (writeNative) import qualified Data.Map as M import Text.Pandoc.MediaBag (MediaBag, lookupMedia, mediaDirectory) import Codec.Archive.Zip -import Text.Pandoc.Error import Text.Pandoc.Class (runIOorExplode) +import qualified Text.Pandoc.Class as P -- We define a wrapper around pandoc that doesn't normalize in the -- tests. Since we do our own normalization, we want to make sure @@ -43,9 +43,9 @@ compareOutput :: ReaderOptions compareOutput opts docxFile nativeFile = do df <- B.readFile docxFile nf <- Prelude.readFile nativeFile - let (p, _) = handleError $ readDocx opts df + p <- runIOorExplode $ readDocx opts df df' <- runIOorExplode $ readNative nf - return $ (noNorm p, noNorm $ handleError df') + return $ (noNorm p, noNorm df') testCompareWithOptsIO :: ReaderOptions -> String -> FilePath -> FilePath -> IO Test testCompareWithOptsIO opts name docxFile nativeFile = do @@ -62,7 +62,7 @@ testCompare = testCompareWithOpts def testForWarningsWithOptsIO :: ReaderOptions -> String -> FilePath -> [String] -> IO Test testForWarningsWithOptsIO opts name docxFile expected = do df <- B.readFile docxFile - let (_, _, warns) = handleError $ readDocxWithWarnings opts df + warns <- runIOorExplode (readDocx opts df >> P.getWarnings) return $ test id name (unlines warns, unlines expected) testForWarningsWithOpts :: ReaderOptions -> String -> FilePath -> [String] -> Test @@ -95,7 +95,7 @@ compareMediaPathIO mediaPath mediaBag docxPath = do compareMediaBagIO :: FilePath -> IO Bool compareMediaBagIO docxFile = do df <- B.readFile docxFile - let (_, mb) = handleError $ readDocx def df + mb <- runIOorExplode (readDocx def df >> P.getMediaBag) bools <- mapM (\(fp, _, _) -> compareMediaPathIO fp mb docxFile) (mediaDirectory mb) diff --git a/tests/Tests/Readers/EPUB.hs b/tests/Tests/Readers/EPUB.hs index 2ad36eba6..9190671c3 100644 --- a/tests/Tests/Readers/EPUB.hs +++ b/tests/Tests/Readers/EPUB.hs @@ -7,10 +7,12 @@ import Test.Framework.Providers.HUnit import qualified Data.ByteString.Lazy as BL import Text.Pandoc.Readers.EPUB import Text.Pandoc.MediaBag (MediaBag, mediaDirectory) -import Text.Pandoc.Error +import qualified Text.Pandoc.Class as P getMediaBag :: FilePath -> IO MediaBag -getMediaBag fp = snd . handleError . readEPUB def <$> BL.readFile fp +getMediaBag fp = do + bs <- BL.readFile fp + snd <$> (P.runIOorExplode $ P.withMediaBag $ readEPUB def bs) testMediaBag :: FilePath -> [(String, String, Int)] -> IO () testMediaBag fp bag = do diff --git a/tests/Tests/Readers/HTML.hs b/tests/Tests/Readers/HTML.hs index 1426a8bea..a1533e42a 100644 --- a/tests/Tests/Readers/HTML.hs +++ b/tests/Tests/Readers/HTML.hs @@ -9,7 +9,7 @@ import Text.Pandoc.Builder import Text.Pandoc html :: String -> Pandoc -html = handleError . readHtml def +html = purely $ readHtml def tests :: [Test] tests = [ testGroup "base tag" diff --git a/tests/Tests/Readers/LaTeX.hs b/tests/Tests/Readers/LaTeX.hs index 27e775724..45e88d90e 100644 --- a/tests/Tests/Readers/LaTeX.hs +++ b/tests/Tests/Readers/LaTeX.hs @@ -9,7 +9,7 @@ import Text.Pandoc.Builder import Text.Pandoc latex :: String -> Pandoc -latex = handleError . readLaTeX def +latex = purely $ readLaTeX def infix 4 =: (=:) :: ToString c diff --git a/tests/Tests/Readers/Markdown.hs b/tests/Tests/Readers/Markdown.hs index 439307dc9..b43a0ec49 100644 --- a/tests/Tests/Readers/Markdown.hs +++ b/tests/Tests/Readers/Markdown.hs @@ -10,17 +10,17 @@ import qualified Data.Set as Set import Text.Pandoc markdown :: String -> Pandoc -markdown = handleError . readMarkdown def +markdown = purely $ readMarkdown def markdownSmart :: String -> Pandoc -markdownSmart = handleError . readMarkdown def { readerSmart = True } +markdownSmart = purely $ readMarkdown def { readerSmart = True } markdownCDL :: String -> Pandoc -markdownCDL = handleError . readMarkdown def { readerExtensions = Set.insert +markdownCDL = purely $ readMarkdown def { readerExtensions = Set.insert Ext_compact_definition_lists $ readerExtensions def } markdownGH :: String -> Pandoc -markdownGH = handleError . readMarkdown def { readerExtensions = githubMarkdownExtensions } +markdownGH = purely $ readMarkdown def { readerExtensions = githubMarkdownExtensions } infix 4 =: (=:) :: ToString c @@ -29,7 +29,7 @@ infix 4 =: testBareLink :: (String, Inlines) -> Test testBareLink (inp, ils) = - test (handleError . readMarkdown def{ readerExtensions = + test (purely $ readMarkdown def{ readerExtensions = Set.fromList [Ext_autolink_bare_uris, Ext_raw_html] }) inp (inp, doc $ para ils) @@ -303,7 +303,7 @@ tests = [ testGroup "inline code" =?> para (note (para "See [^1]")) ] , testGroup "lhs" - [ test (handleError . readMarkdown def{ readerExtensions = Set.insert + [ test (purely $ readMarkdown def{ readerExtensions = Set.insert Ext_literate_haskell $ readerExtensions def }) "inverse bird tracks and html" $ "> a\n\n< b\n\n
\n" diff --git a/tests/Tests/Readers/Odt.hs b/tests/Tests/Readers/Odt.hs index 0ff527130..db9184107 100644 --- a/tests/Tests/Readers/Odt.hs +++ b/tests/Tests/Readers/Odt.hs @@ -5,7 +5,7 @@ import Text.Pandoc.Options import Text.Pandoc.Readers.Native import Text.Pandoc.Readers.Markdown import Text.Pandoc.Definition -import Text.Pandoc.Class (runIOorExplode) +import Text.Pandoc.Class (runIOorExplode, runIO, withMediaBag) import Tests.Helpers import Test.Framework import qualified Data.ByteString.Lazy as B @@ -63,17 +63,16 @@ compareOdtToNative :: TestCreator compareOdtToNative opts odtPath nativePath = do nativeFile <- Prelude.readFile nativePath odtFile <- B.readFile odtPath - native <- getNoNormVia id "native" <$> - runIOorExplode (readNative nativeFile) - let odt = getNoNormVia fst "odt" $ readOdt opts odtFile + native <- getNoNormVia id "native" <$> runIO (readNative nativeFile) + odt <- getNoNormVia id "odt" <$> runIO (readOdt opts odtFile) return (odt,native) compareOdtToMarkdown :: TestCreator compareOdtToMarkdown opts odtPath markdownPath = do markdownFile <- Prelude.readFile markdownPath odtFile <- B.readFile odtPath - let markdown = getNoNormVia id "markdown" $ readMarkdown opts markdownFile - let odt = getNoNormVia fst "odt" $ readOdt opts odtFile + markdown <- getNoNormVia id "markdown" <$> runIO (readMarkdown opts markdownFile) + odt <- getNoNormVia id "odt" <$> runIO (readOdt opts odtFile) return (odt,markdown) diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs index 72b7e2601..b1db75b83 100644 --- a/tests/Tests/Readers/Org.hs +++ b/tests/Tests/Readers/Org.hs @@ -9,10 +9,10 @@ import Text.Pandoc import Data.List (intersperse) org :: String -> Pandoc -org = handleError . readOrg def +org = purely $ readOrg def orgSmart :: String -> Pandoc -orgSmart = handleError . readOrg def { readerSmart = True } +orgSmart = purely $ readOrg def { readerSmart = True } infix 4 =: (=:) :: ToString c diff --git a/tests/Tests/Readers/RST.hs b/tests/Tests/Readers/RST.hs index 9ecbb7af7..464720496 100644 --- a/tests/Tests/Readers/RST.hs +++ b/tests/Tests/Readers/RST.hs @@ -9,7 +9,7 @@ import Text.Pandoc.Builder import Text.Pandoc rst :: String -> Pandoc -rst = handleError . readRST def{ readerStandalone = True } +rst = purely $ readRST def{ readerStandalone = True } infix 4 =: (=:) :: ToString c diff --git a/tests/Tests/Readers/Txt2Tags.hs b/tests/Tests/Readers/Txt2Tags.hs index 1bda32a49..33502ba78 100644 --- a/tests/Tests/Readers/Txt2Tags.hs +++ b/tests/Tests/Readers/Txt2Tags.hs @@ -10,8 +10,10 @@ import Text.Pandoc import Data.List (intersperse) import Text.Pandoc.Readers.Txt2Tags + t2t :: String -> Pandoc -t2t = handleError . readTxt2Tags (T2TMeta "date" "mtime" "in" "out") def +-- t2t = handleError . readTxt2Tags (T2TMeta "date" "mtime" "in" "out") def +t2t = purely $ readTxt2Tags def infix 4 =: (=:) :: ToString c diff --git a/tests/Tests/Writers/Docx.hs b/tests/Tests/Writers/Docx.hs index cdaa2c097..548e9ddcf 100644 --- a/tests/Tests/Writers/Docx.hs +++ b/tests/Tests/Writers/Docx.hs @@ -7,7 +7,6 @@ import Tests.Helpers import Test.Framework import Text.Pandoc.Readers.Docx import Text.Pandoc.Writers.Docx -import Text.Pandoc.Error import System.FilePath (()) import Text.Pandoc.Class (runIOorExplode) @@ -22,10 +21,10 @@ compareOutput opts nativeFileIn nativeFileOut = do nf' <- Prelude.readFile nativeFileOut let wopts = fst opts df <- runIOorExplode $ do - d <- handleError <$> readNative nf + d <- readNative nf writeDocx wopts{writerUserDataDir = Just (".." "data")} d - df' <- handleError <$> runIOorExplode (readNative nf') - let (p, _) = handleError $ readDocx (snd opts) df + df' <- runIOorExplode (readNative nf') + p <- runIOorExplode $ readDocx (snd opts) df return (p, df') testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO Test -- cgit v1.2.3