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.
9import System.IO ( openTempFile, stderr )
10import Prelude hiding ( putStrLn, putStr, readFile )
11import System.Process ( runProcess, waitForProcess )
12import System.FilePath ( (</>), (<.>) )
13import System.Directory
19pandocPath = ".." </> "dist" </> "build" </> "pandoc" </> "pandoc"
21data TestResult = TestPassed
23 | TestFailed [(DI, String)]
26instance Show TestResult where
27 show TestPassed = "PASSED"
28 show (TestError ec) = "ERROR " ++ show ec
29 show (TestFailed d) = "FAILED\n" ++ showDiff d
31showDiff :: [(DI, String)] -> String
33showDiff ((F, ln) : ds) = "|TEST| " ++ ln ++ "\n" ++ showDiff ds
34showDiff ((S, ln) : ds) = "|NORM| " ++ ln ++ "\n" ++ showDiff ds
35showDiff ((B, _ ) : ds) = showDiff ds
37writerFormats :: [String]
38writerFormats = [ "native"
54 r1s <- mapM runWriterTest writerFormats
55 r2 <- runS5WriterTest "basic" ["-s"] "s5"
56 r3 <- runS5WriterTest "fancy" ["-s","-m","-i"] "s5"
57 r4 <- runS5WriterTest "fragment" [] "html"
58 r5 <- runS5WriterTest "inserts" ["-s", "-H", "insert",
59 "-B", "insert", "-A", "insert", "-c", "main.css"] "html"
60 r6 <- runTest "markdown reader" ["-r", "markdown", "-w", "native", "-s", "-S"]
61 "testsuite.txt" "testsuite.native"
62 r7 <- runTest "markdown reader (tables)" ["-r", "markdown", "-w", "native"]
63 "tables.txt" "tables.native"
64 r7a <- runTest "markdown reader (more)" ["-r", "markdown", "-w", "native"]
65 "markdown-reader-more.txt" "markdown-reader-more.native"
66 r8 <- runTest "rst reader" ["-r", "rst", "-w", "native", "-s", "-S"]
67 "rst-reader.rst" "rst-reader.native"
68 r9 <- runTest "html reader" ["-r", "html", "-w", "native", "-s"]
69 "html-reader.html" "html-reader.native"
70 r10 <- runTest "latex reader" ["-r", "latex", "-w", "native", "-s", "-R"]
71 "latex-reader.latex" "latex-reader.native"
72 r11 <- runTest "native reader" ["-r", "native", "-w", "native", "-s"]
73 "testsuite.native" "testsuite.native"
74 let results = r1s ++ [r2, r3, r4, r5, r6, r7, r7a, r8, r9, r10, r11]
77 putStrLn "\nAll tests passed."
80 let failures = length $ filter not results
81 putStrLn $ "\n" ++ show failures ++ " tests failed."
82 exitWith (ExitFailure failures)
84-- makes sure file is fully closed after reading
85readFile' :: FilePath -> IO String
86readFile' f = do s <- readFile f
87 return $! (length s `seq` s)
89runWriterTest :: String -> IO Bool
90runWriterTest format = do
91 r1 <- runTest (format ++ " writer") ["-r", "native", "-s", "-w", format] "testsuite.native" ("writer" <.> format)
92 r2 <- runTest (format ++ " writer (tables)") ["-r", "native", "-w", format] "tables.native" ("tables" <.> format)
95runS5WriterTest :: String -> [String] -> String -> IO Bool
96runS5WriterTest modifier opts format = runTest (format ++ " writer (" ++ modifier ++ ")")
97 (["-r", "native", "-w", format] ++ opts) "s5.native" ("s5." ++ modifier <.> "html")
99-- | Run a test, return True if test passed.
100runTest :: String -- ^ Title of test
101 -> [String] -- ^ Options to pass to pandoc
102 -> String -- ^ Input filepath
103 -> FilePath -- ^ Norm (for test results) filepath
105runTest testname opts inp norm = do
106 (outputPath, hOut) <- openTempFile "" "pandoc-test"
109 -- Note: COLUMNS must be set for markdown table reader
110 ph <- runProcess pandocPath (opts ++ [inpPath]) Nothing (Just [("COLUMNS", "80")]) Nothing (Just hOut) (Just stderr)
111 ec <- waitForProcess ph
112 result <- if ec == ExitSuccess
114 -- filter \r so the tests will work on Windows machines
115 outputContents <- readFile' outputPath >>= return . filter (/='\r')
116 normContents <- readFile' normPath >>= return . filter (/='\r')
117 if outputContents == normContents
118 then return TestPassed
119 else return $ TestFailed $ getDiff (lines outputContents) (lines normContents)
120 else return $ TestError ec
121 removeFile outputPath
122 putStrLn $ printf "%-28s ---> %s" testname (show result)
123 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