diff options
author | John MacFarlane <fiddlosopher@gmail.com> | 2013-10-20 12:36:26 -0700 |
---|---|---|
committer | John MacFarlane <fiddlosopher@gmail.com> | 2013-10-20 12:36:26 -0700 |
commit | 9d6bca06ee944c3bf056be61d075d65594963c79 (patch) | |
tree | de35dff9b39a77c1361d5bf7de49f5eb121fef4f | |
parent | 1ce875a010e1471e06338a20c82781036d476776 (diff) | |
download | pandoc-9d6bca06ee944c3bf056be61d075d65594963c79.tar.gz |
Pass the buildDir as first argument to test suite.
Allows test suite to work with cabal sandboxes.
Previously we hard-coded the build directory.
-rw-r--r-- | Setup.hs | 10 | ||||
-rw-r--r-- | tests/Tests/Old.hs | 10 | ||||
-rw-r--r-- | tests/test-pandoc.hs | 5 |
3 files changed, 18 insertions, 7 deletions
@@ -3,13 +3,15 @@ import Distribution.Simple import Distribution.Simple.PreProcess import Distribution.Simple.Setup - (copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..)) + (copyDest, copyVerbosity, fromFlag, installVerbosity, BuildFlags(..), + TestFlags(..)) import Distribution.PackageDescription (PackageDescription(..), Executable(..)) import Distribution.Simple.LocalBuildInfo (LocalBuildInfo(..), absoluteInstallDirs) import Distribution.Verbosity ( Verbosity, silent ) -import Distribution.Simple.InstallDirs (mandir, CopyDest (NoCopyDest)) +import Distribution.Simple.InstallDirs (mandir, CopyDest (NoCopyDest), toPathTemplate) import Distribution.Simple.Utils (installOrdinaryFiles, info) +import Distribution.Simple.Test (test) import Prelude hiding (catch) import System.Process ( rawSystem ) import System.FilePath ( (</>) ) @@ -20,6 +22,10 @@ main :: IO () main = do defaultMainWithHooks $ simpleUserHooks { postBuild = makeManPages + , testHook = \pkg lbi _ flags -> + -- pass build directory as first argument to test program + test pkg lbi flags{ testOptions = + toPathTemplate (buildDir lbi) : testOptions flags } , postCopy = \ _ flags pkg lbi -> installManpages pkg lbi (fromFlag $ copyVerbosity flags) (fromFlag $ copyDest flags) diff --git a/tests/Tests/Old.hs b/tests/Tests/Old.hs index 01e4403fb..a16784889 100644 --- a/tests/Tests/Old.hs +++ b/tests/Tests/Old.hs @@ -3,7 +3,7 @@ module Tests.Old (tests) where import Test.Framework (testGroup, Test ) import Test.Framework.Providers.HUnit import Test.HUnit ( assertBool ) - +import System.Environment ( getArgs ) import System.IO ( openTempFile, stderr ) import System.Process ( runProcess, waitForProcess ) import System.FilePath ( (</>), (<.>) ) @@ -22,9 +22,6 @@ import Text.Printf readFileUTF8 :: FilePath -> IO String readFileUTF8 f = B.readFile f >>= return . toStringLazy -pandocPath :: FilePath -pandocPath = ".." </> "dist" </> "build" </> "pandoc" </> "pandoc" - data TestResult = TestPassed | TestError ExitCode | TestFailed String FilePath [Diff String] @@ -209,6 +206,11 @@ testWithNormalize :: (String -> String) -- ^ Normalize function for output -> FilePath -- ^ Norm (for test results) filepath -> Test testWithNormalize normalizer testname opts inp norm = testCase testname $ do + args <- getArgs + let buildDir = case args of + (x:_) -> ".." </> x + _ -> error "test-pandoc: missing buildDir argument" + let pandocPath = buildDir </> "pandoc" </> "pandoc" (outputPath, hOut) <- openTempFile "" "pandoc-test" let inpPath = inp let normPath = norm diff --git a/tests/test-pandoc.hs b/tests/test-pandoc.hs index 67ca5eae2..ae521541a 100644 --- a/tests/test-pandoc.hs +++ b/tests/test-pandoc.hs @@ -38,4 +38,7 @@ tests = [ testGroup "Old" Tests.Old.tests main :: IO () main = do setLocaleEncoding utf8 - inDirectory "tests" $ defaultMain tests + -- we ignore command-line arguments, since we're having cabal pass + -- the build directory as first argument, and we don't want test-framework + -- to choke on that. + inDirectory "tests" $ defaultMainWithArgs tests [] |