From ae4a5f48584ae88fc4c812270ad9990b694f7398 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 4 Jan 2019 17:44:26 -0800 Subject: Fix findPandoc so it works with cabalv2. --- test/Tests/Helpers.hs | 31 +++++++++++++++++++++++-------- test/test-pandoc.hs | 6 +++++- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/test/Tests/Helpers.hs b/test/Tests/Helpers.hs index 1c031aa64..3a8058114 100644 --- a/test/Tests/Helpers.hs +++ b/test/Tests/Helpers.hs @@ -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 diff --git a/test/test-pandoc.hs b/test/test-pandoc.hs index dc51b73cc..63560936c 100644 --- a/test/test-pandoc.hs +++ b/test/test-pandoc.hs @@ -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 -- cgit v1.2.3