@@ -1,4 +1,5 @@
11{-# LANGUAGE CPP #-}
2+{-# LANGUAGE TupleSections #-}
23{-# LANGUAGE FlexibleInstances #-}
34{- |
45 Module : Tests.Helpers
@@ -13,6 +14,7 @@ Utility functions for the test suite.
1314-}
1415module Tests.Helpers ( test
1516 , TestResult(..)
17+ , setupEnvironment
1618 , showDiff
1719 , (=?>)
1820 , purely
@@ -25,6 +27,8 @@ import Data.Algorithm.Diff
2527import qualified Data.Map as M
2628import Data.Text (Text, unpack)
2729import System.Exit
30+import System.FilePath (takeDirectory)
31+import qualified System.Environment as Env
2832import Test.Tasty
2933import Test.Tasty.HUnit
3034import Text.Pandoc.Builder (Blocks, Inlines, doc, plain)
@@ -57,6 +61,25 @@ test fn name (input, expected) =
5761 dashes "" = replicate 72 '-'
5862 dashes x = replicate (72 - length x - 5) '-' ++ " " ++ x ++ " ---"
5963
64+-- | Set up environment for pandoc command tests.
65+setupEnvironment :: FilePath -> IO [(String, String)]
66+setupEnvironment testExePath = do
67+ mldpath <- Env.lookupEnv "LD_LIBRARY_PATH"
68+ mdyldpath <- Env.lookupEnv "DYLD_LIBRARY_PATH"
69+ mpdd <- Env.lookupEnv "pandoc_datadir"
70+ -- Note that Cabal sets the pandoc_datadir environment variable
71+ -- to point to the source directory, since otherwise getDataFilename
72+ -- will look in the data directory into which pandoc will be installed
73+ -- (but has not yet been). So when we spawn a new process with
74+ -- pandoc, we need to make sure this environment variable is set.
75+ return $ ("PATH",takeDirectory testExePath) :
76+ ("TMP",".") :
77+ ("LANG","en_US.UTF-8") :
78+ ("HOME", "./") :
79+ maybe [] ((:[]) . ("pandoc_datadir",)) mpdd ++
80+ maybe [] ((:[]) . ("LD_LIBRARY_PATH",)) mldpath ++
81+ maybe [] ((:[]) . ("DYLD_LIBRARY_PATH",)) mdyldpath
82+
6083data TestResult = TestPassed
6184 | TestError ExitCode
6285 | TestFailed String FilePath [Diff String]