
In my Cabal file I have defined a flag that controls whether tests are built or not. Now I'd like to hook it up a bit more so that './Setup.hs test' actually runs the tests. I haven't found a way to access that configuration flag in my hook though. Is it not available in some way? Currently I'm settling for calling 'withExeLBI' and triggering the running based on the exe name. That feels somewhat circuitous though. Is there some better approach? Cheers, M

On Sun, Jul 18, 2010 at 12:23 PM, Magnus Therning
In my Cabal file I have defined a flag that controls whether tests are built or not. Now I'd like to hook it up a bit more so that './Setup.hs test' actually runs the tests.
This will allow you to issue 'cabal test' to run the test suite, but it may introduce other issues. I suspect that this won't work well with dependencies or language extensions defined in the cabal file -- I'm really not sure, as I haven't actually done this in "real" code. I just wanted to see if it would work a few months back. In the cabal file, set: Build-type: Custom Then, set the runTests user hook to the function that invokes your test suite: Setup.hs:--------------------------------------------------------------------------- #!/usr/bin/env runhaskell import Distribution.Simple -- The module with your test function, eg: 'testSuite' (see below) import Tests main = do putStrLn "in Main\n" defaultMainWithHooks userHooks -- I think the @testSuite@ function should have type Args -> Bool -> PackageDescription -> LocalBuildInfo -> IO (), but I'm not 100% sure of that. (it does take 4 args, which my sample just ignores) userHooks :: UserHooks userHooks = simpleUserHooks { runTests=testSuite } ---------------------------------------------------------------------------------- Here's my Tests.testSuite fn: testSuite _ _ _ _ = do runTestTT $ TestList [ testSimple1 , testSimple2 ] return () You should now be able to issue 'cabal test' to run the testSuite fn after configuring. I can send the whole sample project if you'd like. --Rogan

On 18/07/10 20:55, Rogan Creswick wrote:
On Sun, Jul 18, 2010 at 12:23 PM, Magnus Therning
wrote: In my Cabal file I have defined a flag that controls whether tests are built or not. Now I'd like to hook it up a bit more so that './Setup.hs test' actually runs the tests.
This will allow you to issue 'cabal test' to run the test suite, but it may introduce other issues. I suspect that this won't work well with dependencies or language extensions defined in the cabal file -- I'm really not sure, as I haven't actually done this in "real" code. I just wanted to see if it would work a few months back.
Yeah, that's why I want to set it up. However, I don't want the setup you suggest. In my Cabal file I have a flag which controls whether the test executable gets built or not: Executable utest Main-Is : Main.hs Hs-Source-Dirs : test_src src Ghc-Options : -threaded if flag(Test) Build-Depends : HUnit, network Buildable : True Ghc-Options : -fhpc else Buildable : False The main reason for this is that the test executable depends on some packages that would never be used in the main part of the package. I also do not want my Setup.hs to depend on those packages. In my Setup.hs I then define the following test hook: runTestsBuild a b pd lbi = let doWithExe e _ = let _exe = "./dist/build/" ++ (exeName e) ++ "/" ++ (exeName e) _runTest = do putStrLn $ "** " ++ (exeName e) ++ ":" ig $ system _exe in when (exeName e `elem` ["utest"]) _runTest in do (runTests simpleUserHooks) a b pd lbi withExeLBI pd lbi doWithExe And this is where the issue I *asked* about comes in. The building of the test executable is controlled by the flag Test, but the flag doesn't seem to be available in the test hook so instead I have to rely on the name of the executable. /M

On Sun, Jul 18, 2010 at 9:23 PM, Magnus Therning
In my Cabal file I have defined a flag that controls whether tests are built or not. Now I'd like to hook it up a bit more so that './Setup.hs test' actually runs the tests.
I haven't found a way to access that configuration flag in my hook though. Is it not available in some way?
Currently I'm settling for calling 'withExeLBI' and triggering the running based on the exe name. That feels somewhat circuitous though. Is there some better approach?
Thomas Tuegel is working on test support for Cabal as part of this year's Google Summer of Code. By the end of the summer, writing and running tests using Cabal will be much simpler. Johan

On 19/07/10 07:14, Johan Tibell wrote:
On Sun, Jul 18, 2010 at 9:23 PM, Magnus Therning
wrote: In my Cabal file I have defined a flag that controls whether tests are built or not. Now I'd like to hook it up a bit more so that './Setup.hs test' actually runs the tests.
I haven't found a way to access that configuration flag in my hook though. Is it not available in some way?
Currently I'm settling for calling 'withExeLBI' and triggering the running based on the exe name. That feels somewhat circuitous though. Is there some better approach?
Thomas Tuegel is working on test support for Cabal as part of this year's Google Summer of Code. By the end of the summer, writing and running tests using Cabal will be much simpler.
Ah, good to know. Then I'll leave things as they are for now and wait until his work makes it into the official release. /M
participants (3)
-
Johan Tibell
-
Magnus Therning
-
Rogan Creswick