Cabal: Building something from within a test hook
Max Bolingbroke
batterseapower at hotmail.com
Thu Jul 17 17:02:35 EDT 2008
Hi,
I'd like to provide tests for my Cabal project, and would like to do
so by having >another< Cabal project in a tests/ directory that is
built and run by "Cabal test". I've got this far towards getting it
working:
""""
main :: IO ()
main = defaultMainWithHooks (simpleUserHooks { runTests = buildAndRunTests })
buildAndRunTests :: Args -> Bool -> PackageDescription ->
LocalBuildInfo -> IO ()
buildAndRunTests _ _ _ local_build_info = do
test_package_description <- fmap flattenPackageDescription $
readPackageDescription normal "./tests/test-package.cabal"
let [executable] = executables test_package_description
build test_package_description local_build_info defaultBuildFlags []
system $ modulePath executable
"""
This kind of works, but the local_build_info is obviously wrong as it
is for the package being compiled rather than the one I >want< to
compile. What I'm really hoping Cabal provides or is able to provide
is a way to configure the tests package using the old LBI such that
the same tools (e.g. compiler, hc-pkg etc) that were used for this
package are used for the tests one while leaving everything else at
it's default value. I could then use the resulting LBI to build the
tests as I desire.
Any pointers or suggestions for alternative ways I should be going
about this are gratefully recieved!
Max
More information about the Libraries
mailing list