git.iko.soy/typeable/pandoc
on master help sign in
Removed special testHook from Setup.

This was just too fragile and dependent on a changing Cabal API (see #1526). Instead of passing the bulid directory to the test program, we now let the test program find itself (using executable-path) and then find the pandoc executable relative to itself.

commit1d6e1cf9f3d45147538aee639e00a3ae95260055 authorJohn MacFarlane <jgm@berkeley.edu> dateWed 13 Aug 2014, 08:12 (12 years ago) parent22ab336
3 files changed+13−11
Setup.hs−4 pandoc.cabal+1 tests/Tests/Old.hs+12−7
Setup.hs−4
@@ -38,10 +38,6 @@ main :: IO ()
3838main = do
3939 defaultMainWithHooks $ simpleUserHooks {
4040 postBuild = makeManPages
41− , testHook = \pkg lbi _ flags ->
42− -- pass build directory as first argument to test program
43− test pkg lbi flags{ testOptions =
44− toPathTemplate (buildDir lbi) : testOptions flags }
4541 , postCopy = \ _ flags pkg lbi ->
4642 installManpages pkg lbi (fromFlag $ copyVerbosity flags)
4743 (fromFlag $ copyDest flags)
pandoc.cabal+1
@@ -406,6 +406,7 @@ Test-Suite test-pandoc
406406 HUnit >= 1.2 && < 1.3,
407407 containers >= 0.1 && < 0.6,
408408 ansi-terminal >= 0.5 && < 0.7,
409+ executable-path >= 0.0 && < 0.1,
409410 zip-archive >= 0.2.3.4 && < 0.3
410411 Other-Modules: Tests.Old
411412 Tests.Helpers
tests/Tests/Old.hs+12−7
@@ -3,10 +3,10 @@ module Tests.Old (tests) where
33import Test.Framework (testGroup, Test )
44import Test.Framework.Providers.HUnit
55import Test.HUnit ( assertBool )
6−import System.Environment ( getArgs )
6+import System.Environment.Executable (getExecutablePath)
77import System.IO ( openTempFile, stderr )
88import System.Process ( runProcess, waitForProcess )
9−import System.FilePath ( (</>), (<.>) )
9+import System.FilePath ( (</>), (<.>), takeDirectory )
1010import System.Directory
1111import System.Exit
1212import Data.Algorithm.Diff
@@ -225,11 +225,16 @@ testWithNormalize :: (String -> String) -- ^ Normalize function for output
225225 -> FilePath -- ^ Norm (for test results) filepath
226226 -> Test
227227testWithNormalize normalizer testname opts inp norm = testCase testname $ do
228− args <- getArgs
229− let buildDir = case args of
230− (x:_) -> ".." </> x
231− _ -> error "test-pandoc: missing buildDir argument"
232− let pandocPath = buildDir </> "pandoc" </> "pandoc"
228+ -- find pandoc executable relative to test-pandoc
229+ -- First, try in same directory (e.g. if both in ~/.cabal/bin)
230+ -- Second, try ../pandoc (e.g. if in dist/XXX/build/test-pandoc)
231+ pandocPath <- do
232+ testExePath <- getExecutablePath
233+ let testExeDir = takeDirectory testExePath
234+ found <- doesFileExist (testExeDir </> "pandoc")
235+ return $ if found
236+ then testExeDir </> "pandoc"
237+ else testExeDir </> ".." </> "pandoc" </> "pandoc"
233238 (outputPath, hOut) <- openTempFile "" "pandoc-test"
234239 let inpPath = inp
235240 let normPath = norm