1{-# OPTIONS_GHC -Wall #-}
2-- RunTests.hs - run test suite for pandoc
3-- This script is designed to be run from the tests directory.
4-- It assumes the pandoc executable is in dist/build/pandoc.
6-- runhaskell -i.. RunTests.hs [lhs]
8-- If the lhs argument is provided, tests for lhs support will be
9-- run. These presuppose that pandoc has been compiled with the
10-- -fhighlighting flag, so these tests are not run by default.
12-- This program assumes that the Diff package has been installed:
16import System.IO ( openTempFile, stderr, stdout, hFlush )
17import System.Process ( runProcess, waitForProcess )
18import System.FilePath ( (</>), (<.>) )
19import System.Directory
20import System.Environment
23import Data.Algorithm.Diff
24import Prelude hiding ( readFile )
25import qualified Data.ByteString.Lazy as B
26import Data.ByteString.Lazy.UTF8 (toString, fromString)
28readFileUTF8 :: FilePath -> IO String
29readFileUTF8 f = B.readFile f >>= return . toString
32pandocPath = ".." </> "dist" </> "build" </> "pandoc" </> "pandoc"
34data TestResult = TestPassed
36 | TestFailed [(DI, String)]
39instance Show TestResult where
40 show TestPassed = "PASSED"
41 show (TestError ec) = "ERROR " ++ show ec
42 show (TestFailed d) = "FAILED\n" ++ showDiff d
44showDiff :: [(DI, String)] -> String
46showDiff ((F, ln) : ds) = "|TEST| " ++ ln ++ "\n" ++ showDiff ds
47showDiff ((S, ln) : ds) = "|NORM| " ++ ln ++ "\n" ++ showDiff ds
48showDiff ((B, _ ) : ds) = showDiff ds
50writerFormats :: [String]
51writerFormats = [ "native"
66lhsWriterFormats :: [String]
67lhsWriterFormats = [ "markdown"
77lhsReaderFormats :: [String]
78lhsReaderFormats = [ "markdown+lhs"
86 let runLhsTests = "lhs" `elem` args
87 r1s <- mapM runWriterTest writerFormats
88 r2 <- runS5WriterTest "basic" ["-s"] "s5"
89 r3 <- runS5WriterTest "fancy" ["-s","-m","-i"] "s5"
90 r4 <- runS5WriterTest "fragment" [] "html"
91 r5 <- runS5WriterTest "inserts" ["-s", "-H", "insert",
92 "-B", "insert", "-A", "insert", "-c", "main.css"] "html"
93 r6 <- runTest "markdown reader" ["-r", "markdown", "-w", "native", "-s", "-S"]
94 "testsuite.txt" "testsuite.native"
95 r7 <- runTest "markdown reader (tables)" ["-r", "markdown", "-w", "native"]
96 "tables.txt" "tables.native"
97 r7a <- runTest "markdown reader (more)" ["-r", "markdown", "-w", "native"]
98 "markdown-reader-more.txt" "markdown-reader-more.native"
99 r8 <- runTest "rst reader" ["-r", "rst", "-w", "native", "-s", "-S"]
100 "rst-reader.rst" "rst-reader.native"
101 r8a <- runTest "rst reader (tables)" ["-r", "rst", "-w", "native"]
102 "tables.rst" "tables-rstsubset.native"
103 r9 <- runTest "html reader" ["-r", "html", "-w", "native", "-s"]
104 "html-reader.html" "html-reader.native"
105 r10 <- runTest "latex reader" ["-r", "latex", "-w", "native", "-s", "-R"]
106 "latex-reader.latex" "latex-reader.native"
107 r11 <- runTest "native reader" ["-r", "native", "-w", "native", "-s"]
108 "testsuite.native" "testsuite.native"
109 r14s <- mapM (\style -> runTest ("markdown reader (citations) (" ++ style ++ ")") ["-r", "markdown", "-w", "html", "--bibliography", "biblio.bib", "--csl", style ++ ".csl"] "markdown-citations.txt" ("markdown-citations." ++ style ++ ".html")) ["chicago-author-date","ieee","mhra"]
110 r12s <- if runLhsTests
111 then mapM runLhsWriterTest lhsWriterFormats
112 else putStrLn "Skipping lhs writer tests because they presuppose highlighting support" >> return []
113 r13s <- if runLhsTests
114 then mapM runLhsReaderTest lhsReaderFormats
115 else putStrLn "Skipping lhs reader tests because they presuppose highlighting support" >> return []
118 [ r2, r3, r4, r5 -- S5
119 , r6, r7, r7a -- markdown reader
124 ] ++ r12s ++ r13s ++ r14s
127 putStrLn "\nAll tests passed."
130 let failures = length $ filter not results
131 putStrLn $ "\n" ++ show failures ++ " tests failed."
132 exitWith (ExitFailure failures)
134-- makes sure file is fully closed after reading
135readFile' :: FilePath -> IO String
136readFile' f = do s <- readFileUTF8 f
137 return $! (length s `seq` s)
139runLhsWriterTest :: String -> IO Bool
140runLhsWriterTest format =
141 runTest ("(lhs) " ++ format ++ " writer") ["-r", "native", "-s", "-w", format] "lhs-test.native" ("lhs-test" <.> format)
143runLhsReaderTest :: String -> IO Bool
144runLhsReaderTest format =
145 runTest ("(lhs) " ++ format ++ " reader") ["-r", format, "-w", "html+lhs"] ("lhs-test" <.> format) "lhs-test.fragment.html+lhs"
147runWriterTest :: String -> IO Bool
148runWriterTest format = do
149 r1 <- runTest (format ++ " writer") ["-r", "native", "-s", "-w", format] "testsuite.native" ("writer" <.> format)
150 r2 <- runTest (format ++ " writer (tables)") ["-r", "native", "-w", format] "tables.native" ("tables" <.> format)
153runS5WriterTest :: String -> [String] -> String -> IO Bool
154runS5WriterTest modifier opts format = runTest (format ++ " writer (" ++ modifier ++ ")")
155 (["-r", "native", "-w", format] ++ opts) "s5.native" ("s5." ++ modifier <.> "html")
157-- | Run a test, return True if test passed.
158runTest :: String -- ^ Title of test
159 -> [String] -- ^ Options to pass to pandoc
160 -> String -- ^ Input filepath
161 -> FilePath -- ^ Norm (for test results) filepath
163runTest testname opts inp norm = do
164 putStr $ printf "%-28s ---> " testname
165 (outputPath, hOut) <- openTempFile "" "pandoc-test"
169 -- Note: COLUMNS must be set for markdown table reader
170 ph <- runProcess pandocPath (opts ++ [inpPath] ++ ["--data-dir", ".."]) Nothing
171 (Just [("LANG","en_US.UTF-8"),("COLUMNS", "80"),("HOME", "./")]) Nothing (Just hOut) (Just stderr)
172 ec <- waitForProcess ph
173 result <- if ec == ExitSuccess
175 -- filter \r so the tests will work on Windows machines
176 outputContents <- readFile' outputPath >>= return . filter (/='\r')
177 normContents <- readFile' normPath >>= return . filter (/='\r')
178 if outputContents == normContents
179 then return TestPassed
180 else return $ TestFailed $ getDiff (lines outputContents) (lines normContents)
181 else return $ TestError ec
182 removeFile outputPath
183 B.putStrLn (fromString $ show result)
184 return (result == TestPassed)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list