Added 'tests' Cabal flag.

+ This ensures that test-pandoc gets built.
+ 'cabal test' now runs this.
+ The old tests/RunTests.hs has been removed, and
  src/test-pandoc.hs added.
This commit is contained in:
John MacFarlane 2010-12-15 17:52:35 -08:00
parent 63cf37a9ca
commit 605648cbbf
3 changed files with 37 additions and 16 deletions

View file

@ -9,8 +9,8 @@ import Distribution.Verbosity ( Verbosity, silent )
import Distribution.Simple.InstallDirs (mandir, bindir, CopyDest (NoCopyDest))
import Distribution.Simple.Utils (copyFiles)
import Control.Exception ( bracket_ )
import Control.Monad ( unless )
import System.Process ( runCommand, runProcess, waitForProcess )
import Control.Monad ( unless, when )
import System.Process ( rawSystem, runCommand, runProcess, waitForProcess )
import System.FilePath ( (</>), (<.>) )
import System.Directory
import System.IO ( stderr )
@ -38,13 +38,20 @@ main = do
-- | Run test suite.
runTestSuite :: Args -> Bool -> PackageDescription -> LocalBuildInfo -> IO a
runTestSuite _ _ pkg _ = do
let isHighlightingKate (Dependency (PackageName "highlighting-kate") _) = True
isHighlightingKate _ = False
let highlightingSupport = any isHighlightingKate $ buildDepends pkg
let testArgs = ["lhs" | highlightingSupport]
let testCmd = "runhaskell -i.. RunTests.hs " ++ unwords testArgs
inDirectory "tests" $ runCommand testCmd >>= waitForProcess >>= exitWith
runTestSuite _ _ pkg lbi = do
let testDir = buildDir lbi </> "test-pandoc"
testDir' <- canonicalizePath testDir
if any id [buildable (buildInfo exe) | exe <- executables pkg, exeName exe == "test-pandoc"]
then do
let isHighlightingKate (Dependency (PackageName "highlighting-kate") _) = True
isHighlightingKate _ = False
let highlightingSupport = any isHighlightingKate $ buildDepends pkg
let testArgs = ["lhs" | highlightingSupport]
inDirectory "tests" $ rawSystem (testDir' </> "test-pandoc")
testArgs >>= exitWith
else do
putStrLn "Build pandoc with the 'tests' flag to run tests"
exitWith $ ExitFailure 3
-- | Build man pages from markdown sources in man/man1/.
makeManPages :: Args -> BuildFlags -> PackageDescription -> LocalBuildInfo -> IO ()

View file

@ -74,7 +74,7 @@ Extra-Source-Files:
-- code to create pandoc.1 man page
MakeManPage.hs,
manpage.template,
-- benchmarking
-- benchmarks
Benchmark.hs,
-- tests
tests/bodybg.gif,
@ -136,8 +136,7 @@ Extra-Source-Files:
tests/lhs-test.latex+lhs,
tests/lhs-test.html,
tests/lhs-test.html+lhs,
tests/lhs-test.fragment.html+lhs,
tests/RunTests.hs
tests/lhs-test.fragment.html+lhs
Extra-Tmp-Files: man/man1/pandoc.1, man/man1/markdown2pdf.1
Flag threaded
@ -155,6 +154,12 @@ Flag library
Flag wrappers
Description: Build the wrappers (markdown2pdf).
Default: True
Flag tests
Description: Build test-pandoc.
Default: False
Flag benchmarks
Description: Build benchmark-pandoc.
Default: False
Library
-- Note: the following material must be in both Library and Executable stanzas.
@ -261,9 +266,9 @@ Executable pandoc
Main-Is: pandoc.hs
if flag(executable) || flag(wrappers)
Buildable: True
Buildable: True
else
Buildable: False
Buildable: False
Executable markdown2pdf
Hs-Source-Dirs: src
@ -275,7 +280,16 @@ Executable markdown2pdf
Ghc-Prof-Options: -auto-all
Extensions: CPP
if flag(wrappers)
Buildable: True
Buildable: True
else
Buildable: False
Buildable: False
Executable test-pandoc
Hs-Source-Dirs: src
Main-Is: test-pandoc.hs
if !flag(tests)
Buildable: False
else
Ghc-Options: -Wall
Build-Depends: base >= 4 && < 5, Diff, MissingH