From 38578ad06cca916cefebe11066622b7e60f305e8 Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Mon, 14 Aug 2017 13:02:34 -0700
Subject: [PATCH] Test fixes so we can find data files.

In old tests & command tests, we now set the environment variable
pandoc_datadir.

In lua tests, we set the datadir explicitly.
---
 test/Tests/Command.hs | 5 ++---
 test/Tests/Lua.hs     | 4 ++--
 test/Tests/Old.hs     | 5 +++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/test/Tests/Command.hs b/test/Tests/Command.hs
index 95fb69ef0..608b00b18 100644
--- a/test/Tests/Command.hs
+++ b/test/Tests/Command.hs
@@ -25,7 +25,6 @@ runTest :: String    -- ^ Title of test
         -> String    -- ^ Expected output
         -> TestTree
 runTest testname pandocpath cmd inp norm = testCase testname $ do
-  let cmd' = cmd ++ " --data-dir ../data"
   let findDynlibDir []           = Nothing
       findDynlibDir ("build":xs) = Just $ joinPath (reverse xs) </> "build"
       findDynlibDir (_:xs)       = findDynlibDir xs
@@ -35,8 +34,8 @@ runTest testname pandocpath cmd inp norm = testCase testname $ do
                        Nothing  -> []
                        Just d   -> [("DYLD_LIBRARY_PATH", d),
                                     ("LD_LIBRARY_PATH", d)]
-  let env' = dynlibEnv ++ [("PATH",takeDirectory pandocpath),("TMP","."),("LANG","en_US.UTF-8"),("HOME", "./")]
-  let pr = (shell cmd'){ env = Just env' }
+  let env' = dynlibEnv ++ [("PATH",takeDirectory pandocpath),("TMP","."),("LANG","en_US.UTF-8"),("HOME", "./"),("pandoc_datadir", "..")]
+  let pr = (shell cmd){ env = Just env' }
   (ec, out', err') <- readCreateProcessWithExitCode pr inp
   -- filter \r so the tests will work on Windows machines
   let out = filter (/= '\r') $ err' ++ out'
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index 8cbda996a..895b93775 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -68,7 +68,7 @@ tests = map (localOption (QuickCheckTests 20))
 
 assertFilterConversion :: String -> FilePath -> Pandoc -> Pandoc -> Assertion
 assertFilterConversion msg filterPath docIn docExpected = do
-  docRes <- runLuaFilter Nothing ("lua" </> filterPath) [] docIn
+  docRes <- runLuaFilter (Just "../data") ("lua" </> filterPath) [] docIn
   assertEqual msg docExpected docRes
 
 roundtripEqual :: (Eq a, FromLuaStack a, ToLuaStack a) => a -> IO Bool
@@ -77,7 +77,7 @@ roundtripEqual x = (x ==) <$> roundtripped
   roundtripped :: (FromLuaStack a, ToLuaStack a) => IO a
   roundtripped = runLua $ do
     openlibs
-    pushPandocModule Nothing
+    pushPandocModule (Just "../data")
     setglobal "pandoc"
     oldSize <- gettop
     push x
diff --git a/test/Tests/Old.hs b/test/Tests/Old.hs
index c4dd4d322..27bb20b4b 100644
--- a/test/Tests/Old.hs
+++ b/test/Tests/Old.hs
@@ -238,7 +238,8 @@ testWithNormalize normalizer testname opts inp norm =
                                    Just d   -> [("DYLD_LIBRARY_PATH", d),
                                                 ("LD_LIBRARY_PATH", d)]
               let env = dynlibEnv ++
-                        [("TMP","."),("LANG","en_US.UTF-8"),("HOME", "./")]
+                        [("TMP","."),("LANG","en_US.UTF-8"),("HOME", "./"),
+                         ("pandoc_datadir","..")]
               ph <- runProcess pandocPath options Nothing
                     (Just env) Nothing (Just hOut) (Just hErr)
               ec <- waitForProcess ph
@@ -253,7 +254,7 @@ testWithNormalize normalizer testname opts inp norm =
                               then ""
                               else '\n':errcontents
         updateGolden = UTF8.writeFile norm
-        options = ["--quiet", "--data-dir", ".." </> "data"] ++ [inp] ++ opts
+        options = ["--quiet"] ++ [inp] ++ opts
 
 compareValues :: FilePath -> [String] -> String -> String -> IO (Maybe String)
 compareValues norm options expected actual = do