git.iko.soy/typeable/pandoc
on master help sign in
Pass the buildDir as first argument to test suite.

Allows test suite to work with cabal sandboxes. Previously we hard-coded the build directory.

commit9d6bca06ee944c3bf056be61d075d65594963c79 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSun 20 Oct 2013, 12:36 (13 years ago) parent1ce875a
3 files changed+18−7
Setup.hs+8−2 tests/Tests/Old.hs+6−4 tests/test-pandoc.hs+4−1
Setup.hs+8−2
@@ -3,13 +3,15 @@
33import Distribution.Simple
44import Distribution.Simple.PreProcess
55import Distribution.Simple.Setup
6− (copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..))
6+ (copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..),
7+ TestFlags(..))
78import Distribution.PackageDescription (PackageDescription(..), Executable(..))
89import Distribution.Simple.LocalBuildInfo
910 (LocalBuildInfo(..), absoluteInstallDirs)
1011import Distribution.Verbosity ( Verbosity, silent )
11−import Distribution.Simple.InstallDirs (mandir, CopyDest (NoCopyDest))
12+import Distribution.Simple.InstallDirs (mandir, CopyDest (NoCopyDest), toPathTemplate)
1213import Distribution.Simple.Utils (installOrdinaryFiles, info)
14+import Distribution.Simple.Test (test)
1315import Prelude hiding (catch)
1416import System.Process ( rawSystem )
1517import System.FilePath ( (</>) )
@@ -20,6 +22,10 @@ main :: IO ()
2022main = do
2123 defaultMainWithHooks $ simpleUserHooks {
2224 postBuild = makeManPages
25+ , testHook = \pkg lbi _ flags ->
26+ -- pass build directory as first argument to test program
27+ test pkg lbi flags{ testOptions =
28+ toPathTemplate (buildDir lbi) : testOptions flags }
2329 , postCopy = \ _ flags pkg lbi ->
2430 installManpages pkg lbi (fromFlag $ copyVerbosity flags)
2531 (fromFlag $ copyDest flags)
tests/Tests/Old.hs+6−4
@@ -3,7 +3,7 @@ module Tests.Old (tests) where
33import Test.Framework (testGroup, Test )
44import Test.Framework.Providers.HUnit
55import Test.HUnit ( assertBool )
6−
6+import System.Environment ( getArgs )
77import System.IO ( openTempFile, stderr )
88import System.Process ( runProcess, waitForProcess )
99import System.FilePath ( (</>), (<.>) )
@@ -22,9 +22,6 @@ import Text.Printf
2222readFileUTF8 :: FilePath -> IO String
2323readFileUTF8 f = B.readFile f >>= return . toStringLazy
2424
25−pandocPath :: FilePath
26−pandocPath = ".." </> "dist" </> "build" </> "pandoc" </> "pandoc"
27−
2825data TestResult = TestPassed
2926 | TestError ExitCode
3027 | TestFailed String FilePath [Diff String]
@@ -209,6 +206,11 @@ testWithNormalize :: (String -> String) -- ^ Normalize function for output
209206 -> FilePath -- ^ Norm (for test results) filepath
210207 -> Test
211208testWithNormalize normalizer testname opts inp norm = testCase testname $ do
209+ args <- getArgs
210+ let buildDir = case args of
211+ (x:_) -> ".." </> x
212+ _ -> error "test-pandoc: missing buildDir argument"
213+ let pandocPath = buildDir </> "pandoc" </> "pandoc"
212214 (outputPath, hOut) <- openTempFile "" "pandoc-test"
213215 let inpPath = inp
214216 let normPath = norm
tests/test-pandoc.hs+4−1
@@ -38,4 +38,7 @@ tests = [ testGroup "Old" Tests.Old.tests
3838main :: IO ()
3939main = do
4040 setLocaleEncoding utf8
41− inDirectory "tests" $ defaultMain tests
41+ -- we ignore command-line arguments, since we're having cabal pass
42+ -- the build directory as first argument, and we don't want test-framework
43+ -- to choke on that.
44+ inDirectory "tests" $ defaultMainWithArgs tests []