Fix findPandoc so it works with cabalv2.

This commit is contained in:
John MacFarlane 2019-01-04 17:44:26 -08:00
parent 577ad44350
commit ae4a5f4858
2 changed files with 28 additions and 9 deletions

View file

@ -83,14 +83,29 @@ showDiff (l,r) (Both _ _ : ds) =
findPandoc :: IO FilePath
findPandoc = do
testExePath <- getExecutablePath
let testExeDir = takeDirectory testExePath
found <- doesFileExist (testExeDir </> "pandoc")
return $ if found
then testExeDir </> "pandoc"
else case splitDirectories testExeDir of
[] -> error "test-pandoc: empty testExeDir"
xs -> joinPath (init xs) </> "pandoc" </> "pandoc"
curdir <- getCurrentDirectory
let relTestExePathParts = splitDirectories $ makeRelative curdir $
takeDirectory testExePath
let pandocPath =
(case reverse relTestExePathParts of
-- cabalv2 with --disable-optimization
"test-pandoc" : "build" : "noopt" : "test-pandoc" : "t" : ps
-> joinPath (reverse ps) </>
"x" </> "pandoc" </> "noopt" </> "build" </> "pandoc"
-- cabalv2 without --disable-optimization
"test-pandoc" : "build" : "test-pandoc" : "t" : ps
-> joinPath (reverse ps) </>
"x" </> "pandoc" </> "build" </> "pandoc"
-- cabalv1
"test-pandoc" : "build" : ps
-> joinPath (reverse ps) </> "build" </> "pandoc"
_ -> error $ "findPandoc: could not find pandoc executable")
</> "pandoc"
found <- doesFileExist pandocPath
if found
then return pandocPath
else error $ "findPandoc: could not find pandoc executable at "
++ pandocPath
vividize :: Diff String -> String
vividize (Both s _) = " " ++ s

View file

@ -40,6 +40,7 @@ import qualified Tests.Writers.Plain
import qualified Tests.Writers.Powerpoint
import qualified Tests.Writers.RST
import qualified Tests.Writers.TEI
import Tests.Helpers (findPandoc)
import Text.Pandoc.Shared (inDirectory)
tests :: TestTree
@ -86,4 +87,7 @@ tests = testGroup "pandoc tests" [ Tests.Command.tests
main :: IO ()
main = do
setLocaleEncoding utf8
inDirectory "test" $ defaultMain tests
inDirectory "test" $ do
fp <- findPandoc
putStrLn $ "Using pandoc executable at " ++ fp
defaultMain tests