[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Running tests as part of build process



David Fox wrote:
> Isn't this better done from the Setup.hs file?
> 
> main = defaultMainWithHooks simpleUserHooks {
>          runTests = runTestScript
>        , postBuild = runTestScript
>        }
> 
> runTestScript _args _flag _pd _lbi =
>     system "runhaskell Test/Main.hs" >>=
>     \ code -> if code == ExitSuccess then return () else error "Test Failure"
> 

Not really.  That has several flaws.  One is that I don't always want to
build and run the tests, because the tests add multiple dependencies.
Another is that your approach isn't using Cabal to build the tests,
which is a significant complicating factor in many cases.

In most of my packages, I have something like this in .cabal:

flag buildtests
  description: Build the executable to run unit tests
  default: False

...

Executable runtests
   if flag(buildtests)
      Buildable: True
      Build-Depends: HUnit, QuickCheck, testpack
   else
      Buildable: False
   Main-Is: runtests.hs
   Other-Modules: TestSqlValue
...


Reply to: