git.iko.soy/typeable/pandoc
on master help sign in
Old tests: remove need for temp files by using pipeProcess.
commitfdf7f07f6269238dacae7dc90068f64d4666367e authorJohn MacFarlane <jgm@berkeley.edu> dateThu 31 Jan 2019, 17:25 (8 years ago) parent4e6ef53
1 file changed+6−16
test/Tests/Old.hs+6−16
test/Tests/Old.hs+6−16
@@ -6,8 +6,7 @@ import Data.Algorithm.Diff
66import Prelude hiding (readFile)
77import System.Exit
88import System.FilePath (joinPath, splitDirectories, (<.>), (</>))
9−import System.IO.Temp (withTempFile)
10−import System.Process (runProcess, waitForProcess)
9+import Text.Pandoc.Process (pipeProcess)
1110import Test.Tasty (TestTree, testGroup)
1211import Test.Tasty.Golden.Advanced (goldenTest)
1312import Tests.Helpers hiding (test)
@@ -250,9 +249,7 @@ testWithNormalize normalizer testname opts inp norm =
250249 goldenTest testname getExpected getActual
251250 (compareValues norm options) updateGolden
252251 where getExpected = normalizer <$> readFile' norm
253− getActual =
254− withTempFile "." "pandoc-test" $ \outputPath hOut -> do
255− withTempFile "." "pandoc-test" $ \errorPath hErr -> do
252+ getActual = do
256253 pandocPath <- findPandoc
257254 let mbDynlibDir = findDynlibDir (reverse $
258255 splitDirectories pandocPath)
@@ -263,19 +260,12 @@ testWithNormalize normalizer testname opts inp norm =
263260 let env = dynlibEnv ++
264261 [("TMP","."),("LANG","en_US.UTF-8"),("HOME", "./"),
265262 ("pandoc_datadir","..")]
266− ph <- runProcess pandocPath options Nothing
267− (Just env) Nothing (Just hOut) (Just hErr)
268− ec <- waitForProcess ph
263+ (ec, out) <- pipeProcess (Just env) pandocPath options mempty
269264 if ec == ExitSuccess
270− then
265+ then return $ filter (/='\r') . normalizer
266+ $ UTF8.toStringLazy out
271267 -- filter \r so the tests will work on Windows machines
272− (filter (/='\r') . normalizer) <$> readFile' outputPath
273− else do
274− errcontents <- UTF8.readFile errorPath
275− fail $ "Pandoc failed with " ++ show ec ++
276− if null errcontents
277− then ""
278− else '\n':errcontents
268+ else fail $ "Pandoc failed with error code " ++ show ec
279269 updateGolden = UTF8.writeFile norm
280270 options = ["--quiet"] ++ [inp] ++ opts
281271