Skip to content

Commit 544f1fc

Browse files
committed
Test figures
1 parent 874f92b commit 544f1fc

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

pandoc.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ extra-source-files:
206206
test/bodybg.gif
207207
test/*.native
208208
test/command/*.md
209+
test/command/figures/*.md
209210
test/command/*.csl
210211
test/command/biblio.bib
211212
test/command/averroes.bib

test/Tests/Command.hs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ runTest testExePath testname cmd inp norm = testCase testname $ do
7373
else return $ TestError ec
7474
assertBool (show result) (result == TestPassed)
7575

76-
tests :: TestTree
76+
tests :: FilePath -> TestTree
7777
{-# NOINLINE tests #-}
78-
tests = unsafePerformIO $ do
78+
tests root = unsafePerformIO $ do
7979
files <- filter (".md" `isSuffixOf`) <$>
80-
getDirectoryContents "command"
80+
getDirectoryContents root
8181
testExePath <- getExecutablePath
82-
let cmds = map (extractCommandTest testExePath) files
83-
return $ testGroup "Command:" cmds
82+
let cmds = map (extractCommandTest root testExePath) files
83+
return $ testGroup ("Command folder: " <> root) cmds
8484

8585
isCodeBlock :: Block -> Bool
8686
isCodeBlock (CodeBlock _ _) = True
@@ -94,9 +94,9 @@ dropPercent :: String -> String
9494
dropPercent ('%':xs) = dropWhile (== ' ') xs
9595
dropPercent xs = xs
9696

97-
runCommandTest :: FilePath -> FilePath -> Int -> String -> TestTree
98-
runCommandTest testExePath fp num code =
99-
goldenTest testname getExpected getActual compareValues' updateGolden
97+
runCommandTest :: FilePath -> FilePath -> FilePath -> Int -> String -> TestTree
98+
runCommandTest root testExePath fp num code =
99+
goldenTest testname getExpected getActual compareValues updateGolden
100100
where
101101
testname = "#" <> show num
102102
codelines = lines code
@@ -109,27 +109,27 @@ runCommandTest testExePath fp num code =
109109
norm = unlines normlines
110110
getExpected = return norm
111111
getActual = snd <$> execTest testExePath cmd input
112-
compareValues' expected actual
112+
compareValues expected actual
113113
| actual == expected = return Nothing
114-
| otherwise = return $ Just $ "--- test/command/" ++ fp ++ "\n+++ " ++
114+
| otherwise = return $ Just $ "--- test" </> root </> fp ++ "\n+++ " ++
115115
cmd ++ "\n" ++ showDiff (1,1)
116116
(getDiff (lines actual) (lines expected))
117117
updateGolden newnorm = do
118-
let fp' = "command" </> fp
118+
let fp' = "command/figures" </> fp
119119
raw <- UTF8.readFile fp'
120120
let cmdline = "% " <> cmd
121121
let x = cmdline <> "\n" <> input <> "^D\n" <> norm
122122
let y = cmdline <> "\n" <> input <> "^D\n" <> newnorm
123123
let updated = T.replace (T.pack x) (T.pack y) raw
124124
UTF8.writeFile fp' updated
125125

126-
extractCommandTest :: FilePath -> FilePath -> TestTree
127-
extractCommandTest testExePath fp = unsafePerformIO $ do
128-
contents <- UTF8.toText <$> BS.readFile ("command" </> fp)
126+
extractCommandTest :: FilePath -> FilePath -> FilePath -> TestTree
127+
extractCommandTest root testExePath fp = unsafePerformIO $ do
128+
contents <- UTF8.toText <$> BS.readFile (root </> fp)
129129
Pandoc _ blocks <- runIOorExplode (readMarkdown
130130
def{ readerExtensions = pandocExtensions } contents)
131131
let codeblocks = map extractCode $ filter isCodeBlock blocks
132-
let cases = zipWith (runCommandTest testExePath fp) [1..] codeblocks
132+
let cases = zipWith (runCommandTest root testExePath fp) [1..] codeblocks
133133
return $ testGroup fp
134134
$ if null cases
135135
then [testCase "!!" $ assertFailure "No command tests defined"]

test/test-pandoc.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ import Text.Pandoc.Shared (inDirectory)
5454

5555
tests :: FilePath -> TestTree
5656
tests pandocPath = testGroup "pandoc tests"
57-
[ Tests.Command.tests
57+
[ Tests.Command.tests "command"
58+
, Tests.Command.tests "command/figures"
5859
, testGroup "Old" (Tests.Old.tests pandocPath)
5960
, testGroup "Shared" Tests.Shared.tests
6061
, testGroup "Writers"

0 commit comments

Comments
 (0)