git.iko.soy/typeable/pandoc
on master help sign in
Removed run prefix from all test functions.
f3ee736Nathan Gass
src/test-pandoc.hs+68−70
@@ -16,8 +16,7 @@ module Main where
16
16
17import Test.Framework (defaultMain, testGroup, Test )
17import Test.Framework (defaultMain, testGroup, Test )
18import Test.Framework.Providers.HUnit
18import Test.Framework.Providers.HUnit
19−
20−import Test.HUnit hiding ( Test )
19+import Test.HUnit ( assertBool )
21
20
22import System.IO ( openTempFile, stderr )
21import System.IO ( openTempFile, stderr )
23import System.Process ( runProcess, waitForProcess )
22import System.Process ( runProcess, waitForProcess )
@@ -52,64 +51,53 @@ showDiff ((F, ln) : ds) = "|TEST| " ++ ln ++ "\n" ++ showDiff ds
52showDiff ((S, ln) : ds) = "|NORM| " ++ ln ++ "\n" ++ showDiff ds
51showDiff ((S, ln) : ds) = "|NORM| " ++ ln ++ "\n" ++ showDiff ds
53showDiff ((B, _ ) : ds) = showDiff ds
52showDiff ((B, _ ) : ds) = showDiff ds
54
53
55−markdownCitationTest :: Test
56−markdownCitationTest
57− = testGroup "citations" $ map styleToTest ["chicago-author-date","ieee","mhra"]
58− ++ [runTest "no-citeproc" wopts "markdown-citations.txt" "markdown-citations.txt"]
59− where
60− ropts = ["-r", "markdown", "-w", "markdown", "--bibliography", "biblio.bib", "--no-wrap"]
61− wopts = ropts ++ ["--no-citeproc"]
62− styleToTest style = runTest style (ropts ++ ["--csl", style ++ ".csl"])
63− "markdown-citations.txt" ("markdown-citations." ++ style ++ ".txt")
64−
65−
66tests :: [Test]
54tests :: [Test]
67−tests = [ testGroup "markdown" [ testGroup "writer" (runWriterTests "markdown" ++ runLhsWriterTests "markdown")
55+tests = [ testGroup "markdown" [ testGroup "writer" (writerTests "markdown" ++ lhsWriterTests "markdown")
68− , testGroup "reader" [ runTest "basic" ["-r", "markdown", "-w", "native", "-s", "-S"]
56+ , testGroup "reader" [ test "basic" ["-r", "markdown", "-w", "native", "-s", "-S"]
69 "testsuite.txt" "testsuite.native"
57 "testsuite.txt" "testsuite.native"
70− , runTest "tables" ["-r", "markdown", "-w", "native"]
58+ , test "tables" ["-r", "markdown", "-w", "native"]
71 "tables.txt" "tables.native"
59 "tables.txt" "tables.native"
72− , runTest "more" ["-r", "markdown", "-w", "native", "-S"]
60+ , test "more" ["-r", "markdown", "-w", "native", "-S"]
73 "markdown-reader-more.txt" "markdown-reader-more.native"
61 "markdown-reader-more.txt" "markdown-reader-more.native"
74− , runLhsReaderTest "markdown+lhs"
62+ , lhsReaderTest "markdown+lhs"
75 ]
63 ]
76− , markdownCitationTest
64+ , testGroup "citations" markdownCitationTests
77 ]
65 ]
78− , testGroup "rst" [ testGroup "writer" (runWriterTests "rst" ++ runLhsWriterTests "rst")
66+ , testGroup "rst" [ testGroup "writer" (writerTests "rst" ++ lhsWriterTests "rst")
79− , testGroup "reader" [ runTest "basic" ["-r", "rst", "-w", "native", "-s", "-S"]
67+ , testGroup "reader" [ test "basic" ["-r", "rst", "-w", "native", "-s", "-S"]
80 "rst-reader.rst" "rst-reader.native"
68 "rst-reader.rst" "rst-reader.native"
81− , runTest "tables" ["-r", "rst", "-w", "native"]
69+ , test "tables" ["-r", "rst", "-w", "native"]
82 "tables.rst" "tables-rstsubset.native"
70 "tables.rst" "tables-rstsubset.native"
83− , runLhsReaderTest "rst+lhs"
71+ , lhsReaderTest "rst+lhs"
84 ]
72 ]
85 ]
73 ]
86− , testGroup "latex" [ testGroup "writer" (runWriterTests "latex" ++ runLhsWriterTests "latex")
74+ , testGroup "latex" [ testGroup "writer" (writerTests "latex" ++ lhsWriterTests "latex")
87− , testGroup "reader" [ runTest "basic" ["-r", "latex", "-w", "native", "-s", "-R"]
75+ , testGroup "reader" [ test "basic" ["-r", "latex", "-w", "native", "-s", "-R"]
88 "latex-reader.latex" "latex-reader.native"
76 "latex-reader.latex" "latex-reader.native"
89− , runLhsReaderTest "latex+lhs"
77+ , lhsReaderTest "latex+lhs"
90 ]
78 ]
91− , runLatexCitationTests "biblatex"
79+ , latexCitationTests "biblatex"
92− , runLatexCitationTests "natbib"
80+ , latexCitationTests "natbib"
93 ]
81 ]
94− , testGroup "html" [ testGroup "writer" (runWriterTests "html" ++ runLhsWriterTests "html")
82+ , testGroup "html" [ testGroup "writer" (writerTests "html" ++ lhsWriterTests "html")
95− , runTest "reader" ["-r", "html", "-w", "native", "-s"]
83+ , test "reader" ["-r", "html", "-w", "native", "-s"]
96 "html-reader.html" "html-reader.native"
84 "html-reader.html" "html-reader.native"
97 ]
85 ]
98− , testGroup "s5" [ runS5WriterTest "basic" ["-s"] "s5"
86+ , testGroup "s5" [ s5WriterTest "basic" ["-s"] "s5"
99− , runS5WriterTest "fancy" ["-s","-m","-i"] "s5"
87+ , s5WriterTest "fancy" ["-s","-m","-i"] "s5"
100− , runS5WriterTest "fragment" [] "html"
88+ , s5WriterTest "fragment" [] "html"
101− , runS5WriterTest "inserts" ["-s", "-H", "insert",
89+ , s5WriterTest "inserts" ["-s", "-H", "insert",
102 "-B", "insert", "-A", "insert", "-c", "main.css"] "html"
90 "-B", "insert", "-A", "insert", "-c", "main.css"] "html"
103 ]
91 ]
104− , testGroup "textile" [ testGroup "writer" $ runWriterTests "textile"
92+ , testGroup "textile" [ testGroup "writer" $ writerTests "textile"
105− , runTest "reader" ["-r", "textile", "-w", "native", "-s"]
93+ , test "reader" ["-r", "textile", "-w", "native", "-s"]
106 "textile-reader.textile" "textile-reader.native"
94 "textile-reader.textile" "textile-reader.native"
107 ]
95 ]
108− , testGroup "native" [ testGroup "writer" $ runWriterTests "native"
96+ , testGroup "native" [ testGroup "writer" $ writerTests "native"
109− , runTest "reader" ["-r", "native", "-w", "native", "-s"]
97+ , test "reader" ["-r", "native", "-w", "native", "-s"]
110 "testsuite.native" "testsuite.native"
98 "testsuite.native" "testsuite.native"
111 ]
99 ]
112− , testGroup "other writers" $ map (\f -> testGroup f $ runWriterTests f)
100+ , testGroup "other writers" $ map (\f -> testGroup f $ writerTests f)
113 [ "docbook", "opendocument" , "context" , "texinfo"
101 [ "docbook", "opendocument" , "context" , "texinfo"
114 , "man" , "plain" , "mediawiki", "rtf", "org"
102 , "man" , "plain" , "mediawiki", "rtf", "org"
115 ]
103 ]
@@ -123,63 +111,73 @@ readFile' :: FilePath -> IO String
123readFile' f = do s <- readFileUTF8 f
111readFile' f = do s <- readFileUTF8 f
124 return $! (length s `seq` s)
112 return $! (length s `seq` s)
125
113
126−runLhsWriterTests :: String -> [Test]
114+lhsWriterTests :: String -> [Test]
127−runLhsWriterTests format
115+lhsWriterTests format
128 = [ t "lhs to normal" format
116 = [ t "lhs to normal" format
129 , t "lhs to lhs" (format ++ "+lhs")
117 , t "lhs to lhs" (format ++ "+lhs")
130 ]
118 ]
131 where
119 where
132− t n f = runTest n ["--columns=78", "-r", "native", "-s", "-w", f]
120+ t n f = test n ["--columns=78", "-r", "native", "-s", "-w", f]
133 "lhs-test.native" ("lhs-test" <.> f)
121 "lhs-test.native" ("lhs-test" <.> f)
134
122
135−runLhsReaderTest :: String -> Test
123+lhsReaderTest :: String -> Test
136−runLhsReaderTest format =
124+lhsReaderTest format =
137− runTest "lhs" ["-r", format, "-w", "html+lhs"] ("lhs-test" <.> format) "lhs-test.fragment.html+lhs"
125+ test "lhs" ["-r", format, "-w", "html+lhs"] ("lhs-test" <.> format) "lhs-test.fragment.html+lhs"
138
126
139
127
140−runLatexCitationTests :: String -> Test
128+latexCitationTests :: String -> Test
141−runLatexCitationTests n
129+latexCitationTests n
142 = testGroup (n ++ " citations")
130 = testGroup (n ++ " citations")
143− [ rt ("latex reader (" ++ n ++ " citations)") (["-r", "latex", "-w", "markdown", "-s", "--no-wrap"] ++ o)
131+ [ t ("latex reader (" ++ n ++ " citations)") (["-r", "latex", "-w", "markdown", "-s", "--no-wrap"] ++ o)
144 f "markdown-citations.txt"
132 f "markdown-citations.txt"
145− , rt ("latex writer (" ++ n ++ " citations)") (["-r", "markdown", "-w", "latex", "-s", "--no-wrap"] ++ o)
133+ , t ("latex writer (" ++ n ++ " citations)") (["-r", "markdown", "-w", "latex", "-s", "--no-wrap"] ++ o)
146 "markdown-citations.txt" f
134 "markdown-citations.txt" f
147 ]
135 ]
148 where
136 where
149 o = ["--bibliography", "biblio.bib", "--csl", "chicago-author-date.csl", "--no-citeproc", "--" ++ n]
137 o = ["--bibliography", "biblio.bib", "--csl", "chicago-author-date.csl", "--no-citeproc", "--" ++ n]
150 f = n ++ "-citations.latex"
138 f = n ++ "-citations.latex"
151 normalize = substitute "\160" " " . substitute "\8211" "-"
139 normalize = substitute "\160" " " . substitute "\8211" "-"
152− rt = runTestWithNormalize normalize
140+ t = testWithNormalize normalize
153
141
154−runWriterTests :: String -> [Test]
142+writerTests :: String -> [Test]
155−runWriterTests format
143+writerTests format
156− = [ runTest "basic" (opts ++ ["-s"]) "testsuite.native" ("writer" <.> format)
144+ = [ test "basic" (opts ++ ["-s"]) "testsuite.native" ("writer" <.> format)
157− , runTest "tables" opts "tables.native" ("tables" <.> format)
145+ , test "tables" opts "tables.native" ("tables" <.> format)
158 ]
146 ]
159 where
147 where
160 opts = ["-r", "native", "-w", format, "--columns=78"]
148 opts = ["-r", "native", "-w", format, "--columns=78"]
161
149
162−runS5WriterTest :: String -> [String] -> String -> Test
150+s5WriterTest :: String -> [String] -> String -> Test
163−runS5WriterTest modifier opts format = runTest (format ++ " writer (" ++ modifier ++ ")")
151+s5WriterTest modifier opts format
152+ = test (format ++ " writer (" ++ modifier ++ ")") (["-r", "native", "-w", format] ++ opts)
164− (["-r", "native", "-w", format] ++ opts) "s5.native" ("s5." ++ modifier <.> "html")
153+ "s5.native" ("s5." ++ modifier <.> "html")
165
154
155+markdownCitationTests :: [Test]
156+markdownCitationTests
157+ = map styleToTest ["chicago-author-date","ieee","mhra"]
158+ ++ [test "no-citeproc" wopts "markdown-citations.txt" "markdown-citations.txt"]
159+ where
160+ ropts = ["-r", "markdown", "-w", "markdown", "--bibliography", "biblio.bib", "--no-wrap"]
161+ wopts = ropts ++ ["--no-citeproc"]
162+ styleToTest style = test style (ropts ++ ["--csl", style ++ ".csl"])
163+ "markdown-citations.txt" ("markdown-citations." ++ style ++ ".txt")
166
164
167-- | Run a test without normalize function, return True if test passed.
165-- | Run a test without normalize function, return True if test passed.
168−runTest :: String -- ^ Title of test
166+test :: String -- ^ Title of test
169− -> [String] -- ^ Options to pass to pandoc
167+ -> [String] -- ^ Options to pass to pandoc
170− -> String -- ^ Input filepath
168+ -> String -- ^ Input filepath
171− -> FilePath -- ^ Norm (for test results) filepath
169+ -> FilePath -- ^ Norm (for test results) filepath
172− -> Test
170+ -> Test
173−runTest = runTestWithNormalize id
171+test = testWithNormalize id
174
172
175-- | Run a test with normalize function, return True if test passed.
173-- | Run a test with normalize function, return True if test passed.
176−runTestWithNormalize :: (String -> String) -- ^ Normalize function for output
174+testWithNormalize :: (String -> String) -- ^ Normalize function for output
177− -> String -- ^ Title of test
175+ -> String -- ^ Title of test
178− -> [String] -- ^ Options to pass to pandoc
176+ -> [String] -- ^ Options to pass to pandoc
179− -> String -- ^ Input filepath
177+ -> String -- ^ Input filepath
180− -> FilePath -- ^ Norm (for test results) filepath
178+ -> FilePath -- ^ Norm (for test results) filepath
181− -> Test
179+ -> Test
182−runTestWithNormalize normalize testname opts inp norm = testCase testname $ do
180+testWithNormalize normalize testname opts inp norm = testCase testname $ do
183 (outputPath, hOut) <- openTempFile "" "pandoc-test"
181 (outputPath, hOut) <- openTempFile "" "pandoc-test"
184 let inpPath = inp
182 let inpPath = inp
185 let normPath = norm
183 let normPath = norm