Hi Sean. Thanks a bunch for these tips. I haven't used the flags feature of cabal before, and i don't seem to be able to get it right. I have:
Flag test Description: Enable testing Default: False And I get "Warning: unamb.cabal: Unknown section type: flag ignoring...". If I indent, I instead get "These flags are used without having been defined: test". Any idea what I'm doing wrong here? - Conal On Tue, Sep 9, 2008 at 4:32 PM, Sean Leather <[EMAIL PROTECTED]> wrote: > > How do folks like to package up QuickCheck tests for their libraries? In >>>> the main library? As a separate repo & package? Same repo & separate >>>> package? Keeping tests with the tested code allows testing of non-exported >>>> functionality, but can add quite a lot of clutter. >>>> >>> >>> I have QuickCheck properties plus HUnit tests, but I think the question >>> is the same. For me, it's in the same repository and shipped with the >>> package source. I think that if you ship source (even via Hackage), you >>> should also ship tests. So, if somebody wants to modify the source, they can >>> run the tests. And making it convenient to test is very important, so I have >>> "cabal test" (or "runhaskell Setup.hs test" without cabal-install) >>> configured to run the tests. I don't think tests should (in general) be part >>> of the user-visible API, so I have them external to the module hierarchy. >>> >> >> How do you set up cabal to do these tests? >> > > I use the "runTests" hook in Distribution.Simple. The code below works on > Windows and Mac, because that's what we use. > > \begin{code} > module Main (main) where > > import Distribution.Simple > import System.Cmd (system) > import System.FilePath ((</>)) > > main :: IO () > main = defaultMainWithHooks hooks where > hooks = simpleUserHooks { runTests = runTests' } > > runTests' _ _ _ _ = system cmd >> return () > where testdir = "dist" </> "build" </> "test" > testcmd = "." </> "test" > cmd = "cd " ++ testdir ++ " && " ++ testcmd > \end{code} > > Do your libraries depend on HUnit? >> > > No, because I use an ultra-secret trick. ;) I have a Library in my .cabal > file and an Executable for testing. Part of the test description follows. > > \begin{cabal} > Executable test > hs-source-dirs: src, tests, examples > main-is: Main.hs > > -- Only enable the build-depends here if configured with "-ftest". This > -- keeps users from having to install QuickCheck 2 in order to use EMGM. > if flag(test) > build-depends: QuickCheck >= 2.0, HUnit >= 1.2 > else > buildable: False > \end{cabal} > > With that last flag-based if/else, I hide the dependencies for normal > building ('test' by default is False). If 'test' is False, then the > executable also cannot be built. > > Where do you like to place your tests? In the functionality modules? A >> parallel structure? A single Test.hs file somewhere? >> > > In a separate "tests" directory at the same level as the "src" directory > containing the module hierarchy. It has a number of files, mostly one per > module tested. > > >> Testing non-exported functionality without exporting the test interface >>> seems difficult in general. Is there a way to hide part of a module >>> interface with Cabal? Then, you could have a 'test' function exported from >>> each module for testing but hidden for release. >>> >> >> My current leaning is to split a package "foo" into packages "foo" and >>>> "foo-test" >>>> >>> >>> What benefit does this provide? >>> >> >> It keeps the library and its dependencies small. Probably some of the >> alternatives do as well. For testing, I'm using >> checkers<http://haskell.org/haskellwiki/Checkers>in addition to QuickCheck, >> and I'd prefer not to make casual library users >> have to pull in those libraries as well. >> > > Ah, so you're handling the same problem we are in a different way. Nice! > > Sean >
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe